Fix missing thinking channel in Gemma 4 chat template when using continue_final_message

#26
Files changed (1) hide show
  1. chat_template.jinja +5 -0
chat_template.jinja CHANGED
@@ -232,6 +232,11 @@
232
  {{- '<|turn>' + role + '\n' }}
233
  {%- endif -%}
234
 
 
 
 
 
 
235
  {#- Render reasoning/reasoning_content as thinking channel -#}
236
  {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
237
  {%- if thinking_text and loop.index0 > ns_turn.last_user_idx and message.get('tool_calls') -%}
 
232
  {{- '<|turn>' + role + '\n' }}
233
  {%- endif -%}
234
 
235
+ {#- Inject empty thinking channel for the last model turn when thinking is disabled -#}
236
+ {%- if role == 'model' and not enable_thinking | default(false) and loop.last -%}
237
+ {{- '<|channel>thought\n<channel|>' -}}
238
+ {%- endif -%}
239
+
240
  {#- Render reasoning/reasoning_content as thinking channel -#}
241
  {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}
242
  {%- if thinking_text and loop.index0 > ns_turn.last_user_idx and message.get('tool_calls') -%}