Preserve the correct ordering of content and tool calls when rendering OpenAI Chat Completions

#12
Files changed (5) hide show
  1. README.md +7 -24
  2. chat_template.jinja +91 -94
  3. config.json +1 -1
  4. model.safetensors +1 -1
  5. tokenizer_config.json +0 -46
README.md CHANGED
@@ -16,8 +16,7 @@ base_model:
16
  <a href="https://huggingface.co/collections/google/gemma-4" target="_blank">Hugging Face</a> |
17
  <a href="https://github.com/google-gemma" target="_blank">GitHub</a> |
18
  <a href="https://blog.google/innovation-and-ai/technology/developers-tools/introducing-gemma-4-12B/" target="_blank">Launch Blog</a> |
19
- <a href="https://ai.google.dev/gemma/docs/core" target="_blank">Documentation</a> |
20
- <a href="https://arxiv.org/abs/2607.02770" target="_blank">Technical Report</a>
21
  <br>
22
  <b>License</b>: <a href="https://ai.google.dev/gemma/docs/gemma_4_license" target="_blank">Apache 2.0</a> | <b>Authors</b>: <a href="https://deepmind.google/models/gemma/" target="_blank">Google DeepMind</a>
23
  </p>
@@ -175,7 +174,7 @@ outputs = model.generate(**inputs, max_new_tokens=1024)
175
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
176
 
177
  # Parse output
178
- processor.parse_response(response, prefix=inputs["input_ids"])
179
  ```
180
 
181
  To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output.
@@ -235,7 +234,7 @@ outputs = model.generate(**inputs, max_new_tokens=512)
235
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
236
 
237
  # Parse output
238
- processor.parse_response(response, prefix=inputs["input_ids"])
239
  ```
240
 
241
  </details>
@@ -293,7 +292,7 @@ outputs = model.generate(**inputs, max_new_tokens=512)
293
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
294
 
295
  # Parse output
296
- processor.parse_response(response, prefix=inputs["input_ids"])
297
  ```
298
 
299
  </details>
@@ -352,7 +351,7 @@ outputs = model.generate(**inputs, max_new_tokens=512)
352
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
353
 
354
  # Parse output
355
- processor.parse_response(response, prefix=inputs["input_ids"])
356
  ```
357
 
358
  </details>
@@ -386,7 +385,7 @@ Compared to Gemma 3, the models use standard `system`, `assistant`, and `user` r
386
 
387
  ### 3. Multi-Turn Conversations
388
 
389
- * **No Thinking Content in History**: In multi-turn conversations, the historical model output should only include the final response. Thoughts from previous model turns must *not be added* before the next user turn begins, with the exception of tool call turns where thinking content should be preserved.
390
 
391
  ### 4. Modality order
392
 
@@ -525,20 +524,4 @@ The development of vision-language models (VLMs) raises several ethical concerns
525
 
526
  ### **Benefits**
527
 
528
- At the time of release, this family of models provides high-performance open vision-language model implementations designed from the ground up for responsible AI development compared to similarly sized models.
529
-
530
- ## **Citation**
531
-
532
- If you find our work helpful, please consider citing it:
533
-
534
- ```bibtex
535
- @misc{gemmateam2026gemma4,
536
- title={Gemma 4 Technical Report},
537
- author={Gemma Team},
538
- year={2026},
539
- eprint={2607.02770},
540
- archivePrefix={arXiv},
541
- primaryClass={cs.CL},
542
- url={https://arxiv.org/abs/2607.02770},
543
- }
544
- ```
 
16
  <a href="https://huggingface.co/collections/google/gemma-4" target="_blank">Hugging Face</a> |
17
  <a href="https://github.com/google-gemma" target="_blank">GitHub</a> |
18
  <a href="https://blog.google/innovation-and-ai/technology/developers-tools/introducing-gemma-4-12B/" target="_blank">Launch Blog</a> |
19
+ <a href="https://ai.google.dev/gemma/docs/core" target="_blank">Documentation</a>
 
20
  <br>
21
  <b>License</b>: <a href="https://ai.google.dev/gemma/docs/gemma_4_license" target="_blank">Apache 2.0</a> | <b>Authors</b>: <a href="https://deepmind.google/models/gemma/" target="_blank">Google DeepMind</a>
22
  </p>
 
174
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
175
 
176
  # Parse output
177
+ processor.parse_response(response)
178
  ```
179
 
180
  To enable reasoning, set `enable_thinking=True` and the `parse_response` function will take care of parsing the thinking output.
 
234
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
235
 
236
  # Parse output
237
+ processor.parse_response(response)
238
  ```
239
 
240
  </details>
 
292
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
293
 
294
  # Parse output
295
+ processor.parse_response(response)
296
  ```
297
 
298
  </details>
 
351
  response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
352
 
353
  # Parse output
354
+ processor.parse_response(response)
355
  ```
356
 
357
  </details>
 
385
 
386
  ### 3. Multi-Turn Conversations
387
 
388
+ * **No Thinking Content in History**: In multi-turn conversations, the historical model output should only include the final response. Thoughts from previous model turns must *not be added* before the next user turn begins.
389
 
390
  ### 4. Modality order
391
 
 
524
 
525
  ### **Benefits**
526
 
527
+ At the time of release, this family of models provides high-performance open vision-language model implementations designed from the ground up for responsible AI development compared to similarly sized models.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
chat_template.jinja CHANGED
@@ -1,9 +1,3 @@
1
- {#
2
- Template: Google Gemma 4 Canonical Chat Template
3
- Author: Google Gemma Engineering Team
4
- Published: 2026-07-09
5
- Context: Fixed tool-calling loops, turn closures, and thinking content-ordering.
6
- #}
7
  {%- macro format_parameters(properties, required, filter_keys=false) -%}
8
  {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
9
  {%- set ns = namespace(found_first=false) -%}
@@ -122,9 +116,7 @@
122
  }
123
  {%- endmacro -%}
124
  {%- macro format_argument(argument, escape_keys=True) -%}
125
- {%- if argument is none -%}
126
- {{- 'null' -}}
127
- {%- elif argument is string -%}
128
  {{- '<|"|>' + argument + '<|"|>' -}}
129
  {%- elif argument is boolean -%}
130
  {{- 'true' if argument else 'false' -}}
@@ -180,21 +172,27 @@
180
  {{- '<tool_response|>' -}}
181
  {%- endmacro -%}
182
 
183
- {#- ===== SETUP ===== -#}
184
- {%- set ns = namespace(prev_message_type=None, prev_non_tool_role=None) -%}
 
 
 
 
 
 
 
 
 
185
  {%- set loop_messages = messages -%}
186
- {%- set enable_thinking = enable_thinking | default(false) -%}
187
- {%- set preserve_thinking = preserve_thinking | default(false) -%}
188
  {{- bos_token -}}
189
  {#- Handle System/Tool Definitions Block -#}
190
- {%- if enable_thinking or tools or (messages and messages[0]['role'] in ['system', 'developer']) -%}
191
- {{- '<|turn>system\n' -}}
192
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
193
- {%- if enable_thinking -%}
194
  {{- '<|think|>\n' -}}
195
- {%- set ns.prev_message_type = 'think' -%}
196
  {%- endif -%}
197
- {%- if messages and messages[0]['role'] in ['system', 'developer'] -%}
198
  {%- if messages[0]['content'] is string -%}
199
  {{- messages[0]['content'] | trim -}}
200
  {%- elif messages[0]['content'] is sequence -%}
@@ -210,9 +208,8 @@
210
  {{- format_function_declaration(tool) | trim -}}
211
  {{- '<tool|>' -}}
212
  {%- endfor %}
213
- {%- set ns.prev_message_type = 'tool' -%}
214
  {%- endif -%}
215
- {{- '<turn|>\n' -}}
216
  {%- endif %}
217
 
218
  {#- Pre-scan: find last user message index for reasoning guard -#}
@@ -226,24 +223,26 @@
226
  {#- Loop through messages -#}
227
  {%- for message in loop_messages -%}
228
  {%- if message['role'] != 'tool' -%}
229
- {%- set ns.prev_message_type = None -%}
230
  {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
231
- {#- Detect continuation using tracked state — O(1) instead of O(n) backward scan -#}
232
- {%- set continue_same_model_turn = (role == 'model' and ns.prev_non_tool_role == 'assistant') -%}
233
- {%- if not continue_same_model_turn -%}
234
- {{- '<|turn>' + role + '\n' }}
235
-
 
 
236
  {%- endif -%}
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 -%}
244
 
245
- {%- if message.get('tool_calls') -%}
246
- {%- for tool_call in message.get('tool_calls') -%}
 
247
  {%- set function = tool_call['function'] -%}
248
  {{- '<|tool_call>call:' + function['name'] + '{' -}}
249
  {%- if function['arguments'] is mapping -%}
@@ -253,28 +252,25 @@
253
  {%- set ns_args.found_first = true -%}
254
  {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
255
  {%- endfor -%}
256
- {%- elif function['arguments'] is none -%}
257
- {%- else -%}
258
- {{- raise_exception(
259
- "chat_template: tool_calls[].function.arguments must be a "
260
- "JSON object (mapping), not a string. Deserialize arguments "
261
- "before passing to the template."
262
- ) -}}
263
  {%- endif -%}
264
  {{- '}<tool_call|>' -}}
265
  {%- endfor -%}
266
- {%- set ns.prev_message_type = 'tool_call' -%}
267
  {%- endif -%}
 
268
 
269
- {%- set ns_tr_out = namespace(flag=false) -%}
270
  {%- if message.get('tool_responses') -%}
271
  {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
272
- {%- for tool_response in message.get('tool_responses') -%}
273
  {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}
274
- {%- set ns_tr_out.flag = true -%}
275
- {%- set ns.prev_message_type = 'tool_response' -%}
276
  {%- endfor -%}
277
- {%- elif message.get('tool_calls') -%}
 
 
 
 
278
  {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}
279
  {%- set ns_tool_scan = namespace(stopped=false) -%}
280
  {%- for k in range(loop.index0 + 1, loop_messages | length) -%}
@@ -284,8 +280,8 @@
284
  {%- else -%}
285
  {%- set follow = loop_messages[k] -%}
286
  {#- Resolve tool_call_id to function name -#}
287
- {%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}
288
- {%- for tc in message.get('tool_calls') -%}
289
  {%- if tc.get('id') == follow.get('tool_call_id') -%}
290
  {%- set ns_tname.name = tc['function']['name'] -%}
291
  {%- endif -%}
@@ -303,9 +299,9 @@
303
  {%- endfor -%}
304
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
305
  {%- for part in tool_body -%}
306
- {%- if part.get('type') in ['image', 'image_url'] -%}
307
  {{- '<|image|>' -}}
308
- {%- elif part.get('type') in ['audio', 'input_audio'] -%}
309
  {{- '<|audio|>' -}}
310
  {%- elif part.get('type') == 'video' -%}
311
  {{- '<|video|>' -}}
@@ -314,77 +310,78 @@
314
  {%- else -%}
315
  {{- format_tool_response_block(ns_tname.name, tool_body) -}}
316
  {%- endif -%}
317
- {%- set ns_tr_out.flag = true -%}
318
- {%- set ns.prev_message_type = 'tool_response' -%}
319
  {%- endif -%}
320
  {%- endfor -%}
321
  {%- endif -%}
 
322
 
323
- {%- set captured_content -%}
324
- {%- if message.get('content') is string -%}
325
  {%- if role == 'model' -%}
326
  {{- strip_thinking(message['content']) -}}
327
  {%- else -%}
328
  {{- message['content'] | trim -}}
329
  {%- endif -%}
330
- {%- elif message.get('content') is sequence -%}
331
  {%- for item in message['content'] -%}
332
- {%- if item.get('type') == 'text' -%}
333
  {%- if role == 'model' -%}
334
  {{- strip_thinking(item['text']) -}}
335
  {%- else -%}
336
  {{- item['text'] | trim -}}
337
  {%- endif -%}
338
- {%- elif item.get('type') in ['image', 'image_url'] -%}
339
  {{- '<|image|>' -}}
340
- {%- elif item.get('type') in ['audio', 'input_audio'] -%}
341
  {{- '<|audio|>' -}}
342
- {%- elif item.get('type') == 'video' -%}
343
  {{- '<|video|>' -}}
344
  {%- endif -%}
345
  {%- endfor -%}
346
  {%- endif -%}
347
- {%- endset -%}
348
 
 
 
349
  {{- captured_content -}}
350
- {%- set has_content = captured_content | trim | length > 0 -%}
351
-
352
- {#- Forward-scan: find next non-tool message role for continuation detection -#}
353
- {%- set next_nt = namespace(role=None, found=false) -%}
354
- {%- for j in range(loop.index0 + 1, loop_messages | length) -%}
355
- {%- if not next_nt.found -%}
356
- {%- if loop_messages[j]['role'] != 'tool' -%}
357
- {%- set next_nt.role = loop_messages[j]['role'] -%}
358
- {%- set next_nt.found = true -%}
359
- {%- endif -%}
360
  {%- endif -%}
361
- {%- endfor -%}
362
-
363
- {%- set continues_into_next = (
364
- role == 'model'
365
- and next_nt.role == 'assistant'
366
- and (not message.get('tool_calls') or ns_tr_out.flag)
367
- ) -%}
368
-
369
- {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
370
- {{- '<|tool_response>' -}}
371
- {%- elif continues_into_next -%}
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 -%}
382
- {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
383
- {{- '<|turn>model\n' -}}
384
- {%- if not enable_thinking -%}
385
- {{- '<|channel>thought\n<channel|>' -}}
386
  {%- endif -%}
387
- {%- elif ns.prev_message_type == 'tool_response' and enable_thinking -%}
388
- {{- '<|channel>thought\n' -}}
 
 
389
  {%- endif -%}
390
- {%- endif -%}
 
 
 
 
 
 
 
1
  {%- macro format_parameters(properties, required, filter_keys=false) -%}
2
  {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
3
  {%- set ns = namespace(found_first=false) -%}
 
116
  }
117
  {%- endmacro -%}
118
  {%- macro format_argument(argument, escape_keys=True) -%}
119
+ {%- if argument is string -%}
 
 
120
  {{- '<|"|>' + argument + '<|"|>' -}}
121
  {%- elif argument is boolean -%}
122
  {{- 'true' if argument else 'false' -}}
 
172
  {{- '<tool_response|>' -}}
173
  {%- endmacro -%}
174
 
175
+ {%- macro open_turn(role, ns) -%}
176
+ {%- set ns.open_turn_role = role -%}
177
+ {{- '<|turn>' + role + '\n' -}}
178
+ {%- endmacro -%}
179
+
180
+ {%- macro end_turn(ns) -%}
181
+ {%- set ns.open_turn_role = none -%}
182
+ {{- '<turn|>\n' -}}
183
+ {%- endmacro -%}
184
+
185
+ {%- set ns = namespace(open_turn_role=none) -%}
186
  {%- set loop_messages = messages -%}
 
 
187
  {{- bos_token -}}
188
  {#- Handle System/Tool Definitions Block -#}
189
+ {%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
190
+ {{- open_turn('system', ns) -}}
191
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
192
+ {%- if enable_thinking is defined and enable_thinking -%}
193
  {{- '<|think|>\n' -}}
 
194
  {%- endif -%}
195
+ {%- if messages[0]['role'] in ['system', 'developer'] -%}
196
  {%- if messages[0]['content'] is string -%}
197
  {{- messages[0]['content'] | trim -}}
198
  {%- elif messages[0]['content'] is sequence -%}
 
208
  {{- format_function_declaration(tool) | trim -}}
209
  {{- '<tool|>' -}}
210
  {%- endfor %}
 
211
  {%- endif -%}
212
+ {{- end_turn(ns) -}}
213
  {%- endif %}
214
 
215
  {#- Pre-scan: find last user message index for reasoning guard -#}
 
223
  {#- Loop through messages -#}
224
  {%- for message in loop_messages -%}
225
  {%- if message['role'] != 'tool' -%}
 
226
  {%- set role = 'model' if message['role'] == 'assistant' else message['role'] -%}
227
+ {%- if ns.open_turn_role -%}
228
+ {%- if ns.open_turn_role != role -%}
229
+ {{- end_turn(ns) -}}
230
+ {{- open_turn(role, ns) -}}
231
+ {%- endif -%}
232
+ {%- else -%}
233
+ {{- open_turn(role, ns) -}}
234
  {%- endif -%}
235
 
236
+ {%- set reasoning_block -%}
237
+ {%- set thinking_text = message['reasoning'] | default(message['reasoning_content']) | default(none) -%}
238
+ {%- if thinking_text is not none and loop.index0 > ns_turn.last_user_idx -%}
239
+ {{- '<|channel>thought\n' + thinking_text + '<channel|>' -}}
240
+ {%- endif -%}
241
+ {%- endset -%}
242
 
243
+ {%- set tool_calls_block -%}
244
+ {%- if message['tool_calls'] -%}
245
+ {%- for tool_call in message['tool_calls'] -%}
246
  {%- set function = tool_call['function'] -%}
247
  {{- '<|tool_call>call:' + function['name'] + '{' -}}
248
  {%- if function['arguments'] is mapping -%}
 
252
  {%- set ns_args.found_first = true -%}
253
  {{- key -}}:{{- format_argument(value, escape_keys=False) -}}
254
  {%- endfor -%}
255
+ {%- elif function['arguments'] is string -%}
256
+ {{- function['arguments'] -}}
 
 
 
 
 
257
  {%- endif -%}
258
  {{- '}<tool_call|>' -}}
259
  {%- endfor -%}
 
260
  {%- endif -%}
261
+ {%- endset -%}
262
 
263
+ {%- set legacy_tool_responses_block -%}
264
  {%- if message.get('tool_responses') -%}
265
  {#- Legacy: tool_responses embedded on the assistant message (Google/Gemma native) -#}
266
+ {%- for tool_response in message['tool_responses'] -%}
267
  {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}
 
 
268
  {%- endfor -%}
269
+ {%- endif -%}
270
+ {%- endset -%}
271
+
272
+ {%- set openai_tool_responses_block -%}
273
+ {%- if message.get('tool_calls') and not message.get('tool_responses') -%}
274
  {#- OpenAI Chat Completions: forward-scan consecutive role:tool messages -#}
275
  {%- set ns_tool_scan = namespace(stopped=false) -%}
276
  {%- for k in range(loop.index0 + 1, loop_messages | length) -%}
 
280
  {%- else -%}
281
  {%- set follow = loop_messages[k] -%}
282
  {#- Resolve tool_call_id to function name -#}
283
+ {%- set ns_tname = namespace(name=follow.get('name') | default('unknown', true)) -%}
284
+ {%- for tc in message['tool_calls'] -%}
285
  {%- if tc.get('id') == follow.get('tool_call_id') -%}
286
  {%- set ns_tname.name = tc['function']['name'] -%}
287
  {%- endif -%}
 
299
  {%- endfor -%}
300
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
301
  {%- for part in tool_body -%}
302
+ {%- if part.get('type') == 'image' -%}
303
  {{- '<|image|>' -}}
304
+ {%- elif part.get('type') == 'audio' -%}
305
  {{- '<|audio|>' -}}
306
  {%- elif part.get('type') == 'video' -%}
307
  {{- '<|video|>' -}}
 
310
  {%- else -%}
311
  {{- format_tool_response_block(ns_tname.name, tool_body) -}}
312
  {%- endif -%}
 
 
313
  {%- endif -%}
314
  {%- endfor -%}
315
  {%- endif -%}
316
+ {%- endset -%}
317
 
318
+ {%- set captured_content -%}
319
+ {%- if message['content'] is string -%}
320
  {%- if role == 'model' -%}
321
  {{- strip_thinking(message['content']) -}}
322
  {%- else -%}
323
  {{- message['content'] | trim -}}
324
  {%- endif -%}
325
+ {%- elif message['content'] is sequence -%}
326
  {%- for item in message['content'] -%}
327
+ {%- if item['type'] == 'text' -%}
328
  {%- if role == 'model' -%}
329
  {{- strip_thinking(item['text']) -}}
330
  {%- else -%}
331
  {{- item['text'] | trim -}}
332
  {%- endif -%}
333
+ {%- elif item['type'] == 'image' -%}
334
  {{- '<|image|>' -}}
335
+ {%- elif item['type'] == 'audio' -%}
336
  {{- '<|audio|>' -}}
337
+ {%- elif item['type'] == 'video' -%}
338
  {{- '<|video|>' -}}
339
  {%- endif -%}
340
  {%- endfor -%}
341
  {%- endif -%}
342
+ {%- endset -%}
343
 
344
+ {%- if role != 'model' -%}
345
+ {#- Non-model turn -#}
346
  {{- captured_content -}}
347
+ {{- end_turn(ns) -}}
348
+ {%- elif message.get('tool_responses') -%}
349
+ {#- Model turn with legacy tool -#}
350
+ {{- reasoning_block -}}
351
+ {{- tool_calls_block -}}
352
+ {{- legacy_tool_responses_block -}}
353
+ {%- if captured_content -%}
354
+ {{- captured_content -}}
355
+ {{- end_turn(ns) -}}
 
356
  {%- endif -%}
357
+ {%- elif message.get('tool_calls') -%}
358
+ {#- Model turn with OpenAI tool -#}
359
+ {{- reasoning_block -}}
360
+ {{- captured_content -}}
361
+ {{- tool_calls_block -}}
362
+ {%- if openai_tool_responses_block -%}
363
+ {{- openai_tool_responses_block -}}
364
+ {%- elif loop.last -%}
365
+ {{- '<|tool_response>' -}}
366
+ {%- endif -%}
367
+ {%- else -%}
368
+ {#- Model turn without tool -#}
369
+ {{- reasoning_block -}}
370
+ {{- captured_content -}}
371
+ {{- end_turn(ns) -}}
372
  {%- endif -%}
 
 
 
373
  {%- endif -%}
374
  {%- endfor -%}
375
 
376
  {%- if add_generation_prompt -%}
377
+ {#- Close previous non-model turn and start a new model turn -#}
378
+ {%- if ns.open_turn_role != 'model' -%}
379
+ {%- if ns.open_turn_role -%}
380
+ {{- end_turn(ns) -}}
381
  {%- endif -%}
382
+ {{- open_turn('model', ns) -}}
383
+ {%- endif -%}
384
+ {%- if not enable_thinking | default(false) -%}
385
+ {{- '<|channel>thought\n<channel|>' -}}
386
  {%- endif -%}
387
+ {%- endif -%}
config.json CHANGED
@@ -106,7 +106,7 @@
106
  "sliding_attention",
107
  "full_attention"
108
  ],
109
- "max_position_embeddings": 262144,
110
  "model_type": "gemma4_unified_text",
111
  "moe_intermediate_size": null,
112
  "num_attention_heads": 16,
 
106
  "sliding_attention",
107
  "full_attention"
108
  ],
109
+ "max_position_embeddings": 131072,
110
  "model_type": "gemma4_unified_text",
111
  "moe_intermediate_size": null,
112
  "num_attention_heads": 16,
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5a84cb313260ac447237b890387116dfa8682e49a6b44bc585ae8353abbff18d
3
  size 23919549408
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:366b79fc7e2ea81106d45e2b3ca10e144925f93dd9d456396692825ddb7bb788
3
  size 23919549408
tokenizer_config.json CHANGED
@@ -63,52 +63,6 @@
63
  "type": "object",
64
  "x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
65
  },
66
- "response_template": {
67
- "defaults": {
68
- "role": "assistant"
69
- },
70
- "fields": {
71
- "content": {
72
- "close": [
73
- "<turn|>",
74
- "<|tool_response>",
75
- "<eos>"
76
- ],
77
- "content": "text"
78
- },
79
- "thinking": {
80
- "close": "<channel|>",
81
- "content": "text",
82
- "open": "<|channel>thought\n"
83
- },
84
- "tool_calls": {
85
- "close": "<tool_call|>",
86
- "content": "json",
87
- "content_args": {
88
- "string_delims": [
89
- [
90
- "<|\"|>",
91
- "<|\"|>"
92
- ]
93
- ],
94
- "unquoted_keys": true
95
- },
96
- "open_pattern": "<\\|tool_call>call:(?P<name>\\w+)",
97
- "repeats": true,
98
- "transform": {
99
- "function": {
100
- "arguments": "{content}",
101
- "name": "{name}"
102
- },
103
- "type": "function"
104
- }
105
- }
106
- },
107
- "start_anchor": [
108
- "<|turn>model\n",
109
- "<tool_response|>"
110
- ]
111
- },
112
  "soc_token": "<|channel>",
113
  "sot_token": "<|turn>",
114
  "stc_token": "<|tool_call>",
 
63
  "type": "object",
64
  "x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
65
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  "soc_token": "<|channel>",
67
  "sot_token": "<|turn>",
68
  "stc_token": "<|tool_call>",