Model

ankit/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4

Blame for chat_template.jinja at f145a01

Line blame for chat_template.jinja
LineCommitAuthorDateCode
1Add files using upload-large-folder toolbf6c919ankit{% macro render_extra_keys(json_dict, handled_keys) %}
2 {%- if json_dict is mapping %}
3 {%- for json_key in json_dict if json_key not in handled_keys %}
4 {%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}
5 {{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}
6 {%- else %}
7 {{-'\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}
8 {%- endif %}
9 {%- endfor %}
10 {%- endif %}
11{% endmacro %}
12{%- macro render_content(content) -%}
13 {%- if content is none -%}
14 {{- '' -}}
15 {%- elif content is string -%}
16 {{- content | string -}}
17 {%- else -%}
18 {%- set text_ns = namespace(val='') -%}
19 {%- set counters = namespace(images=0, videos=0) -%}
20 {%- for part in content -%}
21 {%- if part['type'] == 'image' or part['type'] == 'image_url' or part['type'] == 'input_image' -%}
22 {%- set counters.images = counters.images + 1 -%}
23 {%- elif part['type'] == 'video' or part['type'] == 'video_url' or part['type'] == 'input_video' -%}
24 {%- set counters.videos = counters.videos + 1 -%}
25 {%- elif part['type'] == 'text' or part['type'] == 'input_text' -%}
26 {%- set text_ns.val = text_ns.val + (part['text'] | default('', true)) -%}
27 {%- endif -%}
28 {%- endfor -%}
29 {%- if '<image>' in text_ns.val -%}
30 {%- set counters.images = 0 -%}
31 {%- endif -%}
32 {%- if '<video>' in text_ns.val -%}
33 {%- set counters.videos = 0 -%}
34 {%- endif -%}
35 {%- set content_ns = namespace(val='') -%}
36 {%- set render_ns = namespace(image_index=0, after_text=false) -%}
37 {%- for part in content -%}
38 {%- set sep = '\n' if render_ns.after_text and not content_ns.val.endswith('\n') else '' -%}
39 {%- if part['type'] == 'image' or part['type'] == 'image_url' or part['type'] == 'input_image' -%}
40 {%- set render_ns.image_index = render_ns.image_index + 1 -%}
41 {%- if counters.images > 0 -%}
42 {%- if counters.images > 1 -%}
43 {%- set content_ns.val = content_ns.val + sep
44 + '<image ' + render_ns.image_index|string + '><image>' -%}
45 {%- else -%}
46 {%- set content_ns.val = content_ns.val + sep + '<image>' -%}
47 {%- endif -%}
48 {%- set render_ns.after_text = false -%}
49 {%- endif -%}
50 {%- elif part['type'] == 'video' or part['type'] == 'video_url' or part['type'] == 'input_video' -%}
51 {%- if counters.videos > 0 -%}
52 {%- set content_ns.val = content_ns.val + sep + '<video>' -%}
53 {%- set render_ns.after_text = false -%}
54 {%- endif -%}
55 {%- elif part['type'] == 'text' or part['type'] == 'input_text' -%}
56 {%- set content_ns.val = content_ns.val + (part['text'] | default('', true)) -%}
57 {%- if part['text'] | default('', true) -%}
58 {%- set render_ns.after_text = true -%}
59 {%- endif -%}
60 {%- endif -%}
61 {%- endfor -%}
62 {{- content_ns.val -}}
63 {%- endif -%}
64{%- endmacro %}
65{%- set enable_thinking = enable_thinking if enable_thinking is defined else True %}
66{%- set medium_effort = medium_effort if medium_effort is defined else False %}
67{%- set truncate_history_thinking = truncate_history_thinking if truncate_history_thinking is defined else True %}
68{%- set ns = namespace(last_user_idx = -1) %}
69{%- set loop_messages = messages %}
70{%- for m in loop_messages %}
71 {%- if m["role"] == "user" %}
72 {%- set ns.last_user_idx = loop.index0 %}
73 {%- endif %}
74{%- endfor %}
75{%- if messages[0]["role"] == "system" %}
76 {%- set system_message = messages[0]["content"] %}
77 {%- set loop_messages = messages[1:] %}
78{%- else %}
79 {%- set system_message = "" %}
80 {%- set loop_messages = messages %}
81{%- endif %}
82{%- if not tools is defined %}
83 {%- set tools = [] %}
84{%- endif %}
85{%- set ns = namespace(last_user_idx = -1) %}
86{%- for m in loop_messages %}
87 {%- if m["role"] == "user" %}
88 {%- set ns.last_user_idx = loop.index0 %}
89 {%- endif %}
90{%- endfor %}
91{%- if system_message is defined %}
92 {{- "<|im_start|>system\n" ~ render_content(system_message) }}
93{%- else %}
94 {%- if tools is iterable and tools | length > 0 %}
95 {{- "<|im_start|>system\n" }}
96 {%- endif %}
97{%- endif %}
98{%- if tools is iterable and tools | length > 0 %}
99 {%- if system_message is defined and system_message | length > 0 %}
100 {{- "\n\n" }}
101 {%- endif %}
102 {{- "# Tools\n\nYou have access to the following functions:\n\n" }}
103 {{- "<tools>" }}
104 {%- for tool in tools %}
105 {%- if tool.function is defined %}
106 {%- set tool = tool.function %}
107 {%- endif %}
108 {{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
109 {%- if tool.description is defined %}
110 {{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
111 {%- endif %}
112 {{- '\n<parameters>' }}
113 {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
114 {%- for param_name, param_fields in tool.parameters.properties|items %}
115 {{- '\n<parameter>' }}
116 {{- '\n<name>' ~ param_name ~ '</name>' }}
117 {%- if param_fields.type is defined %}
118 {{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
119 {%- endif %}
120 {%- if param_fields.description is defined %}
121 {{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
122 {%- endif %}
123 {%- if param_fields.enum is defined %}
124 {{- '\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}
125 {%- endif %}
126 {%- set handled_keys = ['name', 'type', 'description', 'enum'] %}
127 {{- render_extra_keys(param_fields, handled_keys) }}
128 {{- '\n</parameter>' }}
129 {%- endfor %}
130 {%- endif %}
131 {% set handled_keys = ['type', 'properties', 'required'] %}
132 {{- render_extra_keys(tool.parameters, handled_keys) }}
133 {%- if tool.parameters is defined and tool.parameters.required is defined %}
134 {{- '\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}
135 {%- endif %}
136 {{- '\n</parameters>' }}
137 {%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}
138 {{- render_extra_keys(tool, handled_keys) }}
139 {{- '\n</function>' }}
140 {%- endfor %}
141 {{- "\n</tools>" }}
142 {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
143{%- endif %}
144{%- if system_message is defined %}
145 {{- '<|im_end|>\n' }}
146{%- else %}
147 {%- if tools is iterable and tools | length > 0 %}
148 {{- '<|im_end|>\n' }}
149 {%- endif %}
150{%- endif %}
151{%- for message in loop_messages %}
152 {%- set content = render_content(message.content | default('', true)) %}
153 {%- if message.role == "assistant" %}
154 {%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %}
155 {%- set content = "<think>\n" ~ message.reasoning_content ~ "</think>" ~ content %}
156 {%- else %}
157 {%- if content is string -%}
158 {%- if '<think>' not in content and '</think>' not in content -%}
159 {%- set content = "<think></think>" ~ content -%}
160 {%- endif -%}
161 {%- endif -%}
162 {%- endif %}
163 {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
164 {{- '<|im_start|>assistant\n' }}
165 {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
166 {%- if content is string and content | trim | length > 0 %}
167 {%- if include_content %}
168 {{- (content | trim) ~ '\n' -}}
169 {%- else %}
170 {%- set c = (content | string) %}
171 {%- if '</think>' in c %}
172 {%- set c = c.split('</think>')[-1] %}
173 {%- elif '<think>' in c %}
174 {%- set c = c.split('<think>')[0] %}
175 {%- endif %}
176 {%- set c = "<think></think>" ~ c %}
177 {%- if c | length > 0 %}
178 {{- c ~ '\n' -}}
179 {%- endif %}
180 {%- endif %}
181 {%- else %}
182 {{- "<think></think>" -}}
183 {%- endif %}
184 {%- for tool_call in message.tool_calls %}
185 {%- if tool_call.function is defined %}
186 {%- set tool_call = tool_call.function %}
187 {%- endif %}
188 {{- '<tool_call>\n<function=' ~ tool_call.name ~ '>\n' -}}
189 {%- if tool_call.arguments is defined %}
190 {%- for args_name, args_value in tool_call.arguments|items %}
191 {{- '<parameter=' ~ args_name ~ '>\n' -}}
192 {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
193 {{- args_value ~ '\n</parameter>\n' -}}
194 {%- endfor %}
195 {%- endif %}
196 {{- '</function>\n</tool_call>\n' -}}
197 {%- endfor %}
198 {{- '<|im_end|>\n' }}
199 {%- else %}
200 {%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
201 {{- '<|im_start|>assistant\n' ~ (content | default('', true) | string | trim) ~ '<|im_end|>\n' }}
202 {%- else %}
203 {%- set c = (content | default('', true) | string) %}
204 {%- if '<think>' in c and '</think>' in c %}
205 {%- set c = "<think></think>" ~ c.split('</think>')[-1] %}
206 {%- endif %}
207 {%- set c = c | trim %}
208 {%- if c | length > 0 %}
209 {{- '<|im_start|>assistant\n' ~ c ~ '<|im_end|>\n' }}
210 {%- else %}
211 {{- '<|im_start|>assistant\n<|im_end|>\n' }}
212 {%- endif %}
213 {%- endif %}
214 {%- endif %}
215 {%- elif message.role == "user" or message.role == "system" %}
216 {{- '<|im_start|>' + message.role + '\n' }}
217 {#- Render structured image/video content in its original order. -#}
218 {%- if message.role == "user" and loop.index0 == ns.last_user_idx and medium_effort %}
219 {{- content + '\n\n{reasoning effort: efficient}' }}
220 {%- else %}
221 {{- content }}
222 {%- endif %}
223 {{- '<|im_end|>\n' }}
224 {%- elif message.role == "tool" %}
225 {%- if loop.previtem and loop.previtem.role != "tool" %}
226 {{- '<|im_start|>user\n' }}
227 {%- endif %}
228 {{- '<tool_response>\n' }}
229 {{- content }}
230 {{- '\n</tool_response>\n' }}
231 {%- if not loop.last and loop.nextitem.role != "tool" %}
232 {{- '<|im_end|>\n' }}
233 {%- elif loop.last %}
234 {{- '<|im_end|>\n' }}
235 {%- endif %}
236 {%- else %}
237 {{- '<|im_start|>' ~ message.role ~ '\n' ~ content ~ '<|im_end|>\n' }}
238 {%- endif %}
239{%- endfor %}
240{%- if add_generation_prompt %}
241 {%- if enable_thinking %}
242 {{- '<|im_start|>assistant\n<think>\n' }}
243 {%- else %}
244 {{- '<|im_start|>assistant\n<think></think>' }}
245 {%- endif %}
246{%- endif %}