| {{- bos_token -}} | |
| {%- set system_prompt = "" -%} | |
| {%- if messages[0]["role"] == "system" -%} | |
| {%- set system_prompt = messages[0]["content"] -%} | |
| {%- set messages = messages[1:] -%} | |
| {%- endif -%} | |
| {%- if tools -%} | |
| {%- set system_prompt = system_prompt + ("\n" if system_prompt else "") + "List of tools: <|tool_list_start|>" + tools | tojson + "<|tool_list_end|>" -%} | |
| {%- endif -%} | |
| {%- if system_prompt -%} | |
| {{- "<|im_start|>system\n" + system_prompt + "<|im_end|>\n" -}} | |
| {%- endif -%} | |
| {%- for message in messages -%} | |
| {{- "<|im_start|>" + message["role"] + "\n" -}} | |
| {%- set content = message["content"] -%} | |
| {%- if content is not string -%} | |
| {%- set content = content | tojson -%} | |
| {%- endif -%} | |
| {%- if message["role"] == "tool" -%} | |
| {%- set content = "<|tool_response_start|>" + content + "<|tool_response_end|>" -%} | |
| {%- endif -%} | |
| {{- content + "<|im_end|>\n" -}} | |
| {%- endfor -%} | |
| {%- if add_generation_prompt -%} | |
| {{- "<|im_start|>assistant\n" -}} | |
| {%- endif -%} |