| {%- if add_special_tokens -%} | |
| {{ bos_token }} | |
| {%- endif -%} | |
| {%- set first_user_prefix = "" -%} | |
| {%- set loop_messages = messages -%} | |
| {%- for message in loop_messages -%} | |
| {%- if (message['role'] == 'tool_call') -%} | |
| {%- set role = "model" -%} | |
| {%- elif (message['role'] == 'assistant') -%} | |
| {%- set role = "model" -%} | |
| {%- else -%} | |
| {%- set role = message['role'] -%} | |
| {%- endif -%} | |
| {{ '<start_of_turn>' + role + ' | |
| ' + (first_user_prefix if loop.first else "") }} | |
| {%- if (message.reasoning_content) -%} | |
| {{- '<think>'+message.reasoning_content+'</think>' }} | |
| {%- endif -%} | |
| {%- if (message['role'] == 'tool_call') -%} | |
| {{- '<tool_call> | |
| {"name": "' }} | |
| {{- message.name }} | |
| {{- '", "arguments": ' }} | |
| {{- message.content | replace("'", '"') | trim }} | |
| {{- '} | |
| </tool_call>' }} | |
| {%- elif message['content'] is string -%} | |
| {{ message['content'] | trim }} | |
| {%- endif -%} | |
| {{ '<end_of_turn> | |
| ' }} | |
| {%- endfor -%} | |
| {%- if add_generation_prompt -%} | |
| {{'<start_of_turn>model | |
| '}} | |
| {%- endif -%} |