Skip to content

Commit

Permalink
[3.0]Bumps openai (#242)
Browse files Browse the repository at this point in the history
* Bumps `openai-php/client` to `0.6.0`

* Bumps `openai-php/client` to `0.6.0`

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed Jun 15, 2023
1 parent 8d6094b commit 3161c83
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"hyperf/config": "~3.0.0",
"hyperf/di": "~3.0.0",
"hyperf/guzzle": "~3.0.0",
"openai-php/client": "^0.5.1"
"openai-php/client": "^0.6.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions publish/openai.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use function Hyperf\Support\env;

return [
'base_uri' => env('OPENAI_BASE_URI', 'api.openai.com/v1'),
'api_key' => env('OPENAI_API_KEY', ''),
'organization' => env('OPENAI_ORGANIZATION'),
'request_timeout' => (int) env('OPENAI_REQUEST_TIMEOUT', 30),
];
12 changes: 8 additions & 4 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@ final class ClientFactory
{
public function __invoke(ContainerInterface $container)
{
$baseUri = config('openai.base_uri', 'api.openai.com/v1');
$apiKey = config('openai.api_key');
$organization = config('openai.organization');
$timeout = config('openai.request_timeout', 30);

if (! is_string($apiKey) || ($organization !== null && ! is_string($organization))) {
throw ApiKeyIsMissing::create();
}

$httpClient = $container->get(GuzzleClientFactory::class)->create([
'timeout' => $timeout,
]);

return OpenAI::factory()
->withBaseUri($baseUri)
->withApiKey($apiKey)
->withOrganization($organization)
->withBaseUri('api.openai.com/v1')
->withHttpClient(
$container->get(GuzzleClientFactory::class)->create()
)
->withHttpClient($httpClient)
->make();
}
}

0 comments on commit 3161c83

Please sign in to comment.