fix: chat_template, close model turn across tool results + keep tool-call reasoning

#25
Files changed (1) hide show
  1. chat_template.jinja +2 -2
chat_template.jinja CHANGED
@@ -237,7 +237,7 @@
237
 
238
  {#- Render reasoning/reasoning_content as thinking channel -#}
239
  {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
240
- {%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or (preserve_thinking and message.get('tool_calls')) -%}
241
  {%- if thinking_text and thinking_gate -%}
242
  {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
243
  {%- endif -%}
@@ -372,10 +372,10 @@
372
  {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
373
  {{- '<turn|>\n' -}}
374
  {%- endif -%}
375
- {%- endif -%}
376
 
377
  {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
378
  {%- set ns.prev_non_tool_role = message['role'] -%}
 
379
  {%- endfor -%}
380
 
381
  {%- if add_generation_prompt -%}
 
237
 
238
  {#- Render reasoning/reasoning_content as thinking channel -#}
239
  {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
240
+ {%- set thinking_gate = (loop.index0 > ns_turn.last_user_idx) or message.get('tool_calls') or preserve_thinking -%}
241
  {%- if thinking_text and thinking_gate -%}
242
  {{- '<|channel>thought\n' + thinking_text + '\n<channel|>' -}}
243
  {%- endif -%}
 
372
  {%- elif not (ns_tr_out.flag and not has_content and not next_nt.found) -%}
373
  {{- '<turn|>\n' -}}
374
  {%- endif -%}
 
375
 
376
  {#- Track previous non-tool role for next iteration (avoids O(n) backward scan) -#}
377
  {%- set ns.prev_non_tool_role = message['role'] -%}
378
+ {%- endif -%}
379
  {%- endfor -%}
380
 
381
  {%- if add_generation_prompt -%}