Skip to content

Commit 7ececae

Browse files
committed
Wire Docker Model Runner platform bridge into Ai Bundle
1 parent 80c3e46 commit 7ececae

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

examples/dockermodelrunner/chat.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,5 @@
2525
Message::forSystem('You are a pirate and you write funny.'),
2626
Message::ofUser('What is the Symfony framework?'),
2727
);
28-
$result = $agent->call($messages, [
29-
'max_tokens' => 500, // specific options just for this call
30-
]);
28+
$result = $agent->call($messages);
3129
echo $result->getContent().\PHP_EOL;

src/ai-bundle/config/options.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@
155155
->end()
156156
->end()
157157
->end()
158+
->arrayNode('dockermodelrunner')
159+
->children()
160+
->scalarNode('host_url')->defaultValue('http://127.0.0.1:12434')->end()
161+
->scalarNode('http_client')
162+
->defaultValue('http_client')
163+
->info('Service ID of the HTTP client to use')
164+
->end()
165+
->end()
166+
->end()
158167
->end()
159168
->end()
160169
->arrayNode('agent')

src/ai-bundle/src/AiBundle.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
3636
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory as AzureOpenAiPlatformFactory;
3737
use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory as CerebrasPlatformFactory;
38+
use Symfony\AI\Platform\Bridge\DockerModelRunner\PlatformFactory as DockerModelRunnerPlatformFactory;
3839
use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory as ElevenLabsPlatformFactory;
3940
use Symfony\AI\Platform\Bridge\Gemini\PlatformFactory as GeminiPlatformFactory;
4041
use Symfony\AI\Platform\Bridge\LmStudio\PlatformFactory as LmStudioPlatformFactory;
@@ -473,6 +474,24 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
473474
return;
474475
}
475476

477+
if ('dockermodelrunner' === $type) {
478+
$platformId = 'ai.platform.dockermodelrunner';
479+
$definition = (new Definition(Platform::class))
480+
->setFactory(DockerModelRunnerPlatformFactory::class.'::create')
481+
->setLazy(true)
482+
->addTag('proxy', ['interface' => PlatformInterface::class])
483+
->setArguments([
484+
$platform['host_url'],
485+
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
486+
new Reference('ai.platform.contract.default'),
487+
])
488+
->addTag('ai.platform');
489+
490+
$container->setDefinition($platformId, $definition);
491+
492+
return;
493+
}
494+
476495
throw new InvalidArgumentException(\sprintf('Platform "%s" is not supported for configuration via bundle at this point.', $type));
477496
}
478497

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,9 @@ private function getFullConfig(): array
18131813
'location' => 'global',
18141814
'project_id' => '123',
18151815
],
1816+
'dockermodelrunner' => [
1817+
'host_url' => 'http://127.0.0.1:12434',
1818+
],
18161819
],
18171820
'agent' => [
18181821
'my_chat_agent' => [

src/platform/src/Bridge/DockerModelRunner/Completions.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public function __construct(
4040
string $name = self::SMOLLM_2,
4141
array $options = [],
4242
) {
43-
// All capabilities are assumed to be supported since we cannot know in advance
44-
// whether Docker Model Runner and/or each model allows for a particular capability.
4543
parent::__construct($name, Capability::cases(), $options);
4644
}
4745
}

src/platform/src/Bridge/DockerModelRunner/Embeddings.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public function __construct(
2828
string $name = self::NOMIC_EMBED_TEXT,
2929
array $options = [],
3030
) {
31-
// All capabilities are assumed to be supported since we cannot know in advance
32-
// whether Docker Model Runner and/or each model allows for a particular capability.
3331
parent::__construct($name, Capability::cases(), $options);
3432
}
3533
}

0 commit comments

Comments
 (0)