{%- if tools %} <|im_start|>system {%- if messages[0].role == 'system' -%} {{ messages[0].content }} {%- else -%} You are a helpful assistant. {%- endif -%} # Tools You may call one or more functions to assist with the user query. The function signatures are provided below: {%- for tool in tools %} {{ tool | tojson }} {%- endfor %} When you need to call a tool, respond with XML tags in this exact format: value1 value2 <|im_end|> {%- else %} {%- if messages[0].role == 'system' -%} <|im_start|>system {{ messages[0].content }}<|im_end|> {%- endif -%} {%- endif %} {%- for message in messages %} {%- if (message.role == "user") or (message.role == "system" and not loop.first) %} <|im_start|>{{ message.role }} {{ message.content }}<|im_end|> {%- elif message.role == "assistant" %} <|im_start|>assistant {%- if message.content %} {{ message.content }} {%- endif %} <|im_end|> {%- elif message.role == "tool" %} <|im_start|>user {{ message.content }} <|im_end|> {%- endif %} {%- endfor %} {%- if add_generation_prompt %} <|im_start|>assistant {%- endif %}