qgallouedec HF Staff commited on
Commit
ed38f06
·
verified ·
1 Parent(s): 53a01b9

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +39 -30
chat_template.jinja CHANGED
@@ -11,34 +11,15 @@
11
  description:<|"|>{{ value['description'] }}<|"|>
12
  {%- set add_comma = true -%}
13
  {%- endif -%}
14
- {%- if value['nullable'] %}
15
- {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
16
- nullable:true
17
- {%- endif -%}
18
  {%- if value['type'] | upper == 'STRING' -%}
19
  {%- if value['enum'] -%}
20
  {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
21
  enum:{{ format_argument(value['enum']) }}
22
  {%- endif -%}
23
- {%- elif value['type'] | upper == 'OBJECT' -%}
24
- ,properties:{
25
- {%- if value['properties'] is defined and value['properties'] is mapping -%}
26
- {{- format_parameters(value['properties'], value['required'] | default([])) -}}
27
- {%- elif value is mapping -%}
28
- {{- format_parameters(value, value['required'] | default([])) -}}
29
- {%- endif -%}
30
- }
31
- {%- if value['required'] -%}
32
- ,required:[
33
- {%- for item in value['required'] | default([]) -%}
34
- <|"|>{{- item -}}<|"|>
35
- {%- if not loop.last %},{% endif -%}
36
- {%- endfor -%}
37
- ]
38
- {%- endif -%}
39
  {%- elif value['type'] | upper == 'ARRAY' -%}
40
  {%- if value['items'] is mapping and value['items'] -%}
41
- ,items:{
 
42
  {%- set ns_items = namespace(found_first=false) -%}
43
  {%- for item_key, item_value in value['items'] | dictsort -%}
44
  {%- if item_value is not none -%}
@@ -71,6 +52,32 @@
71
  }
72
  {%- endif -%}
73
  {%- endif -%}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
75
  type:<|"|>{{ value['type'] | upper }}<|"|>}
76
  {%- endif -%}
@@ -167,14 +174,14 @@
167
 
168
  {%- set ns = namespace(prev_message_type=None) -%}
169
  {%- set loop_messages = messages -%}
170
- {{ bos_token }}
171
  {#- Handle System/Tool Definitions Block -#}
172
  {%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
173
  {{- '<|turn>system\n' -}}
174
 
175
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
176
  {%- if enable_thinking is defined and enable_thinking -%}
177
- {{- '<|think|>' -}}
178
  {%- set ns.prev_message_type = 'think' -%}
179
  {%- endif -%}
180
 
@@ -310,29 +317,31 @@
310
  {{- item['text'] | trim -}}
311
  {%- endif -%}
312
  {%- elif item['type'] == 'image' -%}
313
- {{- '\n\n<|image|>\n\n' -}}
314
  {%- set ns.prev_message_type = 'image' -%}
315
  {%- elif item['type'] == 'audio' -%}
316
  {{- '<|audio|>' -}}
317
  {%- set ns.prev_message_type = 'audio' -%}
318
  {%- elif item['type'] == 'video' -%}
319
- {{- '\n\n<|video|>\n\n' -}}
320
  {%- set ns.prev_message_type = 'video' -%}
321
  {%- endif -%}
322
  {%- endfor -%}
323
  {%- endif -%}
324
 
325
- {%- if not (ns_tr_out.flag and not message.get('content')) -%}
 
 
326
  {{- '<turn|>\n' -}}
327
  {%- endif -%}
328
  {%- endif -%}
329
  {%- endfor -%}
330
 
331
  {%- if add_generation_prompt -%}
332
- {%- if ns.prev_message_type != 'tool_response' -%}
333
  {{- '<|turn>model\n' -}}
334
- {%- endif -%}
335
- {%- if not enable_thinking | default(false) -%}
336
- {{- '<|channel>thought\n<channel|>' -}}
337
  {%- endif -%}
338
  {%- endif -%}
 
11
  description:<|"|>{{ value['description'] }}<|"|>
12
  {%- set add_comma = true -%}
13
  {%- endif -%}
 
 
 
 
14
  {%- if value['type'] | upper == 'STRING' -%}
15
  {%- if value['enum'] -%}
16
  {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
17
  enum:{{ format_argument(value['enum']) }}
18
  {%- endif -%}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  {%- elif value['type'] | upper == 'ARRAY' -%}
20
  {%- if value['items'] is mapping and value['items'] -%}
21
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
22
+ items:{
23
  {%- set ns_items = namespace(found_first=false) -%}
24
  {%- for item_key, item_value in value['items'] | dictsort -%}
25
  {%- if item_value is not none -%}
 
52
  }
53
  {%- endif -%}
54
  {%- endif -%}
55
+ {%- if value['nullable'] %}
56
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
57
+ nullable:true
58
+ {%- endif -%}
59
+ {%- if value['type'] | upper == 'OBJECT' -%}
60
+ {%- if value['properties'] is defined and value['properties'] is mapping -%}
61
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
62
+ properties:{
63
+ {{- format_parameters(value['properties'], value['required'] | default([])) -}}
64
+ }
65
+ {%- elif value is mapping -%}
66
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
67
+ properties:{
68
+ {{- format_parameters(value, value['required'] | default([])) -}}
69
+ }
70
+ {%- endif -%}
71
+ {%- if value['required'] -%}
72
+ {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
73
+ required:[
74
+ {%- for item in value['required'] | default([]) -%}
75
+ <|"|>{{- item -}}<|"|>
76
+ {%- if not loop.last %},{% endif -%}
77
+ {%- endfor -%}
78
+ ]
79
+ {%- endif -%}
80
+ {%- endif -%}
81
  {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}
82
  type:<|"|>{{ value['type'] | upper }}<|"|>}
83
  {%- endif -%}
 
174
 
175
  {%- set ns = namespace(prev_message_type=None) -%}
176
  {%- set loop_messages = messages -%}
177
+ {{- bos_token -}}
178
  {#- Handle System/Tool Definitions Block -#}
179
  {%- if (enable_thinking is defined and enable_thinking) or tools or messages[0]['role'] in ['system', 'developer'] -%}
180
  {{- '<|turn>system\n' -}}
181
 
182
  {#- Inject Thinking token at the very top of the FIRST system turn -#}
183
  {%- if enable_thinking is defined and enable_thinking -%}
184
+ {{- '<|think|>\n' -}}
185
  {%- set ns.prev_message_type = 'think' -%}
186
  {%- endif -%}
187
 
 
317
  {{- item['text'] | trim -}}
318
  {%- endif -%}
319
  {%- elif item['type'] == 'image' -%}
320
+ {{- '<|image|>' -}}
321
  {%- set ns.prev_message_type = 'image' -%}
322
  {%- elif item['type'] == 'audio' -%}
323
  {{- '<|audio|>' -}}
324
  {%- set ns.prev_message_type = 'audio' -%}
325
  {%- elif item['type'] == 'video' -%}
326
+ {{- '<|video|>' -}}
327
  {%- set ns.prev_message_type = 'video' -%}
328
  {%- endif -%}
329
  {%- endfor -%}
330
  {%- endif -%}
331
 
332
+ {%- if ns.prev_message_type == 'tool_call' and not ns_tr_out.flag -%}
333
+ {{- '<|tool_response>' -}}
334
+ {%- elif not (ns_tr_out.flag and not message.get('content')) -%}
335
  {{- '<turn|>\n' -}}
336
  {%- endif -%}
337
  {%- endif -%}
338
  {%- endfor -%}
339
 
340
  {%- if add_generation_prompt -%}
341
+ {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
342
  {{- '<|turn>model\n' -}}
343
+ {%- if not enable_thinking | default(false) -%}
344
+ {{- '<|channel>thought\n<channel|>' -}}
345
+ {%- endif -%}
346
  {%- endif -%}
347
  {%- endif -%}