|
|
|
|
|
|
|
|
|
|
|
|
|
|
{%- 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 -%} |
|
|
|
|
|
|
|
|
{%- 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 -%} |
|
|
|
|
|
|
|
|
{%- if add_generation_prompt -%} |
|
|
<|im_start|>assistant |
|
|
{% generation %}{% endgeneration %} |
|
|
{%- endif -%} |
|
|
|
|
|
|