Rocketknight1 HF Staff commited on
Commit
f0dcb0c
·
verified ·
1 Parent(s): 0b988d7

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +20 -1
chat_template.jinja CHANGED
@@ -132,7 +132,7 @@
132
  {%- endif -%}
133
  {%- endif %}
134
  {{- '<|im_start|>assistant\n' }}
135
- {%- generation %}
136
  {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
137
  {# Assistant message has tool calls. #}
138
  {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
@@ -188,6 +188,25 @@
188
  {%- endif %}
189
  {%- endif %}
190
  {%- endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  {%- endgeneration %}
192
  {{- '\n' }}
193
  {%- elif message.role == "user" or message.role == "system" %}
 
132
  {%- endif -%}
133
  {%- endif %}
134
  {{- '<|im_start|>assistant\n' }}
135
+ {%- set turn %}
136
  {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
137
  {# Assistant message has tool calls. #}
138
  {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
 
188
  {%- endif %}
189
  {%- endif %}
190
  {%- endif %}
191
+ {%- endset %}
192
+ {#- What the generation prompt pre-fills stays out of the generation block: the model never generates it #}
193
+ {%- set prefill = '<think>\n' if enable_thinking else '<think></think>' %}
194
+ {%- if turn.startswith(prefill) %}
195
+ {%- set lead = prefill %}
196
+ {%- elif not turn.startswith('<think>') %}
197
+ {%- set lead = '' %}
198
+ {%- elif enable_thinking or '</think>' not in turn %}
199
+ {%- set lead = '<think>' %}
200
+ {%- else %}
201
+ {#- Reasoning with thinking off: the prompt pre-fills an empty block, so the whole block stays out #}
202
+ {%- set lead = turn.split('</think>')[0] ~ '</think>' %}
203
+ {%- if turn[lead | length:].startswith('\n') %}
204
+ {%- set lead = lead ~ '\n' %}
205
+ {%- endif %}
206
+ {%- endif %}
207
+ {{- lead }}
208
+ {%- generation %}
209
+ {{- turn[lead | length:] }}
210
  {%- endgeneration %}
211
  {{- '\n' }}
212
  {%- elif message.role == "user" or message.role == "system" %}