mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-03-15 00:07:28 +00:00
Jinja2 is a lightweight template parser that's used in Transformers for parsing chat completions. It's much more efficient than Fastchat and can be imported as part of requirements. Also allows for unblocking Pydantic's version. Users now have to provide their own template if needed. A separate repo may be usable for common prompt template storage. Signed-off-by: kingbri <bdashore3@proton.me>
30 lines
668 B
Django/Jinja
30 lines
668 B
Django/Jinja
{{ (messages|selectattr('role', 'equalto', 'system')|list|last).content|trim if (messages|selectattr('role', 'equalto', 'system')|list) else '' }}
|
|
|
|
{% for message in messages %}
|
|
{% if message['role'] == 'user' %}
|
|
### Instruction:
|
|
{{ message['content']|trim -}}
|
|
{% if not loop.last %}
|
|
|
|
|
|
{% endif %}
|
|
{% elif message['role'] == 'assistant' %}
|
|
### Response:
|
|
{{ message['content']|trim -}}
|
|
{% if not loop.last %}
|
|
|
|
|
|
{% endif %}
|
|
{% elif message['role'] == 'user_context' %}
|
|
### Input:
|
|
{{ message['content']|trim -}}
|
|
{% if not loop.last %}
|
|
|
|
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}
|
|
### Response:
|
|
{% endif %}
|