Skip to content

Commit 0e846d2

Browse files
committed
feat(aibundle): integrate Albert platform support
- Add Albert platform configuration and service definitions. - Make platform factory accept a customizable ModelCatalog instance.
1 parent 3b12db8 commit 0e846d2

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

src/ai-bundle/config/options.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
->children()
3030
->arrayNode('platform')
3131
->children()
32+
->arrayNode('albert')
33+
->children()
34+
->stringNode('api_key')->isRequired()->end()
35+
->stringNode('base_url')->isRequired()->end()
36+
->stringNode('http_client')
37+
->defaultValue('http_client')
38+
->info('Service ID of the HTTP client to use')
39+
->end()
40+
->end()
41+
->end()
3242
->arrayNode('anthropic')
3343
->children()
3444
->stringNode('api_key')->isRequired()->end()

src/ai-bundle/config/services.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\AI\Chat\Command\DropStoreCommand as DropMessageStoreCommand;
2525
use Symfony\AI\Chat\Command\SetupStoreCommand as SetupMessageStoreCommand;
2626
use Symfony\AI\Platform\Bridge\AiMlApi\ModelCatalog as AiMlApiModelCatalog;
27+
use Symfony\AI\Platform\Bridge\Albert\ModelCatalog as AlbertModelCatalog;
2728
use Symfony\AI\Platform\Bridge\Anthropic\Contract\AnthropicContract;
2829
use Symfony\AI\Platform\Bridge\Anthropic\ModelCatalog as AnthropicModelCatalog;
2930
use Symfony\AI\Platform\Bridge\Anthropic\TokenOutputProcessor as AnthropicTokenOutputProcessor;
@@ -83,6 +84,7 @@
8384

8485
// model catalog
8586
->set('ai.platform.model_catalog.aimlapi', AiMlApiModelCatalog::class)
87+
->set('ai.platform.model_catalog.albert', AlbertModelCatalog::class)
8688
->set('ai.platform.model_catalog.anthropic', AnthropicModelCatalog::class)
8789
->set('ai.platform.model_catalog.cerebras', CerebrasModelCatalog::class)
8890
->set('ai.platform.model_catalog.deepseek', DeepSeekModelCatalog::class)

src/ai-bundle/src/AiBundle.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\AI\Chat\Bridge\Meilisearch\MessageStore as MeilisearchMessageStore;
3939
use Symfony\AI\Chat\Bridge\Pogocache\MessageStore as PogocacheMessageStore;
4040
use Symfony\AI\Chat\MessageStoreInterface;
41+
use Symfony\AI\Platform\Bridge\Albert\PlatformFactory as AlbertPlatformFactory;
4142
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
4243
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory as AzureOpenAiPlatformFactory;
4344
use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory as CerebrasPlatformFactory;
@@ -246,6 +247,26 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
246247
*/
247248
private function processPlatformConfig(string $type, array $platform, ContainerBuilder $container): void
248249
{
250+
if ('albert' === $type) {
251+
$platformId = 'ai.platform.albert';
252+
$definition = (new Definition(Platform::class))
253+
->setFactory(AlbertPlatformFactory::class.'::create')
254+
->setLazy(true)
255+
->addTag('proxy', ['interface' => PlatformInterface::class])
256+
->setArguments([
257+
$platform['api_key'],
258+
$platform['base_url'],
259+
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
260+
new Reference('ai.platform.model_catalog.albert'),
261+
new Reference('event_dispatcher'),
262+
])
263+
->addTag('ai.platform', ['name' => 'albert']);
264+
265+
$container->setDefinition($platformId, $definition);
266+
267+
return;
268+
}
269+
249270
if ('anthropic' === $type) {
250271
$platformId = 'ai.platform.anthropic';
251272
$definition = (new Definition(Platform::class))

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,10 @@ private function getFullConfig(): array
27742774
'anthropic' => [
27752775
'api_key' => 'anthropic_key_full',
27762776
],
2777+
'albert' => [
2778+
'api_key' => 'albert-test-key',
2779+
'base_url' => 'https://albert.api.etalab.gouv.fr/v1',
2780+
],
27772781
'azure' => [
27782782
'my_azure_instance' => [
27792783
'api_key' => 'azure_key_full',

src/platform/src/Bridge/Albert/PlatformFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
1717
use Symfony\AI\Platform\Contract;
1818
use Symfony\AI\Platform\Exception\InvalidArgumentException;
19+
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
1920
use Symfony\AI\Platform\Platform;
2021
use Symfony\Component\HttpClient\EventSourceHttpClient;
2122
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -29,6 +30,7 @@ public static function create(
2930
#[\SensitiveParameter] string $apiKey,
3031
string $baseUrl,
3132
?HttpClientInterface $httpClient = null,
33+
ModelCatalogInterface $modelCatalog = new ModelCatalog(),
3234
?EventDispatcherInterface $eventDispatcher = null,
3335
): Platform {
3436
if (!str_starts_with($baseUrl, 'https://')) {
@@ -52,7 +54,7 @@ public static function create(
5254
new EmbeddingsModelClient($httpClient, $apiKey, $baseUrl),
5355
],
5456
[new Gpt\ResultConverter(), new Embeddings\ResultConverter()],
55-
new ModelCatalog(),
57+
$modelCatalog,
5658
Contract::create(),
5759
$eventDispatcher,
5860
);

0 commit comments

Comments
 (0)