Update chat_template.jinja
Browse files- chat_template.jinja +23 -13
chat_template.jinja
CHANGED
@@ -17,27 +17,34 @@
|
|
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 %}
|
20 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
{%- set ns.multi_step_tool = false %}
|
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 |
-
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
33 |
{%- elif message.role == "assistant" %}
|
|
|
34 |
{%- set reasoning_content = '' %}
|
35 |
-
{%- if message.reasoning_content is
|
36 |
{%- set reasoning_content = message.reasoning_content %}
|
37 |
{%- else %}
|
38 |
-
{%- if '</think>' in content %}
|
39 |
-
{%- set
|
40 |
-
{%- set
|
|
|
41 |
{%- endif %}
|
42 |
{%- endif %}
|
43 |
{%- if loop.index0 > ns.last_query_index %}
|
@@ -74,7 +81,7 @@
|
|
74 |
{{- '<|im_start|>user' }}
|
75 |
{%- endif %}
|
76 |
{{- '\n<tool_response>\n' }}
|
77 |
-
{{- content }}
|
78 |
{{- '\n</tool_response>' }}
|
79 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
80 |
{{- '<|im_end|>\n' }}
|
@@ -82,5 +89,8 @@
|
|
82 |
{%- endif %}
|
83 |
{%- endfor %}
|
84 |
{%- if add_generation_prompt %}
|
85 |
-
{{- '<|im_start|>assistant\n
|
|
|
|
|
|
|
86 |
{%- 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 %}
|
20 |
+
{%- set tool_start = "<tool_response>" %}
|
21 |
+
{%- set tool_start_length = tool_start|length %}
|
22 |
+
{%- set start_of_message = message.content[:tool_start_length] %}
|
23 |
+
{%- set tool_end = "</tool_response>" %}
|
24 |
+
{%- set tool_end_length = tool_end|length %}
|
25 |
+
{%- set start_pos = (message.content|length) - tool_end_length %}
|
26 |
+
{%- if start_pos < 0 %}
|
27 |
+
{%- set start_pos = 0 %}
|
28 |
+
{%- endif %}
|
29 |
+
{%- set end_of_message = message.content[start_pos:] %}
|
30 |
+
{%- if ns.multi_step_tool and message.role == "user" and not(start_of_message == tool_start and end_of_message == tool_end) %}
|
31 |
{%- set ns.multi_step_tool = false %}
|
32 |
{%- set ns.last_query_index = index %}
|
33 |
{%- endif %}
|
34 |
{%- endfor %}
|
35 |
{%- for message in messages %}
|
|
|
|
|
|
|
|
|
|
|
36 |
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
|
37 |
+
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
38 |
{%- elif message.role == "assistant" %}
|
39 |
+
{%- set content = message.content %}
|
40 |
{%- set reasoning_content = '' %}
|
41 |
+
{%- if message.reasoning_content is defined and message.reasoning_content is not none %}
|
42 |
{%- set reasoning_content = message.reasoning_content %}
|
43 |
{%- else %}
|
44 |
+
{%- if '</think>' in message.content %}
|
45 |
+
{%- set content = (message.content.split('</think>')|last).lstrip('\n') %}
|
46 |
+
{%- set reasoning_content = (message.content.split('</think>')|first).rstrip('\n') %}
|
47 |
+
{%- set reasoning_content = (reasoning_content.split('<think>')|last).lstrip('\n') %}
|
48 |
{%- endif %}
|
49 |
{%- endif %}
|
50 |
{%- if loop.index0 > ns.last_query_index %}
|
|
|
81 |
{{- '<|im_start|>user' }}
|
82 |
{%- endif %}
|
83 |
{{- '\n<tool_response>\n' }}
|
84 |
+
{{- message.content }}
|
85 |
{{- '\n</tool_response>' }}
|
86 |
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
87 |
{{- '<|im_end|>\n' }}
|
|
|
89 |
{%- endif %}
|
90 |
{%- endfor %}
|
91 |
{%- if add_generation_prompt %}
|
92 |
+
{{- '<|im_start|>assistant\n' }}
|
93 |
+
{%- if enable_thinking is defined and enable_thinking is false %}
|
94 |
+
{{- '<think>\n\n</think>\n\n' }}
|
95 |
+
{%- endif %}
|
96 |
{%- endif %}
|