{{ '' -}}{% set ns = namespace(system_prompt='') -%}{% for message in messages -%}{% if message['role'] == 'system' -%}{% set ns.system_prompt = ns.system_prompt + message['content'][0]['text'] -%}{% endif -%}{%- endfor -%}{% if ns.system_prompt != '' -%}{{ 'system ai_setting=assistant ' + ns.system_prompt + ' ' -}}{%- endif -%}{% if tools -%}{{ 'system tool_setting=tools You are provided with these tools: ' -}}{% for tool in tools -%}{{ tool | tojson ~ ' ' -}}{%- endfor -%}{{ ' If you need to call tools, please respond with XML tags, and provide tool-name and json-object of arguments, following the format below: {''name'': , ''arguments'': } ... ' -}}{%- endif -%}{% for message in messages -%}{% if message['role'] == 'user' -%}{{ 'user name=user ' + message['content'][0]['text'] + ' ' -}}{% elif message['role'] == 'assistant' -%}{{ 'ai name=assistant ' -}}{% for content in message['content'] | selectattr('type', 'equalto', 'text') -%}{{ content['text'] -}}{%- endfor -%}{{ ' ' -}}{% elif message['role'] == 'tool' -%}{{ 'tool name=tools ' }} {%- for content in message['content'] -%}{{- 'tool name: ' + content['name'] + ' ' + 'tool result: ' + content['text'] + ' ' -}} {%- endfor -%}{{- ' ' -}}{% endif -%}{%- endfor -%}{% if add_generation_prompt -%}{{ 'ai name=assistant ' -}}{%- endif -%}