{#- 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 -%}