Model

ankit/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4

Blame for chat_template.jinja at 96438cf

Line blame for chat_template.jinja
LineCommitAuthorDateCode
1Mirror nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP496438cfankit{% 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{%- set enable_thinking = enable_thinking if enable_thinking is defined else True %}
13{%- set truncate_history_thinking = truncate_history_thinking if truncate_history_thinking is defined else True %}
14{%- set ns = namespace(last_user_idx = -1) %}
15{%- set loop_messages = messages %}
16{%- for m in loop_messages %}
17 {%- if m["role"] == "user" %}
18 {%- set ns.last_user_idx = loop.index0 %}
19 {%- endif %}
20{%- endfor %}
21{%- if messages[0]["role"] == "system" %}
22 {%- set system_message = messages[0]["content"] %}
23 {%- set loop_messages = messages[1:] %}
24{%- else %}
25 {%- set system_message = "" %}
26 {%- set loop_messages = messages %}
27{%- endif %}
28{%- if not tools is defined %}
29 {%- set tools = [] %}
30{%- endif %}
31{%- set ns = namespace(last_user_idx = -1) %}
32{%- for m in loop_messages %}
33 {%- if m["role"] == "user" %}
34 {%- set ns.last_user_idx = loop.index0 %}
35 {%- endif %}
36{%- endfor %}
37{%- if system_message is defined %}
38 {{- "<|im_start|>system\n" + system_message }}
39{%- else %}
40 {%- if tools is iterable and tools | length > 0 %}
41 {{- "<|im_start|>system\n" }}
42 {%- endif %}
43{%- endif %}
44{%- if tools is iterable and tools | length > 0 %}
45 {%- if system_message is defined and system_message | length > 0 %}
46 {{- "\n\n" }}
47 {%- endif %}
48 {{- "# Tools\n\nYou have access to the following functions:\n\n" }}
49 {{- "<tools>" }}
50 {%- for tool in tools %}
51 {%- if tool.function is defined %}
52 {%- set tool = tool.function %}
53 {%- endif %}
54 {{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
55 {%- if tool.description is defined %}
56 {{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
57 {%- endif %}
58 {{- '\n<parameters>' }}
59 {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
60 {%- for param_name, param_fields in tool.parameters.properties|items %}
61 {{- '\n<parameter>' }}
62 {{- '\n<name>' ~ param_name ~ '</name>' }}
63 {%- if param_fields.type is defined %}
64 {{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
65 {%- endif %}
66 {%- if param_fields.description is defined %}
67 {{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
68 {%- endif %}
69 {%- if param_fields.enum is defined %}
70 {{- '\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}
71 {%- endif %}
72 {%- set handled_keys = ['name', 'type', 'description', 'enum'] %}
73 {{- render_extra_keys(param_fields, handled_keys) }}
74 {{- '\n</parameter>' }}
75 {%- endfor %}
76 {%- endif %}
77 {% set handled_keys = ['type', 'properties', 'required'] %}
78 {{- render_extra_keys(tool.parameters, handled_keys) }}
79 {%- if tool.parameters is defined and tool.parameters.required is defined %}
80 {{- '\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}
81 {%- endif %}
82 {{- '\n</parameters>' }}
83 {%- set handled_keys = ['type', 'name', 'description', 'parameters'] %}
84 {{- render_extra_keys(tool, handled_keys) }}
85 {{- '\n</function>' }}
86 {%- endfor %}
87 {{- "\n</tools>" }}
88 {{- '\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>' }}
89{%- endif %}
90{%- if system_message is defined %}
91 {{- '<|im_end|>\n' }}
92{%- else %}
93 {%- if tools is iterable and tools | length > 0 %}
94 {{- '<|im_end|>\n' }}
95 {%- endif %}
96{%- endif %}
97{%- for message in loop_messages %}
98 {%- if message.role == "assistant" %}
99 {%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 %}
100 {%- set content = "<think>\n" ~ message.reasoning_content ~ "</think>" ~ (message.content | default('', true)) %}
101 {%- else %}
102 {%- set content = message.content | default('', true) %}
103 {%- if content is string -%}
104 {%- if '<think>' not in content and '</think>' not in content -%}
105 {%- set content = "<think></think>" ~ content -%}
106 {%- endif -%}
107 {%- else -%}
108 {%- set content = content -%}
109 {%- endif -%}
110 {%- endif %}
111 {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 %}
112 {{- '<|im_start|>assistant\n' }}
113 {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
114 {%- if content is string and content | trim | length > 0 %}
115 {%- if include_content %}
116 {{- (content | trim) ~ '\n' -}}
117 {%- else %}
118 {%- set c = (content | string) %}
119 {%- if '</think>' in c %}
120 {%- set c = c.split('</think>')[-1] %}
121 {%- elif '<think>' in c %}
122 {%- set c = c.split('<think>')[0] %}
123 {%- endif %}
124 {%- set c = "<think></think>" ~ c %}
125 {%- if c | length > 0 %}
126 {{- c ~ '\n' -}}
127 {%- endif %}
128 {%- endif %}
129 {%- else %}
130 {{- "<think></think>" -}}
131 {%- endif %}
132 {%- for tool_call in message.tool_calls %}
133 {%- if tool_call.function is defined %}
134 {%- set tool_call = tool_call.function %}
135 {%- endif %}
136 {{- '<tool_call>\n<function=' ~ tool_call.name ~ '>\n' -}}
137 {%- if tool_call.arguments is defined %}
138 {%- for args_name, args_value in tool_call.arguments|items %}
139 {{- '<parameter=' ~ args_name ~ '>\n' -}}
140 {%- 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 %}
141 {{- args_value ~ '\n</parameter>\n' -}}
142 {%- endfor %}
143 {%- endif %}
144 {{- '</function>\n</tool_call>\n' -}}
145 {%- endfor %}
146 {{- '<|im_end|>\n' }}
147 {%- else %}
148 {%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) %}
149 {{- '<|im_start|>assistant\n' ~ (content | default('', true) | string | trim) ~ '<|im_end|>\n' }}
150 {%- else %}
151 {%- set c = (content | default('', true) | string) %}
152 {%- if '<think>' in c and '</think>' in c %}
153 {%- set c = "<think></think>" ~ c.split('</think>')[-1] %}
154 {%- endif %}
155 {%- set c = c | trim %}
156 {%- if c | length > 0 %}
157 {{- '<|im_start|>assistant\n' ~ c ~ '<|im_end|>\n' }}
158 {%- else %}
159 {{- '<|im_start|>assistant\n<|im_end|>\n' }}
160 {%- endif %}
161 {%- endif %}
162 {%- endif %}
163 {%- elif message.role == "user" or message.role == "system" %}
164 {{- '<|im_start|>' + message.role + '\n' }}
165 {%- set content = message.content | string %}
166 {{- content }}
167 {{- '<|im_end|>\n' }}
168 {%- elif message.role == "tool" %}
169 {%- if loop.previtem and loop.previtem.role != "tool" %}
170 {{- '<|im_start|>user\n' }}
171 {%- endif %}
172 {{- '<tool_response>\n' }}
173 {{- message.content }}
174 {{- '\n</tool_response>\n' }}
175 {%- if not loop.last and loop.nextitem.role != "tool" %}
176 {{- '<|im_end|>\n' }}
177 {%- elif loop.last %}
178 {{- '<|im_end|>\n' }}
179 {%- endif %}
180 {%- else %}
181 {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>\n' }}
182 {%- endif %}
183{%- endfor %}
184{%- if add_generation_prompt %}
185 {%- if enable_thinking %}
186 {{- '<|im_start|>assistant\n<think>\n' }}
187 {%- else %}
188 {{- '<|im_start|>assistant\n<think></think>' }}
189 {%- endif %}
190{%- endif %}