Skip to content

Commit

Permalink
Add an alias for the ClientContract
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 22, 2024
1 parent 8e33983 commit 0c02044
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use OpenAI;
use OpenAI\Client;
use OpenAI\Contracts\ClientContract;
use OpenAI\Factory;
use Symfony\Component\HttpClient\Psr18Client;

Expand All @@ -22,5 +23,6 @@
->set(Client::class)
->factory([service(Factory::class), 'make'])

->alias(ClientContract::class, Client::class)
->alias('openai', Client::class);
};
5 changes: 4 additions & 1 deletion tests/DependencyInjection/OpenAIExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OpenAI\Symfony\Tests\DependencyInjection;

use OpenAI\Client;
use OpenAI\Contracts\ClientContract;
use OpenAI\Symfony\DependencyInjection\OpenAIExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -13,7 +14,7 @@

final class OpenAIExtensionTest extends TestCase
{
public function testService(): void
public function test_service(): void
{
// Using a mock to test the service configuration
$httpClient = new MockHttpClient(function (string $method, string $url, array $options = []) {
Expand Down Expand Up @@ -45,5 +46,7 @@ public function testService(): void

$response = $openai->files()->delete('file.txt');
self::assertSame('file.txt', $response->id);

self::assertSame($openai, $container->get(ClientContract::class), 'Alias for the ClientContract interface');
}
}

0 comments on commit 0c02044

Please sign in to comment.