Spaces:
Sleeping
Sleeping
iteration, for example using {% if loop.last %} to check if the current message is the last message in the | |
conversation. Here's an example that puts these ideas together to add a generation prompt at the end of the | |
conversation if add_generation_prompt is True: | |
{%- if loop.last and add_generation_prompt %} | |
{{- bos_token + 'Assistant:\n' }} | |
{%- endif %} | |
Compatibility with non-Python Jinja | |
There are multiple implementations of Jinja in various languages. They generally have the same syntax, | |
but a key difference is that when you're writing a template in Python you can use Python methods, such as | |
.lower() on strings or .items() on dicts. This will break if someone tries to use your template on a non-Python | |
implementation of Jinja. Non-Python implementations are particularly common in deployment environments, where JS | |
and Rust are very popular. | |
Don't panic, though! There are a few easy changes you can make to your templates to ensure they're compatible across | |
all implementations of Jinja: |