Skip to content

Commit

Permalink
feat: replace default guzzle http client by any psr/http-client-imple…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
GromNaN committed Mar 4, 2023
1 parent 6af9170 commit f05e9bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
],
"require": {
"php": "^8.1.0",
"guzzlehttp/guzzle": "^7.5.0"
"psr/http-client-implementation": "1.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.5.0",
"laravel/pint": "^1.6.0",
"nunomaduro/collision": "^7.0.5",
"pestphp/pest": "^2.0.0",
Expand All @@ -23,6 +24,9 @@
"rector/rector": "^0.14.8",
"symfony/var-dumper": "^6.2.7"
},
"suggest": {
"guzzlehttp/guzzle": "^7.5.0"
},
"autoload": {
"psr-4": {
"OpenAI\\": "src/"
Expand Down
7 changes: 6 additions & 1 deletion src/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ public static function client(string $apiKey, string $organization = null, Clien
$headers = $headers->withOrganization($organization);
}

$client ??= new GuzzleClient();
if (null === $client) {
if (!class_exists(GuzzleClient::class)) {
throw new \LogicException('Guzzle is not installed. Try running "composer require guzzlehttp/guzzle" or pass a PSR-18 client.');
}
$client = new GuzzleClient();
}

$transporter = new HttpTransporter($client, $baseUri, $headers);

Expand Down

0 comments on commit f05e9bc

Please sign in to comment.