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