From f107a20e280f70f854f66eb2663510c7d9051ae7 Mon Sep 17 00:00:00 2001 From: Nikolay Mikhaylov Date: Thu, 2 Oct 2025 16:41:27 +0400 Subject: [PATCH] [AI Bundle] Preserve boolean options in agent/vectorizer model confguration --- src/ai-bundle/config/options.php | 12 +++++ .../DependencyInjection/AiBundleTest.php | 52 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/ai-bundle/config/options.php b/src/ai-bundle/config/options.php index c1e3b57f4..5d553197d 100644 --- a/src/ai-bundle/config/options.php +++ b/src/ai-bundle/config/options.php @@ -271,6 +271,12 @@ return $model; } + array_walk_recursive($options, static function (mixed &$value): void { + if (\is_bool($value)) { + $value = $value ? 'true' : 'false'; + } + }); + return $model.'?'.http_build_query($options); }) ->end() @@ -698,6 +704,12 @@ return $model; } + array_walk_recursive($options, static function (mixed &$value): void { + if (\is_bool($value)) { + $value = $value ? 'true' : 'false'; + } + }); + return $model.'?'.http_build_query($options); }) ->end() diff --git a/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php b/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php index eede239a1..a03480078 100644 --- a/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php +++ b/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php @@ -2583,6 +2583,58 @@ public function testVectorizerConfigurationWithColonNotation(string $model) $this->assertSame($model, $definition->getArgument(1)); } + public function testAgentModelBooleanOptionsArePreserved() + { + $container = $this->buildContainer([ + 'ai' => [ + 'agent' => [ + 'test' => [ + 'model' => [ + 'name' => 'qwen3', + 'options' => [ + 'stream' => false, + 'think' => true, + 'nested' => [ + 'bool' => false, + ], + ], + ], + ], + ], + ], + ]); + + $agentDefinition = $container->getDefinition('ai.agent.test'); + + $this->assertSame('qwen3?stream=false&think=true&nested%5Bbool%5D=false', $agentDefinition->getArgument(1)); + } + + public function testVectorizerModelBooleanOptionsArePreserved() + { + $container = $this->buildContainer([ + 'ai' => [ + 'vectorizer' => [ + 'test' => [ + 'model' => [ + 'name' => 'text-embedding-3-small', + 'options' => [ + 'normalize' => false, + 'cache' => true, + 'nested' => [ + 'bool' => false, + ], + ], + ], + ], + ], + ], + ]); + + $vectorizerDefinition = $container->getDefinition('ai.vectorizer.test'); + + $this->assertSame('text-embedding-3-small?normalize=false&cache=true&nested%5Bbool%5D=false', $vectorizerDefinition->getArgument(1)); + } + private function buildContainer(array $configuration): ContainerBuilder { $container = new ContainerBuilder();