yiqichen01 commited on
Commit
f332661
·
verified ·
1 Parent(s): b53bd70

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +36 -74
chat_template.jinja CHANGED
@@ -1,61 +1,26 @@
1
- {# ----------‑‑‑ special token variables ‑‑‑---------- #}
2
- {%- set HYTK = '' %}
3
  {%- set bos_token = '<|hy_begin▁of▁sentence|>' %}
4
  {%- set pad_token = '<|hy_▁pad▁|>' %}
5
  {%- set user_token = '<|hy_User|>' %}
6
  {%- set assistant_token = '<|hy_Assistant|>' %}
7
- {%- set eos_token = '<eos:6124c78e>' %}
8
- {# ----------‑‑‑ tokens with md5 encoding (conditional on HYTK) ‑‑‑---------- #}
9
- {%- if HYTK %}
10
- {%- set think_begin_token = '<think:{}>'.format(HYTK) %}
11
- {%- set think_end_token = '</think:{}>'.format(HYTK) %}
12
- {%- set toolcalls_begin_token = '<tool_calls:{}>'.format(HYTK) %}
13
- {%- set toolcalls_end_token = '</tool_calls:{}>'.format(HYTK) %}
14
- {%- set toolcall_begin_token = '<tool_call:{}>'.format(HYTK) %}
15
- {%- set toolcall_end_token = '</tool_call:{}>'.format(HYTK) %}
16
- {%- set toolsep_token = '<tool_sep:{}>'.format(HYTK) %}
17
- {%- set argkey_begin_token = '<arg_key:{}>'.format(HYTK) %}
18
- {%- set argkey_end_token = '</arg_key:{}>'.format(HYTK) %}
19
- {%- set argvalue_begin_token = '<arg_value:{}>'.format(HYTK) %}
20
- {%- set argvalue_end_token = '</arg_value:{}>'.format(HYTK) %}
21
- {%- set toolresponses_begin_token = '<tool_responses:{}>'.format(HYTK) %}
22
- {%- set toolresponses_end_token = '</tool_responses:{}>'.format(HYTK) %}
23
- {%- set toolresponse_begin_token = '<tool_response:{}>'.format(HYTK) %}
24
- {%- set toolresponse_end_token = '</tool_response:{}>'.format(HYTK) %}
25
- {%- set reasoning_mode_token = '<|reasoning_mode|>' %}
26
- {%- set toolcalls_begin_ds_token = '<|tool▁calls▁begin|>' %}
27
- {%- set toolcalls_end_ds_token = '<|tool▁calls▁end|>' %}
28
- {%- set toolcall_begin_ds_token = '<|tool▁call▁begin|>' %}
29
- {%- set toolcall_end_ds_token = '<|tool▁call▁end|>' %}
30
- {%- set toolsep_ds_token = '<|tool▁sep|>' %}
31
- {%- set tooloutput_begin_ds_token = '<|tool▁output▁begin|>' %}
32
- {%- set tooloutput_end_ds_token = '<|tool▁output▁end|>' %}
33
- {%- else %}
34
- {%- set think_begin_token = '<think>' %}
35
- {%- set think_end_token = '</think>' %}
36
- {%- set toolcalls_begin_token = '<tool_calls>' %}
37
- {%- set toolcalls_end_token = '</tool_calls>' %}
38
- {%- set toolcall_begin_token = '<tool_call>' %}
39
- {%- set toolcall_end_token = '</tool_call>' %}
40
- {%- set toolsep_token = '<tool_sep>' %}
41
- {%- set argkey_begin_token = '<arg_key>' %}
42
- {%- set argkey_end_token = '</arg_key>' %}
43
- {%- set argvalue_begin_token = '<arg_value>' %}
44
- {%- set argvalue_end_token = '</arg_value>' %}
45
- {%- set toolresponses_begin_token = '<tool_responses>' %}
46
- {%- set toolresponses_end_token = '</tool_responses>' %}
47
- {%- set toolresponse_begin_token = '<tool_response>' %}
48
- {%- set toolresponse_end_token = '</tool_response>' %}
49
- {%- set reasoning_mode_token = '<|reasoning_mode|>' %}
50
- {%- set toolcalls_begin_ds_token = '<|tool▁calls▁begin|>' %}
51
- {%- set toolcalls_end_ds_token = '<|tool▁calls▁end|>' %}
52
- {%- set toolcall_begin_ds_token = '<|tool▁call▁begin|>' %}
53
- {%- set toolcall_end_ds_token = '<|tool▁call▁end|>' %}
54
- {%- set toolsep_ds_token = '<|tool▁sep|>' %}
55
- {%- set tooloutput_begin_ds_token = '<|tool▁output▁begin|>' %}
56
- {%- set tooloutput_end_ds_token = '<|tool▁output▁end|>' %}
57
- {%- endif %}
58
- {# ----------‑‑‑ hyperparameters variables ‑‑‑---------- #}
59
  {%- if not add_generation_prompt is defined %}
60
  {%- set add_generation_prompt = false %}
61
  {%- endif %}
@@ -68,9 +33,6 @@
68
  {%- if not is_training is defined %}
69
  {%- set is_training = false %}
70
  {%- endif %}
71
- {%- if not is_ai_search is defined %}
72
- {%- set is_ai_search = false %}
73
- {%- endif %}
74
  {%- if not reasoning_effort is defined or reasoning_effort not in ['high', 'low', 'no_think'] %}
75
  {%- set reasoning_effort = 'no_think' %}
76
  {%- endif %}
@@ -143,23 +105,30 @@
143
  {%- set last_ns = namespace(last_is_assistant=false) %}
144
  {%- for message in messages %}
145
  {%- if message['role'] == 'user' %}
146
- {%- if prev_ns.is_tool and not is_ai_search %}
147
  {{- toolresponses_end_token }}
148
  {%- endif %}
149
  {{- user_token + visible_text(message['content']) }}
150
  {%- set prev_ns.is_tool = false %}
151
  {%- endif %}
152
  {%- if message['role'] == 'assistant' %}
 
 
 
 
 
 
 
153
  {%- if is_training %}
154
- {%- if 'reasoning_content' in message and message['reasoning_content'] is string %}
155
- {%- set content = think_begin_token + message['reasoning_content'] + think_end_token + visible_text(message['content']) %}
156
  {%- else %}
157
  {%- set content = think_begin_token + think_end_token + visible_text(message['content']) %}
158
  {%- endif %}
159
  {%- else %}
160
  {%- if interleaved_thinking %}
161
- {%- if loop.index0 > ns.last_user_index and 'reasoning_content' in message and message['reasoning_content'] is string %}
162
- {%- set content = think_begin_token + message['reasoning_content'] + think_end_token + visible_text(message['content']) %}
163
  {%- else %}
164
  {%- set content = think_begin_token + think_end_token + visible_text(message['content']) %}
165
  {%- endif %}
@@ -167,7 +136,7 @@
167
  {%- set content = think_begin_token + think_end_token + visible_text(message['content']) %}
168
  {%- endif %}
169
  {%- endif %}
170
- {%- if prev_ns.is_tool and not is_ai_search %}
171
  {{- toolresponses_end_token }}
172
  {%- endif %}
173
  {{- assistant_token }}
@@ -199,30 +168,23 @@
199
  {%- endif %}
200
  {%- if message['role'] == 'tool' %}
201
  {%- set prev_ns.is_tool = true %}
202
- {%- if prev_ns.is_tool_first and not is_ai_search %}
203
  {{- toolresponses_begin_token + '\n' }}
204
  {%- set prev_ns.is_tool_first = false %}
205
  {%- endif %}
206
- {%- if is_ai_search %}
207
- {{- tooloutput_begin_ds_token + visible_text(message['content']) + tooloutput_end_ds_token }}
208
- {%- else %}
209
- {{- toolresponse_begin_token + '\n' + visible_text(message['content']) + '\n' + toolresponse_end_token + '\n' }}
210
- {%- endif %}
211
  {%- endif %}
212
  {%- if loop.last and message['role'] == 'assistant' %}
213
  {%- set last_ns.last_is_assistant = true %}
214
  {%- endif %}
215
 
216
  {%- endfor %}
217
- {%- if prev_ns.is_tool and not is_ai_search %}
218
  {{- toolresponses_end_token }}
219
  {%- endif %}
220
  {%- if add_generation_prompt %}
221
  {%- if not last_ns.last_is_assistant %}
222
- {%- if is_ai_search %}
223
- {{- assistant_token }}
224
- {{- think_begin_token + think_end_token }}
225
- {%- elif reasoning_effort is defined and reasoning_effort in ['low', 'high'] %}
226
  {{- assistant_token + think_begin_token }}
227
  {%- elif reasoning_effort is defined and reasoning_effort == 'no_think' %}
228
  {{- assistant_token + think_begin_token + think_end_token }}
 
1
+ {#- ----------‑‑‑ special token variables ‑‑‑---------- -#}
 
2
  {%- set bos_token = '<|hy_begin▁of▁sentence|>' %}
3
  {%- set pad_token = '<|hy_▁pad▁|>' %}
4
  {%- set user_token = '<|hy_User|>' %}
5
  {%- set assistant_token = '<|hy_Assistant|>' %}
6
+ {%- set eos_token = '<|hy_eos|>' %}
7
+ {%- set think_begin_token = '<think>' %}
8
+ {%- set think_end_token = '</think>' %}
9
+ {%- set toolcalls_begin_token = '<tool_calls>' %}
10
+ {%- set toolcalls_end_token = '</tool_calls>' %}
11
+ {%- set toolcall_begin_token = '<tool_call>' %}
12
+ {%- set toolcall_end_token = '</tool_call>' %}
13
+ {%- set toolsep_token = '<tool_sep>' %}
14
+ {%- set argkey_begin_token = '<arg_key>' %}
15
+ {%- set argkey_end_token = '</arg_key>' %}
16
+ {%- set argvalue_begin_token = '<arg_value>' %}
17
+ {%- set argvalue_end_token = '</arg_value>' %}
18
+ {%- set toolresponses_begin_token = '<tool_responses>' %}
19
+ {%- set toolresponses_end_token = '</tool_responses>' %}
20
+ {%- set toolresponse_begin_token = '<tool_response>' %}
21
+ {%- set toolresponse_end_token = '</tool_response>' %}
22
+ {%- set reasoning_mode_token = '<|reasoning_mode|>' %}
23
+ {#- ----------‑‑‑ hyperparameters variables ‑‑‑---------- -#}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  {%- if not add_generation_prompt is defined %}
25
  {%- set add_generation_prompt = false %}
26
  {%- endif %}
 
33
  {%- if not is_training is defined %}
34
  {%- set is_training = false %}
35
  {%- endif %}
 
 
 
36
  {%- if not reasoning_effort is defined or reasoning_effort not in ['high', 'low', 'no_think'] %}
37
  {%- set reasoning_effort = 'no_think' %}
38
  {%- endif %}
 
105
  {%- set last_ns = namespace(last_is_assistant=false) %}
106
  {%- for message in messages %}
107
  {%- if message['role'] == 'user' %}
108
+ {%- if prev_ns.is_tool %}
109
  {{- toolresponses_end_token }}
110
  {%- endif %}
111
  {{- user_token + visible_text(message['content']) }}
112
  {%- set prev_ns.is_tool = false %}
113
  {%- endif %}
114
  {%- if message['role'] == 'assistant' %}
115
+ {%- if 'reasoning_content' in message and message['reasoning_content'] is string %}
116
+ {%- set rc = message['reasoning_content'] %}
117
+ {%- elif 'reasoning' in message and message['reasoning'] is string %}
118
+ {%- set rc = message['reasoning'] %}
119
+ {%- else %}
120
+ {%- set rc = none %}
121
+ {%- endif %}
122
  {%- if is_training %}
123
+ {%- if rc is not none %}
124
+ {%- set content = think_begin_token + rc + think_end_token + visible_text(message['content']) %}
125
  {%- else %}
126
  {%- set content = think_begin_token + think_end_token + visible_text(message['content']) %}
127
  {%- endif %}
128
  {%- else %}
129
  {%- if interleaved_thinking %}
130
+ {%- if loop.index0 > ns.last_user_index and rc is not none %}
131
+ {%- set content = think_begin_token + rc + think_end_token + visible_text(message['content']) %}
132
  {%- else %}
133
  {%- set content = think_begin_token + think_end_token + visible_text(message['content']) %}
134
  {%- endif %}
 
136
  {%- set content = think_begin_token + think_end_token + visible_text(message['content']) %}
137
  {%- endif %}
138
  {%- endif %}
139
+ {%- if prev_ns.is_tool %}
140
  {{- toolresponses_end_token }}
141
  {%- endif %}
142
  {{- assistant_token }}
 
168
  {%- endif %}
169
  {%- if message['role'] == 'tool' %}
170
  {%- set prev_ns.is_tool = true %}
171
+ {%- if prev_ns.is_tool_first %}
172
  {{- toolresponses_begin_token + '\n' }}
173
  {%- set prev_ns.is_tool_first = false %}
174
  {%- endif %}
175
+ {{- toolresponse_begin_token + '\n' + visible_text(message['content']) + '\n' + toolresponse_end_token + '\n' }}
 
 
 
 
176
  {%- endif %}
177
  {%- if loop.last and message['role'] == 'assistant' %}
178
  {%- set last_ns.last_is_assistant = true %}
179
  {%- endif %}
180
 
181
  {%- endfor %}
182
+ {%- if prev_ns.is_tool %}
183
  {{- toolresponses_end_token }}
184
  {%- endif %}
185
  {%- if add_generation_prompt %}
186
  {%- if not last_ns.last_is_assistant %}
187
+ {%- if reasoning_effort is defined and reasoning_effort in ['low', 'high'] %}
 
 
 
188
  {{- assistant_token + think_begin_token }}
189
  {%- elif reasoning_effort is defined and reasoning_effort == 'no_think' %}
190
  {{- assistant_token + think_begin_token + think_end_token }}