2026-07-26 18:21:35 +07:00
{{ - bos_token }}
{% - if tools %}
{% - set tool_definitions %}
{{ - "# Tools\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
{% - for tool in tools %}
{{ - "\n" }}
{{ - tool | tojson }}
{% - endfor %}
2026-08-03 08:58:13 +07:00
{{ - '\n</tools>\n\nTool usage guidelines:\n- You may call zero or more functions. If no function calls are needed, just answer normally.\n- When calling a function, wrap each call in <tool_call> tags:\n<tool_call>\n<function=name>\n<parameter=key>value</parameter>\n</function>\n</tool_call>' }}
2026-07-26 18:21:35 +07:00
{% - endset %}
{{ - '<|im_start|>system\n' }}
{% - if messages [ 0 ] .role == 'system' %}
{{ - messages [ 0 ] .content + '\n\n' + tool_definitions }}
{% - else %}
{{ - tool_definitions }}
{% - endif %}
{{ - '<|im_end|>\n' }}
{% - else %}
{% - if messages [ 0 ] .role == 'system' %}
{{ - '<|im_start|>system\n' + messages [ 0 ] .content + '<|im_end|>\n' }}
{% - endif %}
{% - endif %}
{% - for message in messages %}
{% - set content = message.content %}
{% - if ( message.role == "user" ) or ( message.role == "system" and not loop .first ) %}
{{ - '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
{% - elif message.role == "assistant" %}
2026-08-03 08:58:13 +07:00
{#- Tool-call XML from history is pre-embedded in content by build_prompt. #}
{{ - '<|im_start|>assistant\n' + content + '<|im_end|>\n' }}
2026-07-26 18:21:35 +07:00
{% - elif message.role == "tool" %}
{{ - '<|im_start|>user\n<tool_response>\n' + content + '\n</tool_response><|im_end|>\n' }}
{% - endif %}
{% - endfor %}
{% - if add_generation_prompt %}
{{ - '<|im_start|>assistant\n' }}
{% - if enable_thinking is defined %}
{% - if enable_thinking is false %}
{{ - '<think>\n\n</think>\n\n' }}
{% - elif enable_thinking is true %}
{{ - '<think>\n' }}
{% - endif %}
{% - endif %}
{% - endif %}