Skip to content

Commit

Permalink
feat: use symfony/http-client
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Mar 4, 2023
1 parent c7d4a74 commit 9e68c37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
],
"require": {
"php": "^8.1.0",
"nyholm/psr7": "^1.5",
"openai-php/client": "^0.3.4",
"psr/http-client": "^1.0.1",
"psr/http-factory": "^1.0.1",
"symfony/config": "^5.4.21|^6.2.7",
"symfony/dependency-injection": "^5.4.21|^6.2.7",
"symfony/http-client": "^5.4.21|^6.2.7",
"symfony/http-kernel": "^5.4.21|^6.2.7"
},
"require-dev": {
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@

use OpenAI;
use OpenAI\Client;
use Symfony\Component\HttpClient\Psr18Client;

return static function (ContainerConfigurator $container) {
$container->services()
->set('openai.http_client', Psr18Client::class)
->arg(0, service('http_client'))

->set(Client::class)
->factory([OpenAI::class, 'client'])
->args([
abstract_arg('API Key'),
abstract_arg('Organisation'),
service('openai.http_client'),
])

->alias('openai', Client::class);
};
3 changes: 3 additions & 0 deletions tests/DependencyInjection/OpenAIExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
use OpenAI\Symfony\DependencyInjection\OpenAIExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class OpenAIExtensionTest extends TestCase
{
public function testService(): void
{
$container = new ContainerBuilder();
$container->set('http_client', $this->createMock(HttpClientInterface::class));

$extension = new OpenAIExtension();
$extension->load([
'openai' => [
Expand Down

0 comments on commit 9e68c37

Please sign in to comment.