Skip to content

Commit a7d8972

Browse files
committed
feature #837 add support for the albert platform configuration (jvancoillie)
This PR was merged into the main branch. Discussion ---------- add support for the albert platform configuration | Q | A | ------------- | --- | Bug fix? |no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #836 | License | MIT This PR introduces support for configuring the **Albert** platform under the `ai.platforms` section, following the pattern of existing platforms (OpenAI, Mistral, Ollama, etc.). The underlying Albert integration was already implemented, but the `albert` platform key was not recognized during configuration parsing. ```yaml ai: platforms: albert: api_key: '%env(ALBERT_API_KEY)%' base_url: '%env(ALBERT_API_URL)%' ``` The configuration uses `base_url` because this is the parameter expected by the Albert platform factory. Some platforms use `host` instead, which might cause confusion. If needed, I'm open to aligning naming conventions in a follow-up discussion. I did not define a default `base_url`, but we could consider providing the known Albert endpoint (`https://albert.api.etalab.gouv.fr/v1`) if that aligns with the project’s policy on defaults. While working on this, I also noticed that the list of Albert models may not be fully aligned with the current API. I can open a separate issue to track that, unless this work is already in progress. Commits ------- 0e846d2 feat(aibundle): integrate Albert platform support
2 parents a3f8624 + 0e846d2 commit a7d8972

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
@@ -25,6 +25,7 @@
2525
use Symfony\AI\Chat\Command\SetupStoreCommand as SetupMessageStoreCommand;
2626
use Symfony\AI\Chat\MessageNormalizer;
2727
use Symfony\AI\Platform\Bridge\AiMlApi\ModelCatalog as AiMlApiModelCatalog;
28+
use Symfony\AI\Platform\Bridge\Albert\ModelCatalog as AlbertModelCatalog;
2829
use Symfony\AI\Platform\Bridge\Anthropic\Contract\AnthropicContract;
2930
use Symfony\AI\Platform\Bridge\Anthropic\ModelCatalog as AnthropicModelCatalog;
3031
use Symfony\AI\Platform\Bridge\Anthropic\TokenOutputProcessor as AnthropicTokenOutputProcessor;
@@ -88,6 +89,7 @@
8889

8990
// model catalog
9091
->set('ai.platform.model_catalog.aimlapi', AiMlApiModelCatalog::class)
92+
->set('ai.platform.model_catalog.albert', AlbertModelCatalog::class)
9193
->set('ai.platform.model_catalog.anthropic', AnthropicModelCatalog::class)
9294
->set('ai.platform.model_catalog.cartesia', CartesiaModelCatalog::class)
9395
->set('ai.platform.model_catalog.cerebras', CerebrasModelCatalog::class)

src/ai-bundle/src/AiBundle.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use Symfony\AI\Chat\Chat;
4444
use Symfony\AI\Chat\ChatInterface;
4545
use Symfony\AI\Chat\MessageStoreInterface;
46+
use Symfony\AI\Platform\Bridge\Albert\PlatformFactory as AlbertPlatformFactory;
4647
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
4748
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory as AzureOpenAiPlatformFactory;
4849
use Symfony\AI\Platform\Bridge\Cartesia\PlatformFactory as CartesiaPlatformFactory;
@@ -292,6 +293,26 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
292293
*/
293294
private function processPlatformConfig(string $type, array $platform, ContainerBuilder $container): void
294295
{
296+
if ('albert' === $type) {
297+
$platformId = 'ai.platform.albert';
298+
$definition = (new Definition(Platform::class))
299+
->setFactory(AlbertPlatformFactory::class.'::create')
300+
->setLazy(true)
301+
->addTag('proxy', ['interface' => PlatformInterface::class])
302+
->setArguments([
303+
$platform['api_key'],
304+
$platform['base_url'],
305+
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
306+
new Reference('ai.platform.model_catalog.albert'),
307+
new Reference('event_dispatcher'),
308+
])
309+
->addTag('ai.platform', ['name' => 'albert']);
310+
311+
$container->setDefinition($platformId, $definition);
312+
313+
return;
314+
}
315+
295316
if ('anthropic' === $type) {
296317
$platformId = 'ai.platform.anthropic';
297318
$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
@@ -2817,6 +2817,10 @@ private function getFullConfig(): array
28172817
'anthropic' => [
28182818
'api_key' => 'anthropic_key_full',
28192819
],
2820+
'albert' => [
2821+
'api_key' => 'albert-test-key',
2822+
'base_url' => 'https://albert.api.etalab.gouv.fr/v1',
2823+
],
28202824
'azure' => [
28212825
'my_azure_instance' => [
28222826
'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)