You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #1017 [AI Bundle][Platform] Integrate template rendering into Message API (wachterjohannes)
This PR was squashed before being merged into the main branch.
Discussion
----------
[AI Bundle][Platform] Integrate template rendering into Message API
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| Docs? | no
| Issues | Fix#258
| License | MIT
## Summary
Adds a new **prompt-template** component to the Symfony AI monorepo, filling a gap we identified in our ([Christopher Hertel](https://github.com/chr-hertel) and me) recent discussion about missing core functionality for prompt management.
## Background
This implementation merges and adapts code from both [sulu.ai](sulu.ai) and [modelflow-ai](https://github.com/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:
- **StringRenderer** (default): Simple `{variable}` replacement with zero dependencies
- **ExpressionRenderer**: Advanced expression evaluation using Symfony Expression Language (optional)
- **Extensible**: Ready for additional renderers like Twig, Mustache, or custom implementations
### Key Features
- Zero core dependencies (only PHP 8.2+)
- Factory pattern for exceptions with typed error methods
- Immutable readonly classes throughout
- Interface-first design for maximum flexibility
- Comprehensive test coverage (42 tests, 52 assertions)
- PHPStan level 6 compliant
## Usage Examples
**Simple variable replacement:**
```php
$template = PromptTemplate::fromString('Hello {name}!');
echo $template->format(['name' => 'World']); // "Hello World!"
Expression-based rendering:
$renderer = new ExpressionRenderer();
$template = new PromptTemplate('Total: {price * quantity}', $renderer);
echo $template->format(['price' => 10, 'quantity' => 5]); // "Total: 50"
Custom renderer:
class TwigRenderer implements RendererInterface {
public function render(string $template, array $values): string {
// Twig implementation
}
}
```
This provides a solid foundation for prompt template management across the Symfony AI ecosystem while maintaining the flexibility to adapt to different rendering needs.
Commits
-------
e7dd1b2 [AI Bundle][Platform] Integrate template rendering into Message API
0 commit comments