diff --git a/src/ai-bundle/src/AiBundle.php b/src/ai-bundle/src/AiBundle.php index ad056c551..2803e5987 100644 --- a/src/ai-bundle/src/AiBundle.php +++ b/src/ai-bundle/src/AiBundle.php @@ -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']); @@ -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']); @@ -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']); @@ -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']); @@ -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']); @@ -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']); @@ -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']); @@ -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']); @@ -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'); @@ -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'); diff --git a/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php b/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php index 3e975cbdb..bc6ef3384 100644 --- a/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php +++ b/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php @@ -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() @@ -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', ], @@ -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', @@ -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',