Skip to content

Commit 7a0978d

Browse files
authored
add timeout configuration support (#45)
1 parent 7ae57d0 commit 7a0978d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

config/openai.php

+10
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@
1515
'api_key' => env('OPENAI_API_KEY'),
1616
'organization' => env('OPENAI_ORGANIZATION'),
1717

18+
/*
19+
|--------------------------------------------------------------------------
20+
| Request Timeout
21+
|--------------------------------------------------------------------------
22+
|
23+
| The timeout may be used to specify the maximum number of seconds to wait
24+
| for a response. By default, the client will time out after 30 seconds.
25+
*/
26+
27+
'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30),
1828
];

src/ServiceProvider.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public function register(): void
2929
throw ApiKeyIsMissing::create();
3030
}
3131

32-
return OpenAI::client($apiKey, $organization);
32+
return OpenAI::factory()
33+
->withApiKey($apiKey)
34+
->withOrganization($organization)
35+
->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)]))
36+
->make();
3337
});
3438

3539
$this->app->alias(ClientContract::class, 'openai');

tests/Arch.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
test('service providers')
1717
->expect('OpenAI\Laravel\ServiceProvider')
1818
->toOnlyUse([
19+
'GuzzleHttp\Client',
1920
'Illuminate\Support\ServiceProvider',
2021
'OpenAI\Laravel',
2122
'OpenAI',

0 commit comments

Comments
 (0)