{ "chat_template": "{%- macro render_content(content) -%}\n {%- if content is string -%}\n {{- content -}}\n {%- else -%}\n {%- for item in content -%}\n {%- if item.type is defined and item.type == 'text' -%}\n {{- item.text -}}\n {%- elif item.type is defined and (item.type == 'image' or item.type == 'image_url') -%}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' -}}\n {%- elif item.type is defined and (item.type == 'video' or item.type == 'video_url') -%}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' -}}\n {%- elif item.text is defined -%}\n {{- item.text -}}\n {%- elif item.image is defined or item.image_url is defined -%}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' -}}\n {%- elif item.video is defined -%}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' -}}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n{%- endmacro -%}\n{%- set DEFAULT_SYSTEM = 'Your name is Salience 1.5 Flash. You ARE this AI assistant; never describe Salience as an external company or third party. When asked who you are, answer in the first person (for example: \"Sono Salience, un assistente AI per coding, debugging e design\"). You are an elite software-engineering agent: you handle very large codebases with long context, write production-grade backend and frontend code, and debug methodically. For any UI, default to modern stacks (React/Next, TypeScript, Tailwind, shadcn/ui), real design tokens, accessible WCAG semantics, responsive layout. Reply in the same language as the user.' -%}\n{%- set _has_sys = (messages | length > 0 and messages[0].role == 'system') -%}\n{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if _has_sys %}\n {{- render_content(messages[0].content) + '\\n\\n' }}\n {%- else %}\n {{- DEFAULT_SYSTEM + '\\n\\n' }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\\"name\\\": , \\\"arguments\\\": }\\n<|im_end|>\\n\" }}\n{%- else %}\n {%- if _has_sys %}\n {{- '<|im_start|>system\\n' + render_content(messages[0].content) + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\n' + DEFAULT_SYSTEM + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for forward_message in messages %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- set message = messages[index] %}\n {%- set current_content = message.content if message.content is string else '' %}\n {%- set tool_start = '' %}\n {%- set tool_start_length = tool_start|length %}\n {%- set start_of_message = current_content[:tool_start_length] %}\n {%- set tool_end = '' %}\n {%- set tool_end_length = tool_end|length %}\n {%- set start_pos = (current_content|length) - tool_end_length %}\n {%- if start_pos < 0 %}\n {%- set start_pos = 0 %}\n {%- endif %}\n {%- set end_of_message = current_content[start_pos:] %}\n {%- if ns.multi_step_tool and message.role == \"user\" and not(start_of_message == tool_start and end_of_message == tool_end) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if message.role == \"user\" %}\n {{- '<|im_start|>user\\n' + render_content(message.content) + '<|im_end|>\\n' }}\n {%- elif message.role == \"system\" and not loop.first %}\n {{- '<|im_start|>system\\n' + render_content(message.content) + '<|im_end|>\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set content = render_content(message.content) %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is defined and message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- elif '' in content %}\n {%- set reasoning_content = content.split('')[0].rstrip('\\n').split('')[-1].lstrip('\\n') %}\n {%- set content = content.split('')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- if loop.index0 > ns.last_query_index %}\n {%- if loop.last or (not loop.last and reasoning_content) %}\n {{- '<|im_start|>assistant\\n\\n' + reasoning_content.strip('\\n') + '\\n\\n\\n' + content.lstrip('\\n') }}\n {%- else %}\n {{- '<|im_start|>assistant\\n' + content }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>assistant\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n\\n' + render_content(message.content) + '\\n' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}" }