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
3 changes: 3 additions & 0 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ jobs:
- run: composer run-script auto-scripts --no-interaction
working-directory: demo

- run: bin/console cache:clear
working-directory: demo

- name: Run demo tests
working-directory: demo
run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion src/ai-bundle/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
->factory([OpenAiContract::class, 'create'])
->set('ai.platform.contract.anthropic', Contract::class)
->factory([AnthropicContract::class, 'create'])
->set('ai.platform.contract.google', Contract::class)
->set('ai.platform.contract.gemini', Contract::class)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is also aliased as GeminiContract

->factory([GeminiContract::class, 'create'])
->set('ai.platform.contract.vertexai.gemini', Contract::class)
->factory([VertexAiGeminiContract::class, 'create'])
Expand Down
26 changes: 15 additions & 11 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.anthropic'),
new Reference('ai.platform.model_catalog.anthropic'),
new Reference('ai.platform.contract.anthropic'),
])
->addTag('ai.platform');

Expand All @@ -247,8 +247,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$config['api_version'],
$config['api_key'],
new Reference($config['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.openai'),
new Reference('ai.platform.model_catalog.azure.openai'),
new Reference('ai.platform.contract.azure.openai'),
])
->addTag('ai.platform');

Expand All @@ -268,8 +268,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['api_key'],
$platform['host'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
new Reference('ai.platform.model_catalog.elevenlabs'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand All @@ -287,8 +287,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.google'),
new Reference('ai.platform.model_catalog.gemini'),
new Reference('ai.platform.contract.gemini'),
])
->addTag('ai.platform');

Expand Down Expand Up @@ -327,8 +327,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$platform['location'],
$platform['project_id'],
$httpClient,
new Reference('ai.platform.contract.vertexai', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.vertexai.gemini'),
new Reference('ai.platform.contract.vertexai.gemini'),
])
->addTag('ai.platform');

Expand All @@ -346,6 +346,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.openai'),
new Reference('ai.platform.contract.openai'),
$platform['region'] ?? null,
])
Expand All @@ -365,8 +366,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
new Reference('ai.platform.model_catalog.openrouter'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand All @@ -384,8 +385,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
new Reference('ai.platform.model_catalog.mistral'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand All @@ -403,8 +404,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['host_url'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
new Reference('ai.platform.model_catalog.lmstudio'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand All @@ -422,8 +423,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['host_url'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.ollama'),
new Reference('ai.platform.model_catalog.ollama'),
new Reference('ai.platform.contract.ollama'),
])
->addTag('ai.platform');

Expand All @@ -442,6 +443,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'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand All @@ -460,6 +462,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'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand All @@ -477,6 +480,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.model_catalog.perplexity'),
new Reference('ai.platform.contract.perplexity'),
])
->addTag('ai.platform');
Expand All @@ -495,8 +499,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['host_url'],
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
new Reference('ai.platform.model_catalog.dockermodelrunner'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand All @@ -514,8 +518,8 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
new Reference('ai.platform.model_catalog.scaleway'),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');

Expand Down
14 changes: 8 additions & 6 deletions src/ai-bundle/tests/DependencyInjection/AiBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,9 @@ public function testOpenAiPlatformWithDefaultRegion()
$definition = $container->getDefinition('ai.platform.openai');
$arguments = $definition->getArguments();

$this->assertCount(4, $arguments);
$this->assertCount(5, $arguments);
$this->assertSame('sk-test-key', $arguments[0]);
$this->assertNull($arguments[3]); // region should be null by default
$this->assertNull($arguments[4]); // region should be null by default
}

#[TestWith(['EU'])]
Expand All @@ -632,9 +632,9 @@ public function testOpenAiPlatformWithRegion(?string $region)
$definition = $container->getDefinition('ai.platform.openai');
$arguments = $definition->getArguments();

$this->assertCount(4, $arguments);
$this->assertCount(5, $arguments);
$this->assertSame('sk-test-key', $arguments[0]);
$this->assertSame($region, $arguments[3]);
$this->assertSame($region, $arguments[4]);
}

public function testOpenAiPlatformWithInvalidRegion()
Expand Down Expand Up @@ -671,12 +671,14 @@ public function testPerplexityPlatformConfiguration()
$definition = $container->getDefinition('ai.platform.perplexity');
$arguments = $definition->getArguments();

$this->assertCount(3, $arguments);
$this->assertCount(4, $arguments);
$this->assertSame('pplx-test-key', $arguments[0]);
$this->assertInstanceOf(Reference::class, $arguments[1]);
$this->assertSame('http_client', (string) $arguments[1]);
$this->assertInstanceOf(Reference::class, $arguments[2]);
$this->assertSame('ai.platform.contract.perplexity', (string) $arguments[2]);
$this->assertSame('ai.platform.model_catalog.perplexity', (string) $arguments[2]);
$this->assertInstanceOf(Reference::class, $arguments[3]);
$this->assertSame('ai.platform.contract.perplexity', (string) $arguments[3]);
}

#[TestDox('System prompt with array structure works correctly')]
Expand Down
3 changes: 3 additions & 0 deletions src/platform/src/Bridge/Cerebras/PlatformFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\AI\Platform\Bridge\Cerebras;

use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
use Symfony\AI\Platform\Platform;
use Symfony\Component\HttpClient\EventSourceHttpClient;
Expand All @@ -25,13 +26,15 @@ public static function create(
#[\SensitiveParameter] string $apiKey,
?HttpClientInterface $httpClient = null,
ModelCatalogInterface $modelCatalog = new ModelCatalog(),
?Contract $contract = null,
): Platform {
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);

return new Platform(
[new ModelClient($httpClient, $apiKey)],
[new ResultConverter()],
$modelCatalog,
$contract,
);
}
}
7 changes: 6 additions & 1 deletion src/platform/src/Bridge/Voyage/PlatformFactory.php
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only line breaks here

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static function create(
): Platform {
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);

return new Platform([new ModelClient($httpClient, $apiKey)], [new ResultConverter()], $modelCatalog, $contract);
return new Platform(
[new ModelClient($httpClient, $apiKey)],
[new ResultConverter()],
$modelCatalog,
$contract,
);
}
}