zecanard commited on
Commit
0b51062
·
verified ·
1 Parent(s): 9c94871

Adding Tools support.

Browse files
Files changed (1) hide show
  1. chat_template.jinja +17 -10
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'] -%}
@@ -202,18 +202,21 @@
202
  {#- Handle System/Tool Definitions Block -#}
203
  {%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
204
  {{- '<|turn>system\n' -}}
205
-
206
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
207
  {%- if enable_thinking is defined and enable_thinking -%}
208
  {{- '<|think|>\n' -}}
209
  {%- set ns.prev_message_type = 'think' -%}
210
  {%- endif -%}
211
-
212
  {%- if messages[0]['role'] in ['system', 'developer'] -%}
213
- {{- messages[0]['content'] | trim -}}
 
 
 
 
 
 
214
  {%- set loop_messages = messages[1:] -%}
215
  {%- endif -%}
216
-
217
  {%- if tools -%}
218
  {%- for tool in tools %}
219
  {{- '<|tool>' -}}
@@ -222,7 +225,6 @@
222
  {%- endfor %}
223
  {%- set ns.prev_message_type = 'tool' -%}
224
  {%- endif -%}
225
-
226
  {{- '<turn|>\n' -}}
227
  {%- endif %}
228
 
@@ -326,6 +328,7 @@
326
  {%- endfor -%}
327
  {%- endif -%}
328
 
 
329
  {%- if message['content'] is string -%}
330
  {%- if role == 'model' -%}
331
  {{- strip_thinking(message['content']) -}}
@@ -352,10 +355,14 @@
352
  {%- endif -%}
353
  {%- endfor -%}
354
  {%- endif -%}
 
 
 
 
355
 
356
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
357
  {{- '<|tool_response>' -}}
358
- {%- elif not (ns_tr_out.flag and not message.get('content')) -%}
359
  {{- '<turn|>\n' -}}
360
  {%- endif -%}
361
  {%- endif -%}
@@ -368,4 +375,4 @@
368
  {{- '<|channel>thought\n<channel|>' -}}
369
  {%- endif -%}
370
  {%- endif -%}
371
- {%- 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'] -%}
 
202
  {#- Handle System/Tool Definitions Block -#}
203
  {%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
204
  {{- '<|turn>system\n' -}}
 
205
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
206
  {%- if enable_thinking is defined and enable_thinking -%}
207
  {{- '<|think|>\n' -}}
208
  {%- set ns.prev_message_type = 'think' -%}
209
  {%- endif -%}
 
210
  {%- if messages[0]['role'] in ['system', 'developer'] -%}
211
+ {%- if messages[0]['content'] is string -%}
212
+ {{- messages[0]['content'] | trim -}}
213
+ {%- elif messages[0]['content'] is sequence -%}
214
+ {%- for item in messages[0]['content'] -%}
215
+ {{- item['text'] | trim + ' '-}}
216
+ {%- endfor -%}
217
+ {%- endif -%}
218
  {%- set loop_messages = messages[1:] -%}
219
  {%- endif -%}
 
220
  {%- if tools -%}
221
  {%- for tool in tools %}
222
  {{- '<|tool>' -}}
 
225
  {%- endfor %}
226
  {%- set ns.prev_message_type = 'tool' -%}
227
  {%- endif -%}
 
228
  {{- '<turn|>\n' -}}
229
  {%- endif %}
230
 
 
328
  {%- endfor -%}
329
  {%- endif -%}
330
 
331
+ {%- set captured_content -%}
332
  {%- if message['content'] is string -%}
333
  {%- if role == 'model' -%}
334
  {{- strip_thinking(message['content']) -}}
 
355
  {%- endif -%}
356
  {%- endfor -%}
357
  {%- endif -%}
358
+ {%- endset -%}
359
+
360
+ {{- captured_content -}}
361
+ {%- set has_content = captured_content | trim | length > 0 -%}
362
 
363
  {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
364
  {{- '<|tool_response>' -}}
365
+ {%- elif not (ns_tr_out.flag and not has_content) -%}
366
  {{- '<turn|>\n' -}}
367
  {%- endif -%}
368
  {%- endif -%}
 
375
  {{- '<|channel>thought\n<channel|>' -}}
376
  {%- endif -%}
377
  {%- endif -%}
378
+ {%- endif -%}