Skip to content

Commit 645cd4a

Browse files
committed
Wire Docker Model Runner platform bridge into Ai Bundle
1 parent d13d389 commit 645cd4a

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106
->scalarNode('api_key')->isRequired()->end()
107107
->end()
108108
->end()
109+
->arrayNode('dockermodelrunner')
110+
->children()
111+
->scalarNode('host_url')->defaultValue('http://127.0.0.1:12434')->end()
112+
->end()
113+
->end()
109114
->end()
110115
->end()
111116
->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;
@@ -474,6 +475,24 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
474475
return;
475476
}
476477

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,9 @@ private function getFullConfig(): array
18071807
'location' => 'global',
18081808
'project_id' => '123',
18091809
],
1810+
'dockermodelrunner' => [
1811+
'host_url' => 'http://127.0.0.1:12434',
1812+
],
18101813
],
18111814
'agent' => [
18121815
'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)