Skip to content

Commit c149ec9

Browse files
committed
bug #1043 [AI Bundle] Enabling translations breaks container dumping (VincentLanglet)
This PR was squashed before being merged into the main branch. Discussion ---------- [AI Bundle] Enabling translations breaks container dumping | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #1040 | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- b86f048 [AI Bundle] Enabling translations breaks container dumping
2 parents 06d4e5a + b86f048 commit c149ec9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/ai-bundle/src/AiBundle.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,12 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
881881
throw new RuntimeException('For using prompt translataion, symfony/translation package is required. Try running "composer require symfony/translation".');
882882
}
883883

884-
$prompt = new TranslatableMessage($promptText, domain: $config['prompt']['translation_domain']);
884+
$promptId = 'ai.agent.prompt.'.$name;
885+
$translatableDefinition = (new Definition(TranslatableMessage::class))
886+
->setArguments([$promptText, [], $config['prompt']['translation_domain']]);
887+
888+
$container->setDefinition($promptId, $translatableDefinition);
889+
$prompt = new Reference($promptId);
885890
} else {
886891
$prompt = $promptText;
887892
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
use Symfony\Component\DependencyInjection\Reference;
7474
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7575
use Symfony\Component\HttpClient\HttpClient;
76-
use Symfony\Component\Translation\TranslatableMessage;
7776
use Symfony\Contracts\HttpClient\HttpClientInterface;
7877

7978
class AiBundleTest extends TestCase
@@ -2957,11 +2956,18 @@ public function testSystemPromptWithArrayStructure()
29572956
],
29582957
]);
29592958

2959+
$this->assertTrue($container->hasDefinition('ai.agent.prompt.test_agent'));
2960+
$definition = $container->getDefinition('ai.agent.prompt.test_agent');
2961+
$arguments = $definition->getArguments();
2962+
$this->assertEquals('You are a helpful assistant.', $arguments[0]);
2963+
$this->assertEquals([], $arguments[1]);
2964+
$this->assertEquals('prompts', $arguments[2]);
2965+
29602966
$this->assertTrue($container->hasDefinition('ai.agent.test_agent.system_prompt_processor'));
29612967
$definition = $container->getDefinition('ai.agent.test_agent.system_prompt_processor');
29622968
$arguments = $definition->getArguments();
29632969

2964-
$this->assertEquals(new TranslatableMessage('You are a helpful assistant.', domain: 'prompts'), $arguments[0]);
2970+
$this->assertEquals(new Reference('ai.agent.prompt.test_agent'), $arguments[0]);
29652971
$this->assertNull($arguments[1]); // include_tools is false, so null reference
29662972
}
29672973

0 commit comments

Comments
 (0)