Skip to content
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

StringTemplate should not be the only prompt template mechanism #1687

Open
johnsonr opened this issue Nov 6, 2024 · 0 comments
Open

StringTemplate should not be the only prompt template mechanism #1687

johnsonr opened this issue Nov 6, 2024 · 0 comments
Labels

Comments

@johnsonr
Copy link

johnsonr commented Nov 6, 2024

StringTemplate should not be the only prompt template mechanism used in Spring AI. Nor should it be the default.

StringTemplate is presently deeply baked into Spring AI. Consider AdvisedRequest.toPrompt and PromptTemplate. ChatClient.defaultSystem will automatically use ST.

The template engine should be pluggable, and a more familiar default such as Mustache should be used, ideally aligning as far as possible with existing Spring support. Jinjava provides solid JVM support for Jinja and it should also be an option because of its pervasive use in the Gen AI space.

Reasons:

  • StringTemplate is not particularly popular and is not a common choice in the broader Spring ecosystem. Forcing its use creates unnecessary friction for new adopters, and frustration for existing advanced users.
  • Most existing IP around Gen AI comes out of the Python ecosystem. StringTemplate does not have a Python implementation. Thus supporting only StringTemplate makes it impossible to benefit from the many valuable prompts produced by this ecosystem. Not only is reuse impossible; porting even simple templates from Jinja to StringTemplate is harder than to, say, Mustache.
  • Pluggability has always been a core Spring value. Spring MVC supported different template engines from its inception. Hardcoding one template engine is not Spring-like.
  • StringTemplate syntax is quirky and likely to be off-putting to developers, even if they're familiar with other templating technologies.

While variable interpolation is fine, more complex things are quirky with StringTemplate. For example, looping is a common requirement in prompt templates. Consider how it looks in various popular template languages:

Mustache (familiar to many developers on all stacks):

{{#items}}
    {{.}}
{{/items}}

Jinja (the norm in Python and probably the most widely used in Gen AI):

{% for item in items %}
    {{ item }}
{% endfor %}

Both of these are easy for any developer to grasp, even if they haven't seen that particular syntax.

Now take StringTemplate:

list(items) ::= 
<items:{item | <item>}; separator="\n">
>>

This looks more like a BNF grammar than a typical template.

@johnsonr johnsonr changed the title StringTemplate should not be only prompt template mechanism StringTemplate should not be the only prompt template mechanism Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants