Guest User

Untitled

a guest
Oct 16th, 2026
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.65 KB | None | 0 0
  1. {#- Nemotron 3.5 Bolt 74B (DavidAU) - fixed template for Atomic Chat.
  2. Native ChatML format + <think> reasoning.
  3. Atomic sends chat_template_kwargs:
  4. Thinking ON : {"reasoning_effort": "low"|"medium"|"high"}
  5. Thinking OFF: {"enable_thinking": false, "reasoning_effort": "off"}
  6. Never raises for any effort value ("high" is mapped to the model's "xhigh" mode). -#}
  7. {%- macro render_extra_keys(json_dict, handled_keys) %}
  8. {%- if json_dict is mapping %}
  9. {%- for json_key in json_dict if json_key not in handled_keys %}
  10. {%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %}
  11. {{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '</' ~ json_key ~ '>' }}
  12. {%- else %}
  13. {{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '</' ~ json_key ~ '>' }}
  14. {%- endif %}
  15. {%- endfor %}
  16. {%- endif %}
  17. {% endmacro %}
  18. {%- macro render_content(content) -%}
  19. {%- if content is none -%}
  20. {{- '' -}}
  21. {%- elif content is string -%}
  22. {{- content | string -}}
  23. {%- else -%}
  24. {%- set text_ns = namespace(val='') -%}
  25. {%- set counters = namespace(images=0, videos=0) -%}
  26. {%- for part in content -%}
  27. {%- if part['type'] == 'image' or part['type'] == 'image_url' or part['type'] == 'input_image' -%}
  28. {%- set counters.images = counters.images + 1 -%}
  29. {%- elif part['type'] == 'video' or part['type'] == 'video_url' or part['type'] == 'input_video' -%}
  30. {%- set counters.videos = counters.videos + 1 -%}
  31. {%- elif part['type'] == 'text' or part['type'] == 'input_text' -%}
  32. {%- set text_ns.val = text_ns.val + (part['text'] | default('', true)) -%}
  33. {%- endif -%}
  34. {%- endfor -%}
  35. {%- if '<image>' in text_ns.val -%}
  36. {%- set counters.images = 0 -%}
  37. {%- endif -%}
  38. {%- if '<video>' in text_ns.val -%}
  39. {%- set counters.videos = 0 -%}
  40. {%- endif -%}
  41. {%- set content_ns = namespace(val='') -%}
  42. {%- set render_ns = namespace(image_index=0) -%}
  43. {%- for part in content -%}
  44. {%- if part['type'] == 'image' or part['type'] == 'image_url' or part['type'] == 'input_image' -%}
  45. {%- set render_ns.image_index = render_ns.image_index + 1 -%}
  46. {%- if counters.images > 0 -%}
  47. {%- if counters.images > 1 -%}
  48. {%- set content_ns.val = content_ns.val + '<image ' + render_ns.image_index|string + '><image>' -%}
  49. {%- else -%}
  50. {%- set content_ns.val = content_ns.val + '<image>' -%}
  51. {%- endif -%}
  52. {%- endif -%}
  53. {%- elif part['type'] == 'video' or part['type'] == 'video_url' or part['type'] == 'input_video' -%}
  54. {%- if counters.videos > 0 -%}
  55. {%- set content_ns.val = content_ns.val + '<video>' -%}
  56. {%- endif -%}
  57. {%- elif part['type'] == 'text' or part['type'] == 'input_text' -%}
  58. {%- set content_ns.val = content_ns.val + (part['text'] | default('', true)) -%}
  59. {%- endif -%}
  60. {%- endfor -%}
  61. {{- content_ns.val -}}
  62. {%- endif -%}
  63. {%- endmacro -%}
  64. {%- set DAU_xhigh = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' -%}
  65. {%- set DAU_low = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' -%}
  66. {%- set enable_thinking = enable_thinking if enable_thinking is defined else true -%}
  67. {%- if enable_thinking is string and enable_thinking | lower == 'false' -%}
  68. {%- set enable_thinking = false -%}
  69. {%- endif -%}
  70. {%- set eff = reasoning_effort | default('', true) | string | lower | trim -%}
  71. {%- set resolved = eff -%}
  72. {%- if resolved == '' -%}
  73. {%- if enable_thinking -%}
  74. {%- set resolved = 'off' -%}
  75. {%- else -%}
  76. {%- set resolved = 'medium' -%}
  77. {%- endif -%}
  78. {%- endif -%}
  79. {%- set reasoning_instructions = '' -%}
  80. {%- set medium_effort = false -%}
  81. {%- if resolved == 'low' -%}
  82. {%- set reasoning_instructions = DAU_low -%}
  83. {%- elif resolved == 'medium' -%}
  84. {%- set medium_effort = true -%}
  85. {%- elif resolved == 'high' or resolved == 'xhigh' or resolved == 'max' -%}
  86. {%- set reasoning_instructions = DAU_xhigh -%}
  87. {%- elif resolved == 'off' -%}
  88. {#- "off": no extra instruction, same as the model's native template -#}
  89. {%- elif reasoning_effort not in ['off', 'low', 'medium', 'high'] -%}
  90. {#- any other effort value: thinking stays enabled, no instruction, never raise -#}
  91. {%- endif -%}
  92. {%- if messages[0].role == 'system' -%}
  93. {%- set system_message = render_content(messages[0].content | default('', true)) -%}
  94. {%- set loop_messages = messages[1:] -%}
  95. {%- else -%}
  96. {%- set system_message = '' -%}
  97. {%- set loop_messages = messages -%}
  98. {%- endif -%}
  99. {%- if reasoning_instructions -%}
  100. {%- set system_message = (reasoning_instructions + ('\n' if system_message | trim | length > 0 else '') + (system_message | trim)) -%}
  101. {%- endif -%}
  102. {%- if not tools is defined -%}
  103. {%- set tools = [] -%}
  104. {%- endif -%}
  105. {%- set truncate_history_thinking = truncate_history_thinking if truncate_history_thinking is defined else true -%}
  106. {%- set ns = namespace(last_user_idx = -1) -%}
  107. {%- for m in loop_messages -%}
  108. {%- if m['role'] == 'user' -%}
  109. {%- set ns.last_user_idx = loop.index0 -%}
  110. {%- endif -%}
  111. {%- endfor -%}
  112. {{- '<|im_start|>system\n' + system_message }}
  113. {%- if tools is iterable and tools | length > 0 -%}
  114. {%- if system_message | length > 0 -%}
  115. {{- '\n\n' }}
  116. {%- endif -%}
  117. {{- '# Tools\n\nYou have access to the following functions:\n\n' }}
  118. {{- '<tools>' }}
  119. {%- for tool in tools -%}
  120. {%- if tool.function is defined -%}
  121. {%- set tool = tool.function -%}
  122. {%- endif -%}
  123. {{- '\n<function>\n<name>' ~ tool.name ~ '</name>' }}
  124. {%- if tool.description is defined -%}
  125. {{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
  126. {%- endif -%}
  127. {{- '\n<parameters>' }}
  128. {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping -%}
  129. {%- for param_name, param_fields in tool.parameters.properties | items -%}
  130. {{- '\n<parameter>' }}
  131. {{- '\n<name>' ~ param_name ~ '</name>' }}
  132. {%- if param_fields.type is defined -%}
  133. {{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
  134. {%- endif -%}
  135. {%- if param_fields.description is defined -%}
  136. {{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
  137. {%- endif -%}
  138. {%- if param_fields.enum is defined -%}
  139. {{- '\n<enum>' ~ (param_fields.enum | tojson | safe) ~ '</enum>' }}
  140. {%- endif -%}
  141. {%- set handled_keys = ['name', 'type', 'description', 'enum'] -%}
  142. {{- render_extra_keys(param_fields, handled_keys) }}
  143. {{- '\n</parameter>' }}
  144. {%- endfor -%}
  145. {%- endif -%}
  146. {%- set handled_keys = ['type', 'properties', 'required'] -%}
  147. {{- render_extra_keys(tool.parameters, handled_keys) }}
  148. {%- if tool.parameters is defined and tool.parameters.required is defined -%}
  149. {{- '\n<required>' ~ (tool.parameters.required | tojson | safe) ~ '</required>' }}
  150. {%- endif -%}
  151. {{- '\n</parameters>' }}
  152. {%- set handled_keys = ['type', 'name', 'description', 'parameters'] -%}
  153. {{- render_extra_keys(tool, handled_keys) }}
  154. {{- '\n</function>' }}
  155. {%- endfor -%}
  156. {{- '\n</tools>' }}
  157. {{- '\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>' }}
  158. {%- endif -%}
  159. {{- '<|im_end|>\n' }}
  160. {%- for message in loop_messages -%}
  161. {%- set content = render_content(message.content | default('', true)) -%}
  162. {%- if message.role == 'assistant' -%}
  163. {%- if message.reasoning_content is defined and message.reasoning_content is string and message.reasoning_content | trim | length > 0 -%}
  164. {%- set content = '<think>\n' ~ message.reasoning_content ~ '</think>' ~ content -%}
  165. {%- else -%}
  166. {%- if content is string -%}
  167. {%- if '<think>' not in content and '</think>' not in content -%}
  168. {%- set content = '<think></think>' ~ content -%}
  169. {%- endif -%}
  170. {%- endif -%}
  171. {%- endif -%}
  172. {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 -%}
  173. {{- '<|im_start|>assistant\n' }}
  174. {%- set include_content = not (truncate_history_thinking and loop.index0 < ns.last_user_idx) -%}
  175. {%- if content is string and content | trim | length > 0 -%}
  176. {%- if include_content -%}
  177. {{- (content | trim) ~ '\n' -}}
  178. {%- else -%}
  179. {%- set c = (content | string) -%}
  180. {%- if '</think>' in c -%}
  181. {%- set c = c.split('</think>')[-1] -%}
  182. {%- elif '<think>' in c -%}
  183. {%- set c = c.split('<think>')[0] -%}
  184. {%- endif -%}
  185. {%- set c = '<think></think>' ~ c -%}
  186. {%- if c | length > 0 -%}
  187. {{- c ~ '\n' -}}
  188. {%- endif -%}
  189. {%- endif -%}
  190. {%- else -%}
  191. {{- '<think></think>' -}}
  192. {%- endif -%}
  193. {%- for tool_call in message.tool_calls -%}
  194. {%- if tool_call.function is defined -%}
  195. {%- set tool_call = tool_call.function -%}
  196. {%- endif -%}
  197. {{- '<tool_call>\n<function=' ~ tool_call.name ~ '>\n' -}}
  198. {%- if tool_call.arguments is defined -%}
  199. {%- for args_name, args_value in tool_call.arguments | items -%}
  200. {{- '<parameter=' ~ args_name ~ '>\n' -}}
  201. {%- 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 -%}
  202. {{- args_value ~ '\n</parameter>\n' -}}
  203. {%- endfor -%}
  204. {%- endif -%}
  205. {{- '</function>\n</tool_call>\n' -}}
  206. {%- endfor -%}
  207. {{- '<|im_end|>\n' }}
  208. {%- else -%}
  209. {%- if not (truncate_history_thinking and loop.index0 < ns.last_user_idx) -%}
  210. {{- '<|im_start|>assistant\n' ~ (content | default('', true) | string | trim) ~ '<|im_end|>\n' }}
  211. {%- else -%}
  212. {%- set c = (content | default('', true) | string) -%}
  213. {%- if '<think>' in c and '</think>' in c -%}
  214. {%- set c = '<think></think>' ~ c.split('</think>')[-1] -%}
  215. {%- endif -%}
  216. {%- set c = c | trim -%}
  217. {%- if c | length > 0 -%}
  218. {{- '<|im_start|>assistant\n' ~ c ~ '<|im_end|>\n' }}
  219. {%- else -%}
  220. {{- '<|im_start|>assistant\n<|im_end|>\n' }}
  221. {%- endif -%}
  222. {%- endif -%}
  223. {%- endif -%}
  224. {%- elif message.role == 'user' or message.role == 'system' -%}
  225. {{- '<|im_start|>' + message.role + '\n' }}
  226. {%- if message.role == 'user' and loop.index0 == ns.last_user_idx and medium_effort -%}
  227. {{- content + '\n\n{reasoning effort: efficient}' }}
  228. {%- else -%}
  229. {{- content }}
  230. {%- endif -%}
  231. {{- '<|im_end|>\n' }}
  232. {%- elif message.role == 'tool' -%}
  233. {%- if loop.previtem and loop.previtem.role != 'tool' -%}
  234. {{- '<|im_start|>user\n' }}
  235. {%- endif -%}
  236. {{- '<tool_response>\n' }}
  237. {{- content }}
  238. {{- '\n</tool_response>\n' }}
  239. {%- if not loop.last and loop.nextitem.role != 'tool' -%}
  240. {{- '<|im_end|>\n' }}
  241. {%- elif loop.last -%}
  242. {{- '<|im_end|>\n' }}
  243. {%- endif -%}
  244. {%- else -%}
  245. {{- '<|im_start|>' ~ message.role ~ '\n' ~ content ~ '<|im_end|>\n' }}
  246. {%- endif -%}
  247. {%- endfor -%}
  248. {%- if add_generation_prompt -%}
  249. {%- if enable_thinking -%}
  250. {{- '<|im_start|>assistant\n<think>\n' }}
  251. {%- else -%}
  252. {{- '<|im_start|>assistant\n<think></think>' }}
  253. {%- endif -%}
  254. {%- endif -%}
  255.  
Advertisement
Add Comment
Please, Sign In to add comment