Godcat252 commited on
Commit
6edb0bb
·
verified ·
1 Parent(s): e6a1d4d

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +11 -0
chat_template.jinja CHANGED
@@ -14,6 +14,7 @@
14
  {%- endfor -%}
15
  {%- endif -%}
16
  {%- endmacro -%}
 
17
  {% macro set_roles(message) -%}
18
  {%- set role_name = message.get('name') or message['role'] -%}
19
  {%- if message['role'] == 'user' -%}
@@ -24,6 +25,8 @@
24
  <|im_system|>{{role_name}}<|im_middle|>
25
  {%- endif -%}
26
  {%- endmacro -%}
 
 
27
  {%- macro render_toolcalls(message) -%}
28
  <|tool_calls_section_begin|>
29
  {%- for tool_call in message['tool_calls'] -%}
@@ -32,6 +35,8 @@
32
  {%- endfor -%}
33
  <|tool_calls_section_end|>
34
  {%- endmacro -%}
 
 
35
  {%- set preserve_thinking = preserve_thinking | default(false) -%}
36
  {# Find last non-tool-call assistant message. If preserve_thinking, keep -1 so hist is empty and all msgs use suffix (retain reasoning). #}
37
  {%- set ns = namespace(last_non_tool_call_assistant_msg=-1) -%}
@@ -43,9 +48,11 @@
43
  {%- endif -%}
44
  {%- endfor -%}
45
  {%- endif -%}
 
46
  {# split all messages into history & suffix, reasoning_content in suffix should be reserved.#}
47
  {%- set hist_msgs = messages[:ns.last_non_tool_call_assistant_msg+1] -%}
48
  {%- set suffix_msgs = messages[ns.last_non_tool_call_assistant_msg+1:] -%}
 
49
  {%- if tools -%}
50
  {%- if tools_ts_str -%}
51
  <|im_system|>tool_declare<|im_middle|>{{ tools_ts_str }}<|im_end|>
@@ -53,6 +60,7 @@
53
  <|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
54
  {%- endif -%}
55
  {%- endif -%}
 
56
 
57
  {%- for message in hist_msgs -%}
58
  {{set_roles(message)}}
@@ -70,6 +78,7 @@
70
  {%- endif -%}
71
  <|im_end|>
72
  {%- endfor -%}
 
73
  {%- for message in suffix_msgs -%}
74
  {{set_roles(message)}}
75
  {%- if message['role'] == 'assistant' -%}
@@ -91,6 +100,8 @@
91
  {%- endif -%}
92
  <|im_end|>
93
  {%- endfor -%}
 
 
94
  {%- if add_generation_prompt -%}
95
  <|im_assistant|>assistant<|im_middle|>
96
  {%- if thinking is defined and thinking is false -%}
 
14
  {%- endfor -%}
15
  {%- endif -%}
16
  {%- endmacro -%}
17
+
18
  {% macro set_roles(message) -%}
19
  {%- set role_name = message.get('name') or message['role'] -%}
20
  {%- if message['role'] == 'user' -%}
 
25
  <|im_system|>{{role_name}}<|im_middle|>
26
  {%- endif -%}
27
  {%- endmacro -%}
28
+
29
+
30
  {%- macro render_toolcalls(message) -%}
31
  <|tool_calls_section_begin|>
32
  {%- for tool_call in message['tool_calls'] -%}
 
35
  {%- endfor -%}
36
  <|tool_calls_section_end|>
37
  {%- endmacro -%}
38
+
39
+
40
  {%- set preserve_thinking = preserve_thinking | default(false) -%}
41
  {# Find last non-tool-call assistant message. If preserve_thinking, keep -1 so hist is empty and all msgs use suffix (retain reasoning). #}
42
  {%- set ns = namespace(last_non_tool_call_assistant_msg=-1) -%}
 
48
  {%- endif -%}
49
  {%- endfor -%}
50
  {%- endif -%}
51
+
52
  {# split all messages into history & suffix, reasoning_content in suffix should be reserved.#}
53
  {%- set hist_msgs = messages[:ns.last_non_tool_call_assistant_msg+1] -%}
54
  {%- set suffix_msgs = messages[ns.last_non_tool_call_assistant_msg+1:] -%}
55
+
56
  {%- if tools -%}
57
  {%- if tools_ts_str -%}
58
  <|im_system|>tool_declare<|im_middle|>{{ tools_ts_str }}<|im_end|>
 
60
  <|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
61
  {%- endif -%}
62
  {%- endif -%}
63
+
64
 
65
  {%- for message in hist_msgs -%}
66
  {{set_roles(message)}}
 
78
  {%- endif -%}
79
  <|im_end|>
80
  {%- endfor -%}
81
+
82
  {%- for message in suffix_msgs -%}
83
  {{set_roles(message)}}
84
  {%- if message['role'] == 'assistant' -%}
 
100
  {%- endif -%}
101
  <|im_end|>
102
  {%- endfor -%}
103
+
104
+
105
  {%- if add_generation_prompt -%}
106
  <|im_assistant|>assistant<|im_middle|>
107
  {%- if thinking is defined and thinking is false -%}