Skip to content

Commit

Permalink
Changed underlying openai/client package version from 0.3.4 to 0.4.0 (
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Mar 18, 2023
1 parent 6688c92 commit 7c223b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"hyperf/config": "~3.0.0",
"hyperf/di": "~3.0.0",
"hyperf/guzzle": "~3.0.0",
"openai-php/client": "^0.3.4"
"openai-php/client": "^0.4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
Expand All @@ -44,7 +44,8 @@
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "dev",
Expand Down
26 changes: 9 additions & 17 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@

use FriendsOfHyperf\OpenAi\Exception\ApiKeyIsMissing;
use Hyperf\Guzzle\ClientFactory as GuzzleClientFactory;
use OpenAI\Client;
use OpenAI\Transporters\HttpTransporter;
use OpenAI\ValueObjects\ApiKey;
use OpenAI\ValueObjects\Transporter\BaseUri;
use OpenAI\ValueObjects\Transporter\Headers;
use OpenAI;
use Psr\Container\ContainerInterface;

final class ClientFactory
Expand All @@ -30,17 +26,13 @@ public function __invoke(ContainerInterface $container)
throw ApiKeyIsMissing::create();
}

$apiKey = ApiKey::from($apiKey);
$baseUri = BaseUri::from('api.openai.com/v1');
$headers = Headers::withAuthorization($apiKey);

if ($organization !== null) {
$headers = $headers->withOrganization($organization);
}

$client = $container->get(GuzzleClientFactory::class)->create();
$transporter = new HttpTransporter($client, $baseUri, $headers);

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

0 comments on commit 7c223b0

Please sign in to comment.