Skip to content

Commit 41e7518

Browse files
committed
feat(ai): integrate Albert platform support
- Add Albert platform configuration and service definitions. - Update ModelCatalog with `albert-large` support. - Make platform factory accept a customizable ModelCatalog instance.
1 parent a6c8ea1 commit 41e7518

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

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;
@@ -82,6 +83,7 @@
8283
->factory([PerplexityContract::class, 'create'])
8384

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

src/ai-bundle/src/AiBundle.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,26 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
247247
*/
248248
private function processPlatformConfig(string $type, array $platform, ContainerBuilder $container): void
249249
{
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+
250270
if ('anthropic' === $type) {
251271
$platformId = 'ai.platform.anthropic';
252272
$definition = (new Definition(Platform::class))
@@ -396,25 +416,6 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
396416
return;
397417
}
398418

399-
if ('albert' === $type) {
400-
$platformId = 'ai.platform.albert';
401-
$definition = (new Definition(Platform::class))
402-
->setFactory(AlbertPlatformFactory::class.'::create')
403-
->setLazy(true)
404-
->addTag('proxy', ['interface' => PlatformInterface::class])
405-
->setArguments([
406-
$platform['api_key'],
407-
$platform['base_url'],
408-
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
409-
new Reference('event_dispatcher'),
410-
])
411-
->addTag('ai.platform', ['name' => 'albert']);
412-
413-
$container->setDefinition($platformId, $definition);
414-
415-
return;
416-
}
417-
418419
if ('openrouter' === $type) {
419420
$platformId = 'ai.platform.openrouter';
420421
$definition = (new Definition(Platform::class))

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)