zecanard commited on
Commit
a0261c3
·
verified ·
1 Parent(s): 444067f

Syncing latest template update from Google.

Browse files
Files changed (1) hide show
  1. chat_template.jinja +25 -9
chat_template.jinja CHANGED
@@ -8,12 +8,12 @@
8
  {%- endif %}
9
  {{- 'The current date is: ' + currentDate + ".\n\n" }}
10
  {#- Template customizations by @zecanard. #}
11
- {%- macro format_parameters(properties, required) -%}
12
  {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
13
  {%- set ns = namespace(found_first=false) -%}
14
  {%- for key, value in properties | dictsort -%}
15
  {%- set add_comma = false -%}
16
- {%- if key not in standard_keys -%}
17
  {%- if ns.found_first %},{% endif -%}
18
  {%- set ns.found_first = true -%}
19
  {{ key }}:{
@@ -75,7 +75,7 @@
75
  {%- elif value is mapping -%}
76
  {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
77
  properties:{
78
- {{- format_parameters(value, value['required'] | default([])) -}}
79
  }
80
  {%- endif -%}
81
  {%- if value['required'] -%}
@@ -188,18 +188,21 @@
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
  {{- '<|turn>system\n' -}}
191
-
192
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
193
  {%- if enable_thinking is defined and enable_thinking -%}
194
  {{- '<|think|>\n' -}}
195
  {%- set ns.prev_message_type = 'think' -%}
196
  {%- endif -%}
197
-
198
  {%- if messages[0]['role'] in ['system', 'developer'] -%}
199
- {{- messages[0]['content'] | trim -}}
 
 
 
 
 
 
200
  {%- set loop_messages = messages[1:] -%}
201
  {%- endif -%}
202
-
203
  {%- if tools -%}
204
  {%- for tool in tools %}
205
  {{- '<|tool>' -}}
@@ -208,7 +211,6 @@
208
  {%- endfor %}
209
  {%- set ns.prev_message_type = 'tool' -%}
210
  {%- endif -%}
211
-
212
  {{- '<turn|>\n' -}}
213
  {%- endif %}
214
 
@@ -303,6 +305,15 @@
303
  {%- endif -%}
304
  {%- endfor -%}
305
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
 
 
 
 
 
 
 
 
 
306
  {%- else -%}
307
  {{- format_tool_response_block(ns_tname.name, tool_body) -}}
308
  {%- endif -%}
@@ -312,6 +323,7 @@
312
  {%- endfor -%}
313
  {%- endif -%}
314
 
 
315
  {%- if message['content'] is string -%}
316
  {%- if role == 'model' -%}
317
  {{- strip_thinking(message['content']) -}}
@@ -338,10 +350,14 @@
338
  {%- endif -%}
339
  {%- endfor -%}
340
  {%- endif -%}
 
 
 
 
341
 
342
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
343
  {{- '<|tool_response>' -}}
344
- {%- elif not (ns_tr_out.flag and not message.get('content')) -%}
345
  {{- '<turn|>\n' -}}
346
  {%- endif -%}
347
  {%- endif -%}
 
8
  {%- endif %}
9
  {{- 'The current date is: ' + currentDate + ".\n\n" }}
10
  {#- Template customizations by @zecanard. #}
11
+ {%- macro format_parameters(properties, required, filter_keys=false) -%}
12
  {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
13
  {%- set ns = namespace(found_first=false) -%}
14
  {%- for key, value in properties | dictsort -%}
15
  {%- set add_comma = false -%}
16
+ {%- if not filter_keys or key not in standard_keys -%}
17
  {%- if ns.found_first %},{% endif -%}
18
  {%- set ns.found_first = true -%}
19
  {{ key }}:{
 
75
  {%- elif value is mapping -%}
76
  {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
77
  properties:{
78
+ {{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}
79
  }
80
  {%- endif -%}
81
  {%- if value['required'] -%}
 
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
  {{- '<|turn>system\n' -}}
 
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
  {%- set ns.prev_message_type = 'think' -%}
195
  {%- endif -%}
 
196
  {%- if messages[0]['role'] in ['system', 'developer'] -%}
197
+ {%- if messages[0]['content'] is string -%}
198
+ {{- messages[0]['content'] | trim -}}
199
+ {%- elif messages[0]['content'] is sequence -%}
200
+ {%- for item in messages[0]['content'] -%}
201
+ {{- item['text'] | trim + ' '-}}
202
+ {%- endfor -%}
203
+ {%- endif -%}
204
  {%- set loop_messages = messages[1:] -%}
205
  {%- endif -%}
 
206
  {%- if tools -%}
207
  {%- for tool in tools %}
208
  {{- '<|tool>' -}}
 
211
  {%- endfor %}
212
  {%- set ns.prev_message_type = 'tool' -%}
213
  {%- endif -%}
 
214
  {{- '<turn|>\n' -}}
215
  {%- endif %}
216
 
 
305
  {%- endif -%}
306
  {%- endfor -%}
307
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
308
+ {%- for part in tool_body -%}
309
+ {%- if part.get('type') == 'image' -%}
310
+ {{- '<|image|>' -}}
311
+ {%- elif part.get('type') == 'audio' -%}
312
+ {{- '<|audio|>' -}}
313
+ {%- elif part.get('type') == 'video' -%}
314
+ {{- '<|video|>' -}}
315
+ {%- endif -%}
316
+ {%- endfor -%}
317
  {%- else -%}
318
  {{- format_tool_response_block(ns_tname.name, tool_body) -}}
319
  {%- endif -%}
 
323
  {%- endfor -%}
324
  {%- endif -%}
325
 
326
+ {%- set captured_content -%}
327
  {%- if message['content'] is string -%}
328
  {%- if role == 'model' -%}
329
  {{- strip_thinking(message['content']) -}}
 
350
  {%- endif -%}
351
  {%- endfor -%}
352
  {%- endif -%}
353
+ {%- endset -%}
354
+
355
+ {{- captured_content -}}
356
+ {%- set has_content = captured_content | trim | length > 0 -%}
357
 
358
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
359
  {{- '<|tool_response>' -}}
360
+ {%- elif not (ns_tr_out.flag and not has_content) -%}
361
  {{- '<turn|>\n' -}}
362
  {%- endif -%}
363
  {%- endif -%}