caiovicentino1 armand0e commited on
Commit
5f325f6
·
1 Parent(s): f6392e8

Update chat_template.jinja (#1)

Browse files

- Update chat_template.jinja (d7fb7756c7a84c7a09d0b4b1b4ce8202e4b89a8e)


Co-authored-by: Arman Rafiee <armand0e@users.noreply.huggingface.co>

Files changed (1) hide show
  1. chat_template.jinja +9 -10
chat_template.jinja CHANGED
@@ -151,13 +151,14 @@
151
  {%- endmacro -%}
152
 
153
  {%- set ns = namespace(prev_message_type=None) -%}
154
- {%- set thinking_enabled = enable_thinking | default(true) -%}
155
  {%- set loop_messages = messages -%}
156
  {{ bos_token }}
157
- {%- if thinking_enabled or tools or messages[0]['role'] in ['system', 'developer'] -%}
 
158
  {{- '<|turn>system\n' -}}
159
 
160
- {%- if thinking_enabled -%}
 
161
  {{- '<|think|>' -}}
162
  {%- set ns.prev_message_type = 'think' -%}
163
  {%- endif -%}
@@ -179,15 +180,12 @@
179
  {{- '<turn|>\n' -}}
180
  {%- endif %}
181
 
 
182
  {%- for message in loop_messages -%}
183
  {%- set ns.prev_message_type = None -%}
184
  {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
185
  {{- '<|turn>' + role + '\n' }}
186
 
187
- {%- if role == 'model' and not message['tool_responses'] and (message['reasoning_content'] | default('')) -%}
188
- {{- '<|channel>thought\n' + (message['reasoning_content'] | trim) + '<channel|>' -}}
189
- {%- endif -%}
190
-
191
  {%- if message['tool_calls'] -%}
192
  {%- for tool_call in message['tool_calls'] -%}
193
  {%- set function = tool_call['function'] -%}
@@ -208,6 +206,7 @@
208
  {%- endif -%}
209
 
210
  {%- if message['tool_responses'] -%}
 
211
  {%- for tool_response in message['tool_responses'] -%}
212
  {{- '<|tool_response>' -}}
213
  {%- if tool_response['response'] is mapping -%}
@@ -252,7 +251,7 @@
252
  {%- endfor -%}
253
  {%- endif -%}
254
 
255
- {%- if not (message['tool_responses'] and not message['content'] and not (message['reasoning_content'] | default(''))) -%}
256
  {{- '<turn|>\n' -}}
257
  {%- endif -%}
258
  {%- endfor -%}
@@ -261,7 +260,7 @@
261
  {%- if ns.prev_message_type != 'tool_response' -%}
262
  {{- '<|turn>model\n' -}}
263
  {%- endif -%}
264
- {%- if thinking_enabled -%}
265
- {{- '<|channel>thought\n' -}}
266
  {%- endif -%}
267
  {%- endif -%}
 
151
  {%- endmacro -%}
152
 
153
  {%- set ns = namespace(prev_message_type=None) -%}
 
154
  {%- set loop_messages = messages -%}
155
  {{ bos_token }}
156
+ {#- Handle System/Tool Definitions Block -#}
157
+ {%- if (enable_thinking | default(true)) or tools or messages[0]['role'] in ['system', 'developer'] -%}
158
  {{- '<|turn>system\n' -}}
159
 
160
+ {#- Inject Thinking token at the very top of the FIRST system turn -#}
161
+ {%- if enable_thinking | default(true) -%}
162
  {{- '<|think|>' -}}
163
  {%- set ns.prev_message_type = 'think' -%}
164
  {%- endif -%}
 
180
  {{- '<turn|>\n' -}}
181
  {%- endif %}
182
 
183
+ {#- Loop through messages -#}
184
  {%- for message in loop_messages -%}
185
  {%- set ns.prev_message_type = None -%}
186
  {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
187
  {{- '<|turn>' + role + '\n' }}
188
 
 
 
 
 
189
  {%- if message['tool_calls'] -%}
190
  {%- for tool_call in message['tool_calls'] -%}
191
  {%- set function = tool_call['function'] -%}
 
206
  {%- endif -%}
207
 
208
  {%- if message['tool_responses'] -%}
209
+ {#- Tool Response handling -#}
210
  {%- for tool_response in message['tool_responses'] -%}
211
  {{- '<|tool_response>' -}}
212
  {%- if tool_response['response'] is mapping -%}
 
251
  {%- endfor -%}
252
  {%- endif -%}
253
 
254
+ {%- if not (message['tool_responses'] and not message['content']) -%}
255
  {{- '<turn|>\n' -}}
256
  {%- endif -%}
257
  {%- endfor -%}
 
260
  {%- if ns.prev_message_type != 'tool_response' -%}
261
  {{- '<|turn>model\n' -}}
262
  {%- endif -%}
263
+ {%- if not enable_thinking | default(true) -%}
264
+ {{- '<|channel>thought\n<channel|>' -}}
265
  {%- endif -%}
266
  {%- endif -%}