Update chat_template.jinja
Browse files- chat_template.jinja +61 -34
chat_template.jinja
CHANGED
|
@@ -1,19 +1,31 @@
|
|
| 1 |
{%- if tools %}
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
{%- else %}
|
| 13 |
{%- if messages[0].role == 'system' %}
|
| 14 |
-
|
|
|
|
| 15 |
{%- endif %}
|
| 16 |
{%- endif %}
|
|
|
|
| 17 |
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 18 |
{%- for message in messages[::-1] %}
|
| 19 |
{%- set index = (messages|length - 1) - loop.index0 %}
|
|
@@ -22,14 +34,17 @@
|
|
| 22 |
{%- set ns.last_query_index = index %}
|
| 23 |
{%- endif %}
|
| 24 |
{%- endfor %}
|
|
|
|
| 25 |
{%- for message in messages %}
|
| 26 |
{%- if message.content is string %}
|
| 27 |
{%- set content = message.content %}
|
| 28 |
{%- else %}
|
| 29 |
{%- set content = '' %}
|
| 30 |
{%- endif %}
|
|
|
|
| 31 |
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 32 |
-
|
|
|
|
| 33 |
{%- elif message.role == "assistant" %}
|
| 34 |
{%- set reasoning_content = '' %}
|
| 35 |
{%- if message.reasoning_content is string %}
|
|
@@ -40,50 +55,62 @@
|
|
| 40 |
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 41 |
{%- endif %}
|
| 42 |
{%- endif %}
|
|
|
|
| 43 |
{%- if loop.index0 > ns.last_query_index %}
|
| 44 |
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
{%- else %}
|
| 47 |
-
|
|
|
|
| 48 |
{%- endif %}
|
| 49 |
{%- else %}
|
| 50 |
-
|
|
|
|
| 51 |
{%- endif %}
|
|
|
|
| 52 |
{%- if message.tool_calls %}
|
| 53 |
{%- for tool_call in message.tool_calls %}
|
| 54 |
{%- if (loop.first and content) or (not loop.first) %}
|
| 55 |
-
{{- '\n' }}
|
| 56 |
{%- endif %}
|
| 57 |
{%- if tool_call.function %}
|
| 58 |
{%- set tool_call = tool_call.function %}
|
| 59 |
{%- endif %}
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
{%- endfor %}
|
| 70 |
{%- endif %}
|
| 71 |
-
|
| 72 |
{%- elif message.role == "tool" %}
|
| 73 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 74 |
-
|
| 75 |
{%- endif %}
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 80 |
-
|
| 81 |
{%- endif %}
|
| 82 |
{%- endif %}
|
| 83 |
{%- endfor %}
|
|
|
|
| 84 |
{%- if add_generation_prompt %}
|
| 85 |
-
|
| 86 |
-
{%- if
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
{%- endif %}
|
| 89 |
{%- endif %}
|
|
|
|
| 1 |
{%- if tools %}
|
| 2 |
+
<|im_start|>system
|
| 3 |
+
{%- if messages[0].role == 'system' %}
|
| 4 |
+
{{ messages[0].content }}
|
| 5 |
+
|
| 6 |
+
{%- endif %}
|
| 7 |
+
# Tools
|
| 8 |
+
|
| 9 |
+
You may call one or more functions to assist with the user query.
|
| 10 |
+
|
| 11 |
+
You are provided with function signatures within <tools></tools> XML tags:
|
| 12 |
+
<tools>
|
| 13 |
+
{%- for tool in tools %}
|
| 14 |
+
{{ tool | tojson }}
|
| 15 |
+
{%- endfor %}
|
| 16 |
+
</tools>
|
| 17 |
+
|
| 18 |
+
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
|
| 19 |
+
<tool_call>
|
| 20 |
+
{"name": <function-name>, "arguments": <args-json-object>}
|
| 21 |
+
</tool_call><|im_end|>
|
| 22 |
{%- else %}
|
| 23 |
{%- if messages[0].role == 'system' %}
|
| 24 |
+
<|im_start|>system
|
| 25 |
+
{{ messages[0].content }}<|im_end|>
|
| 26 |
{%- endif %}
|
| 27 |
{%- endif %}
|
| 28 |
+
|
| 29 |
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 30 |
{%- for message in messages[::-1] %}
|
| 31 |
{%- set index = (messages|length - 1) - loop.index0 %}
|
|
|
|
| 34 |
{%- set ns.last_query_index = index %}
|
| 35 |
{%- endif %}
|
| 36 |
{%- endfor %}
|
| 37 |
+
|
| 38 |
{%- for message in messages %}
|
| 39 |
{%- if message.content is string %}
|
| 40 |
{%- set content = message.content %}
|
| 41 |
{%- else %}
|
| 42 |
{%- set content = '' %}
|
| 43 |
{%- endif %}
|
| 44 |
+
|
| 45 |
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
| 46 |
+
<|im_start|>{{ message.role }}
|
| 47 |
+
{{ content }}<|im_end|>
|
| 48 |
{%- elif message.role == "assistant" %}
|
| 49 |
{%- set reasoning_content = '' %}
|
| 50 |
{%- if message.reasoning_content is string %}
|
|
|
|
| 55 |
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 56 |
{%- endif %}
|
| 57 |
{%- endif %}
|
| 58 |
+
|
| 59 |
{%- if loop.index0 > ns.last_query_index %}
|
| 60 |
{%- if loop.last or (not loop.last and reasoning_content) %}
|
| 61 |
+
<|im_start|>assistant
|
| 62 |
+
<think>
|
| 63 |
+
{{ reasoning_content.strip('\n') }}
|
| 64 |
+
</think>
|
| 65 |
+
|
| 66 |
+
{{ content.lstrip('\n') }}
|
| 67 |
{%- else %}
|
| 68 |
+
<|im_start|>assistant
|
| 69 |
+
{{ content }}
|
| 70 |
{%- endif %}
|
| 71 |
{%- else %}
|
| 72 |
+
<|im_start|>assistant
|
| 73 |
+
{{ content }}
|
| 74 |
{%- endif %}
|
| 75 |
+
|
| 76 |
{%- if message.tool_calls %}
|
| 77 |
{%- for tool_call in message.tool_calls %}
|
| 78 |
{%- if (loop.first and content) or (not loop.first) %}
|
|
|
|
| 79 |
{%- endif %}
|
| 80 |
{%- if tool_call.function %}
|
| 81 |
{%- set tool_call = tool_call.function %}
|
| 82 |
{%- endif %}
|
| 83 |
+
<tool_call>
|
| 84 |
+
{"name": "{{ tool_call.name }}", "arguments":
|
| 85 |
+
{%- if tool_call.arguments is string %}
|
| 86 |
+
{{ tool_call.arguments }}
|
| 87 |
+
{%- else %}
|
| 88 |
+
{{ tool_call.arguments | tojson }}
|
| 89 |
+
{%- endif %}
|
| 90 |
+
}
|
| 91 |
+
</tool_call>
|
| 92 |
{%- endfor %}
|
| 93 |
{%- endif %}
|
| 94 |
+
<|im_end|>
|
| 95 |
{%- elif message.role == "tool" %}
|
| 96 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 97 |
+
<|im_start|>user
|
| 98 |
{%- endif %}
|
| 99 |
+
<tool_response>
|
| 100 |
+
{{ content }}
|
| 101 |
+
</tool_response>
|
| 102 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
| 103 |
+
<|im_end|>
|
| 104 |
{%- endif %}
|
| 105 |
{%- endif %}
|
| 106 |
{%- endfor %}
|
| 107 |
+
|
| 108 |
{%- if add_generation_prompt %}
|
| 109 |
+
<|im_start|>assistant
|
| 110 |
+
{%- if true %}
|
| 111 |
+
<think>
|
| 112 |
+
|
| 113 |
+
</think>
|
| 114 |
+
|
| 115 |
{%- endif %}
|
| 116 |
{%- endif %}
|