Skip to content

Commit f0b4e8c

Browse files
committed
feat(bedrock): support bedrock platform config
1 parent e51686d commit f0b4e8c

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

config/options.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@
6262
->end()
6363
->end()
6464
->end()
65+
->arrayNode('bedrock')
66+
->useAttributeAsKey('name')
67+
->arrayPrototype()
68+
->children()
69+
->stringNode('bedrock_runtime_client')
70+
->defaultNull()
71+
->info('Service ID of the Bedrock runtime client to use')
72+
->end()
73+
->stringNode('model_catalog')->defaultNull()->end()
74+
->end()
75+
->end()
76+
->end()
6577
->arrayNode('cache')
6678
->useAttributeAsKey('name')
6779
->arrayPrototype()

config/services.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Symfony\AI\Platform\Bridge\Anthropic\Contract\AnthropicContract;
3030
use Symfony\AI\Platform\Bridge\Anthropic\ModelCatalog as AnthropicModelCatalog;
3131
use Symfony\AI\Platform\Bridge\Azure\OpenAi\ModelCatalog as AzureOpenAiModelCatalog;
32+
use Symfony\AI\Platform\Bridge\Bedrock\ModelCatalog as BedrockModelCatalog;
3233
use Symfony\AI\Platform\Bridge\Cartesia\ModelCatalog as CartesiaModelCatalog;
3334
use Symfony\AI\Platform\Bridge\Cerebras\ModelCatalog as CerebrasModelCatalog;
3435
use Symfony\AI\Platform\Bridge\Decart\ModelCatalog as DecartModelCatalog;
@@ -96,6 +97,7 @@
9697
->set('ai.platform.model_catalog.albert', AlbertModelCatalog::class)
9798
->set('ai.platform.model_catalog.anthropic', AnthropicModelCatalog::class)
9899
->set('ai.platform.model_catalog.azure.openai', AzureOpenAiModelCatalog::class)
100+
->set('ai.platform.model_catalog.bedrock', BedrockModelCatalog::class)
99101
->set('ai.platform.model_catalog.cartesia', CartesiaModelCatalog::class)
100102
->set('ai.platform.model_catalog.cerebras', CerebrasModelCatalog::class)
101103
->set('ai.platform.model_catalog.decart', DecartModelCatalog::class)

src/AiBundle.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use Symfony\AI\Platform\Bridge\Albert\PlatformFactory as AlbertPlatformFactory;
5454
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
5555
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory as AzureOpenAiPlatformFactory;
56+
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory as BedrockFactory;
5657
use Symfony\AI\Platform\Bridge\Cartesia\PlatformFactory as CartesiaPlatformFactory;
5758
use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory as CerebrasPlatformFactory;
5859
use Symfony\AI\Platform\Bridge\Decart\PlatformFactory as DecartPlatformFactory;
@@ -408,6 +409,31 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
408409
return;
409410
}
410411

412+
if ('bedrock' === $type) {
413+
if (!ContainerBuilder::willBeAvailable('symfony/ai-bedrock-platform', BedrockFactory::class, ['symfony/ai-bundle'])) {
414+
throw new RuntimeException('Bedrock platform configuration requires "symfony/ai-bedrock-platform" package. Try running "composer require symfony/ai-bedrock-platform".');
415+
}
416+
417+
foreach ($platform as $name => $config) {
418+
$platformId = 'ai.platform.bedrock_'.$name;
419+
$definition = (new Definition(Platform::class))
420+
->setFactory(BedrockFactory::class.'::create')
421+
->setLazy(true)
422+
->addTag('proxy', ['interface' => PlatformInterface::class])
423+
->setArguments([
424+
$config['bedrock_runtime_client'] ? new Reference($config['bedrock_runtime_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE) : null,
425+
$config['model_catalog'] ? new Reference($config['model_catalog']) : new Reference('ai.platform.model_catalog.bedrock'),
426+
null,
427+
new Reference('event_dispatcher'),
428+
])
429+
->addTag('ai.platform', ['name' => 'bedrock_'.$name]);
430+
431+
$container->setDefinition($platformId, $definition);
432+
}
433+
434+
return;
435+
}
436+
411437
if ('cache' === $type) {
412438
foreach ($platform as $name => $cachedPlatformConfig) {
413439
$definition = (new Definition(CachedPlatform::class))

tests/DependencyInjection/AiBundleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\AI\AiBundle\Tests\DependencyInjection;
1313

14+
use AsyncAws\BedrockRuntime\BedrockRuntimeClient;
1415
use Codewithkyrian\ChromaDB\Client;
1516
use MongoDB\Client as MongoDbClient;
1617
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
@@ -7013,6 +7014,7 @@ private function buildContainer(array $configuration): ContainerBuilder
70137014
$container->setParameter('kernel.environment', 'dev');
70147015
$container->setParameter('kernel.build_dir', 'public');
70157016
$container->setDefinition(ClockInterface::class, new Definition(MonotonicClock::class));
7017+
$container->setDefinition('async_aws.client.bedrock_us', new Definition(BedrockRuntimeClient::class));
70167018

70177019
$extension = (new AiBundle())->getContainerExtension();
70187020
$extension->load($configuration, $container);
@@ -7049,6 +7051,12 @@ private function getFullConfig(): array
70497051
'api_version' => '2024-02-15-preview',
70507052
],
70517053
],
7054+
'bedrock' => [
7055+
'default' => [],
7056+
'us' => [
7057+
'bedrock_runtime_client' => 'async_aws.client.bedrock_us',
7058+
],
7059+
],
70527060
'cache' => [
70537061
'azure' => [
70547062
'platform' => 'ai.platform.azure.my_azure_instance',

0 commit comments

Comments
 (0)