File size: 1,433 Bytes
ccd9a41 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
{#- Daisy Chat Template v2 -#}
{#- Supports: ChatML format, tool calling, multipart content -#}
{#- Macro to render content (string or multipart) -#}
{%- macro render_content(content) -%}
{%- if content is string -%}
{{ content }}
{%- elif content is iterable -%}
{%- for part in content -%}
{%- if part.type == 'text' -%}
{{ part.text }}
{%- elif part.type == 'tool_call' -%}
<|tool_call|>{{ part.text }}<|/tool_call|>
{%- elif part.type == 'tool_result' -%}
<|tool_result|>{{ part.text }}<|/tool_result|>
{%- elif part.type == 'python' -%}
<|python|>{{ part.text }}<|/python|>
{%- elif part.type == 'output' -%}
<|output|>{{ part.text }}<|/output|>
{%- elif part.type == 'think' -%}
<|think|>{{ part.text }}<|/think|>
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{ content }}
{%- endif -%}
{%- endmacro -%}
{#- Main message loop -#}
{%- for message in messages -%}
{%- if message.role == 'system' -%}
<|im_start|>system
{{ message.content }}<|im_end|>
{% elif message.role == 'user' -%}
<|im_start|>user
{{ message.content }}<|im_end|>
{% elif message.role == 'assistant' -%}
<|im_start|>assistant
{% generation %}{{ render_content(message.content) }}{% endgeneration %}<|im_end|>
{% elif message.role == 'tool' -%}
<|tool_result|>{{ message.content }}<|/tool_result|>
{%- endif -%}
{%- endfor -%}
{#- Generation prompt -#}
{%- if add_generation_prompt -%}
<|im_start|>assistant
{% generation %}{% endgeneration %}
{%- endif -%}
|