albertvillanova HF Staff commited on
Commit
3184655
·
1 Parent(s): db367c5

Sync the chat template with the released checkpoint (#1)

Browse files

- Sync the chat template with the released checkpoint (8f96adf936b7622c34a54012241869c784684f2e)

Files changed (1) hide show
  1. chat_template.jinja +32 -32
chat_template.jinja CHANGED
@@ -8,7 +8,7 @@
8
  {#- Handle system prompt if it exists. #}
9
  {%- set loop_messages = messages %}
10
  {%- if messages[0]['role'] != 'system' and default_system_message != '' %}
11
- {{- '[SYSTEM_PROMPT]' + default_system_message + '[/SYSTEM_PROMPT]' }}
12
  {%- endif %}
13
 
14
 
@@ -17,38 +17,38 @@
17
  {%- set has_tools = false %}
18
  {%- if tools is defined and tools is not none and tools|length > 0 %}
19
  {%- set has_tools = true %}
20
- {%- set available_tools = '[AVAILABLE_TOOLS]' + (tools| tojson) + '[/AVAILABLE_TOOLS]' %}
21
  {%- endif %}
22
  {%- set json_schema = none %}
23
  {%- if response_format is defined and response_format is not none %}
24
- {%- if response_format['type'] == 'json_schema' %}
25
- {%- if 'json_schema' in response_format and response_format['json_schema'] is not none %}
26
- {%- if 'schema' in response_format['json_schema'] %}
27
- {%- if response_format['json_schema']['schema'] is not none %}
28
- {%- set json_schema = response_format['json_schema']['schema'] %}
29
- {%- else %}
30
- {{- raise_exception('Response format `json_schema` must define the schema') }}
31
- {%- endif %}
32
- {%- else %}
33
- {{- raise_exception('Response format `json_schema` must define the schema') }}
34
- {%- endif %}
35
- {%- else %}
36
  {{- raise_exception('Response format `json_schema` must define the schema') }}
 
 
37
  {%- endif %}
38
- {%- elif response_format['type'] == 'json_object' %}
39
  {%- set json_schema = {'anyOf': [{'type': 'object'}, {'type': 'array'}]} %}
40
  {%- endif %}
41
  {%- endif %}
42
  {%- if reasoning_effort is not defined or reasoning_effort is none %}
43
- {%- set reasoning_effort = 'none' %}
44
  {%- endif %}
45
- {%- if reasoning_effort not in ['none', 'high'] %}
46
- {{- raise_exception('reasoning_effort must be either "none" or "high"') }}
47
  {%- endif %}
 
48
  {%- if json_schema is not none %}
49
- {%- set model_settings = '[MODEL_SETTINGS]{"json_schema": ' + (json_schema|tojson) + ', "reasoning_effort": "' + reasoning_effort + '"}[/MODEL_SETTINGS]' %}
50
- {%- else %}
51
- {%- set model_settings = '[MODEL_SETTINGS]{"reasoning_effort": "' + reasoning_effort + '"}[/MODEL_SETTINGS]' %}
 
 
 
52
  {%- endif %}
53
 
54
  {#- Macros #}
@@ -60,16 +60,16 @@
60
  {%- if block['type'] == 'text' -%}
61
  {{- block['text'] -}}
62
  {%- elif support_thinking and block['type'] == 'thinking' -%}
63
- {{- '[THINK]' + block['thinking'] -}}
64
  {%- if block.get('closed', true) -%}{{- '[/THINK]' -}}{%- endif -%}
65
  {%- elif support_images and block['type'] in ['image', 'image_url'] -%}
66
  {{- '[IMG]' -}}
67
  {%- else -%}
68
- {{- raise_exception('Only ' + supported_types_desc + ' chunks are supported in ' + context_name + '.') -}}
69
  {%- endif -%}
70
  {%- endfor -%}
71
  {%- else -%}
72
- {{- raise_exception(context_name + ' must have non-empty content.') -}}
73
  {%- endif -%}
74
  {%- endmacro -%}
75
 
@@ -162,7 +162,7 @@
162
  {#- Validates message ordering. #}
163
  {%- set ns = namespace(available_tools_and_settings_emitted=false) %}
164
  {%- if loop_messages | length > 0 and loop_messages[0]['role'] not in ['user', 'system'] %}
165
- {{- raise_exception('Conversation must start with a user or system message, got ' + loop_messages[0]['role'] + '.') }}
166
  {%- endif %}
167
  {%- set ns_order = namespace(previous_role=none) %}
168
  {%- for message in loop_messages %}
@@ -170,19 +170,19 @@
170
  {%- if ns_order.previous_role is not none %}
171
  {%- if ns_order.previous_role == 'system' %}
172
  {%- if current_role not in ['user', 'assistant', 'system'] %}
173
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
174
  {%- endif %}
175
  {%- elif ns_order.previous_role == 'user' %}
176
  {%- if current_role not in ['assistant', 'system', 'user'] %}
177
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
178
  {%- endif %}
179
  {%- elif ns_order.previous_role == 'assistant' %}
180
  {%- if current_role not in ['assistant', 'user', 'tool'] %}
181
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
182
  {%- endif %}
183
  {%- elif ns_order.previous_role == 'tool' %}
184
  {%- if current_role not in ['assistant', 'tool', 'user'] %}
185
- {{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
186
  {%- endif %}
187
  {%- endif %}
188
  {%- endif %}
@@ -233,7 +233,7 @@
233
  {%- elif arguments == '' %}
234
  {%- set arguments = '{}' %}
235
  {%- endif %}
236
- {{- name + '[ARGS]' + arguments }}
237
  {%- endfor %}
238
  {%- endif %}
239
 
@@ -253,6 +253,6 @@
253
 
254
  {#- Raise exception for unsupported roles. #}
255
  {%- else %}
256
- {{- raise_exception('Only user, assistant, system and tool roles are supported, got ' + message['role'] + '.') }}
257
  {%- endif %}
258
- {%- endfor %}
 
8
  {#- Handle system prompt if it exists. #}
9
  {%- set loop_messages = messages %}
10
  {%- if messages[0]['role'] != 'system' and default_system_message != '' %}
11
+ {{- '[SYSTEM_PROMPT]' ~ default_system_message ~ '[/SYSTEM_PROMPT]' }}
12
  {%- endif %}
13
 
14
 
 
17
  {%- set has_tools = false %}
18
  {%- if tools is defined and tools is not none and tools|length > 0 %}
19
  {%- set has_tools = true %}
20
+ {%- set available_tools = '[AVAILABLE_TOOLS]' ~ (tools| tojson) ~ '[/AVAILABLE_TOOLS]' %}
21
  {%- endif %}
22
  {%- set json_schema = none %}
23
  {%- if response_format is defined and response_format is not none %}
24
+ {%- set response_format_type = response_format.get('type', 'text') %}
25
+ {%- set response_json_schema = response_format.get('json_schema') %}
26
+ {%- if response_format_type not in ['text', 'json_object', 'json_schema'] %}
27
+ {{- raise_exception('Response format type must be one of text, json_object or json_schema, got ' ~ response_format_type ~ '.') }}
28
+ {%- elif response_format_type == 'json_schema' %}
29
+ {%- if response_json_schema is none or response_json_schema.get('schema') is none %}
 
 
 
 
 
 
30
  {{- raise_exception('Response format `json_schema` must define the schema') }}
31
+ {%- else %}
32
+ {%- set json_schema = response_json_schema['schema'] %}
33
  {%- endif %}
34
+ {%- elif response_format_type == 'json_object' %}
35
  {%- set json_schema = {'anyOf': [{'type': 'object'}, {'type': 'array'}]} %}
36
  {%- endif %}
37
  {%- endif %}
38
  {%- if reasoning_effort is not defined or reasoning_effort is none %}
39
+ {%- set reasoning_effort = 'high' %}
40
  {%- endif %}
41
+ {%- if reasoning_effort not in ['low', 'medium', 'high'] %}
42
+ {{- raise_exception('reasoning_effort must be one of "low", "medium", "high"') }}
43
  {%- endif %}
44
+ {%- set model_settings_parts = [] %}
45
  {%- if json_schema is not none %}
46
+ {%- set model_settings_parts = model_settings_parts + ['"json_schema": ' ~ (json_schema|tojson)] %}
47
+ {%- endif %}
48
+ {%- set model_settings_parts = model_settings_parts + ['"reasoning_effort": "' ~ reasoning_effort ~ '"'] %}
49
+ {%- set model_settings = '' %}
50
+ {%- if model_settings_parts %}
51
+ {%- set model_settings = '[MODEL_SETTINGS]{' ~ model_settings_parts|join(', ') ~ '}[/MODEL_SETTINGS]' %}
52
  {%- endif %}
53
 
54
  {#- Macros #}
 
60
  {%- if block['type'] == 'text' -%}
61
  {{- block['text'] -}}
62
  {%- elif support_thinking and block['type'] == 'thinking' -%}
63
+ {{- '[THINK]' ~ block['thinking'] -}}
64
  {%- if block.get('closed', true) -%}{{- '[/THINK]' -}}{%- endif -%}
65
  {%- elif support_images and block['type'] in ['image', 'image_url'] -%}
66
  {{- '[IMG]' -}}
67
  {%- else -%}
68
+ {{- raise_exception('Only ' ~ supported_types_desc ~ ' chunks are supported in ' ~ context_name ~ '.') -}}
69
  {%- endif -%}
70
  {%- endfor -%}
71
  {%- else -%}
72
+ {{- raise_exception(context_name ~ ' must have non-empty content.') -}}
73
  {%- endif -%}
74
  {%- endmacro -%}
75
 
 
162
  {#- Validates message ordering. #}
163
  {%- set ns = namespace(available_tools_and_settings_emitted=false) %}
164
  {%- if loop_messages | length > 0 and loop_messages[0]['role'] not in ['user', 'system'] %}
165
+ {{- raise_exception('Conversation must start with a user or system message, got ' ~ loop_messages[0]['role'] ~ '.') }}
166
  {%- endif %}
167
  {%- set ns_order = namespace(previous_role=none) %}
168
  {%- for message in loop_messages %}
 
170
  {%- if ns_order.previous_role is not none %}
171
  {%- if ns_order.previous_role == 'system' %}
172
  {%- if current_role not in ['user', 'assistant', 'system'] %}
173
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
174
  {%- endif %}
175
  {%- elif ns_order.previous_role == 'user' %}
176
  {%- if current_role not in ['assistant', 'system', 'user'] %}
177
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
178
  {%- endif %}
179
  {%- elif ns_order.previous_role == 'assistant' %}
180
  {%- if current_role not in ['assistant', 'user', 'tool'] %}
181
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
182
  {%- endif %}
183
  {%- elif ns_order.previous_role == 'tool' %}
184
  {%- if current_role not in ['assistant', 'tool', 'user'] %}
185
+ {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
186
  {%- endif %}
187
  {%- endif %}
188
  {%- endif %}
 
233
  {%- elif arguments == '' %}
234
  {%- set arguments = '{}' %}
235
  {%- endif %}
236
+ {{- name ~ '[ARGS]' ~ arguments }}
237
  {%- endfor %}
238
  {%- endif %}
239
 
 
253
 
254
  {#- Raise exception for unsupported roles. #}
255
  {%- else %}
256
+ {{- raise_exception('Only user, assistant, system and tool roles are supported, got ' ~ message['role'] ~ '.') }}
257
  {%- endif %}
258
+ {%- endfor %}