Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['host'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.elevenlabs'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'eleven_labs']);
Expand Down Expand Up @@ -363,6 +364,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$httpClient,
new Reference('ai.platform.model_catalog.vertexai.gemini'),
new Reference('ai.platform.contract.vertexai.gemini'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'vertexai']);
Expand Down Expand Up @@ -403,6 +405,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.openrouter'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'openrouter']);
Expand All @@ -422,6 +425,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.mistral'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'mistral']);
Expand All @@ -441,6 +445,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['host_url'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.lmstudio'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'lmstudio']);
Expand Down Expand Up @@ -480,6 +485,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.cerebras'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'cerebras']);
Expand All @@ -499,6 +505,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.deepseek'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'deepseek']);
Expand All @@ -518,6 +525,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.voyage'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform', ['name' => 'voyage']);
Expand Down Expand Up @@ -557,6 +565,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['host_url'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.dockermodelrunner'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform');
Expand All @@ -576,6 +585,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.scaleway'),
null,
new Reference('event_dispatcher'),
])
->addTag('ai.platform');
Expand Down
37 changes: 31 additions & 6 deletions src/ai-bundle/tests/DependencyInjection/AiBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,39 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class AiBundleTest extends TestCase
{
#[DoesNotPerformAssertions]
public function testExtensionLoadDoesNotThrow()
{
$this->buildContainer($this->getFullConfig());
$container = $this->buildContainer($this->getFullConfig());

// Mock services that are used as platform create arguments, but should not be testet here or are not available.
$container->set('event_dispatcher', $this->createMock(EventDispatcherInterface::class));
$container->getDefinition('ai.platform.vertexai')->replaceArgument(2, $this->createMock(HttpClientInterface::class));

$platforms = $container->findTaggedServiceIds('ai.platform');

foreach (array_keys($platforms) as $platformId) {
try {
$platformService = $container->get($platformId);
$platformService->getModelCatalog();
} catch (\Throwable $e) {
$failureMessage = \sprintf(
'Failed to load platform service "%s" or call getModelCatalog(). '.
'Original error: %s (in %s:%d)',
$platformId,
$e->getMessage(),
$e->getFile(),
$e->getLine()
);
$this->fail($failureMessage);
}
}
}

public function testStoreCommandsArentDefinedWithoutStore()
Expand Down Expand Up @@ -2752,13 +2777,13 @@ private function getFullConfig(): array
'azure' => [
'my_azure_instance' => [
'api_key' => 'azure_key_full',
'base_url' => 'https://myazure.openai.azure.com/',
'base_url' => 'myazure.openai.azure.com/',
'deployment' => 'gpt-35-turbo',
'api_version' => '2024-02-15-preview',
],
'another_azure_instance' => [
'api_key' => 'azure_key_2',
'base_url' => 'https://myazure2.openai.azure.com/',
'base_url' => 'myazure2.openai.azure.com/',
'deployment' => 'gpt-4',
'api_version' => '2024-02-15-preview',
],
Expand All @@ -2771,13 +2796,13 @@ private function getFullConfig(): array
'api_key' => 'gemini_key_full',
],
'openai' => [
'api_key' => 'openai_key_full',
'api_key' => 'sk-openai_key_full',
],
'mistral' => [
'api_key' => 'mistral_key_full',
],
'openrouter' => [
'api_key' => 'openrouter_key_full',
'api_key' => 'sk-openrouter_key_full',
],
'lmstudio' => [
'host_url' => 'http://127.0.0.1:1234',
Expand All @@ -2786,7 +2811,7 @@ private function getFullConfig(): array
'host_url' => 'http://127.0.0.1:11434',
],
'cerebras' => [
'api_key' => 'cerebras_key_full',
'api_key' => 'csk-cerebras_key_full',
],
'voyage' => [
'api_key' => 'voyage_key_full',
Expand Down