-
-
Notifications
You must be signed in to change notification settings - Fork 142
[AI Bundle][Platform] Integrate template rendering into Message API #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AI Bundle][Platform] Integrate template rendering into Message API #1017
Conversation
c290706 to
00b4af3
Compare
|
Thanks for this @wachterjohannes - would really love to get this in 🙏 two things that we need to sort here:
we could have something like: $template = new Symfony\AI\Platform\Message\Template::expression('Total: {price * quantity}');
$message = Message::forSystem($template);
$messages = new MessageBag($message);
$result = $platform->invoke('gpt-4o-mini', $messages, [
'template_vars' => ['price' => 10, 'quantity' => 5],
]);and later - while serializing - take care of the rendering - potentially throw an error on unsupported types. with type being only a string instead of a renderer instance + named construct for promoted use: class Template
{
public function __construct(
private string $template,
private string $type,
) { }
public static function string(string $template): self;
public static function expression(string $template): self;
public static function twig(string $template): self
{
return new self($template, 'twig');
}
}WDYT? |
|
@chr-hertel in my opinion an own component makes sense as it is totally independent to the other component and as you mentioned we could integrate it into the agent and platform. @OskarStark what do you think. Regarding the renaming - makes totally sense and i will do that when the decission over the component is final :) |
|
My thinking always is: API first, then implementation, then slicing. That's why i would delay that component discussion. Templates alone are not valuable, they need an integration into the Message I'd say |
|
@chr-hertel both are absolutly thru statements :) so let us wait for feedback from @OskarStark |
|
Lets go with the platform component first 👍 |
d7911d1 to
f67c952
Compare
|
@OskarStark that was luck 😂 pushed a few minutes ago! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it needed for an assistant message, which comes from the LLM? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are totally right :) will remove that from the AssistantMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still in
src/platform/src/Message/TemplateRenderer/ExpressionTemplateRenderer.php
Outdated
Show resolved
Hide resolved
src/platform/src/Message/TemplateRenderer/ChainTemplateRenderer.php
Outdated
Show resolved
Hide resolved
src/platform/src/Message/TemplateRenderer/ChainTemplateRenderer.php
Outdated
Show resolved
Hide resolved
6200479 to
3d1112e
Compare
chr-hertel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome - you pretty much nailed it - only small stuff & fabbot - thanks already!
src/platform/src/Message/TemplateRenderer/ChainTemplateRenderer.php
Outdated
Show resolved
Hide resolved
|
@chr-hertel fixed your comments |
src/platform/src/Message/TemplateRenderer/ExpressionLanguageTemplateRenderer.php
Outdated
Show resolved
Hide resolved
src/platform/src/Message/TemplateRenderer/StringTemplateRenderer.php
Outdated
Show resolved
Hide resolved
src/platform/tests/EventListener/TemplateRendererListenerTest.php
Outdated
Show resolved
Hide resolved
8b4fb03 to
1648643
Compare
|
@chr-hertel hopefully all fixed now :) |
2e78538 to
08fcca4
Compare
|
TemplateRendererRegistry is better that Chained.... imho |
|
No need for 03- prefix etc in the example filenames |
|
@OskarStark yeah your right - just changed that - you can take another look |
4a178c3 to
a3f8f5b
Compare
a3f8f5b to
e7dd1b2
Compare
|
Thank you @wachterjohannes. |
Summary
Adds a new prompt-template component to the Symfony AI monorepo, filling a gap we identified in our (Christopher Hertel and me) recent discussion about missing core functionality for prompt management.
Background
This implementation merges and adapts code from both sulu.ai and modelflow-ai projects, bringing battle-tested prompt templating into the Symfony AI ecosystem with a more extensible architecture.
Architecture
The component uses a strategy pattern for rendering, allowing different template processors to be plugged in:
{variable}replacement with zero dependenciesKey Features
Usage Examples
Simple variable replacement:
This provides a solid foundation for prompt template management across the Symfony AI ecosystem while maintaining the flexibility to adapt to different rendering needs.