| {{- bos_token }}
|
| {%- if not tools is defined %}
|
| {%- set tools = none %}
|
| {%- endif %}
|
| {%- if not enable_thinking is defined %}
|
| {%- set enable_thinking = false %}
|
| {%- endif %}
|
|
|
| {%- if messages[0]['role'] == 'system' %}
|
| {%- set system_message = messages[0]['content']|trim %}
|
| {%- set messages = messages[1:] %}
|
| {%- else %}
|
| {%- set system_message = "" %}
|
| {%- endif %}
|
|
|
| {%- if enable_thinking %}
|
| {%- if system_message != "" %}
|
| {%- set system_message = "Enable deep thinking subroutine.
|
|
|
| " ~ system_message %}
|
| {%- else %}
|
| {%- set system_message = "Enable deep thinking subroutine." %}
|
| {%- endif %}
|
| {%- endif %}
|
|
|
| {%- if tools is not none or system_message != '' %}
|
| {{- "<|start_header_id|>system<|end_header_id|>
|
|
|
| " }}
|
| {{- system_message }}
|
| {%- if tools is not none %}
|
| {%- if system_message != "" %}
|
| {{- "
|
|
|
| " }}
|
| {%- endif %}
|
| {{- "Available Tools:
|
| " }}
|
| {%- for t in tools %}
|
| {{- t | tojson(indent=4) }}
|
| {{- "
|
|
|
| " }}
|
| {%- endfor %}
|
| {%- endif %}
|
| {{- "<|eot_id|>" }}
|
| {%- endif %}
|
|
|
|
|
| {%- for message in messages %}
|
|
|
|
|
| {%- if not (message.role == "ipython" or message.role == "tool" or message.role == "tool_results" or (message.tool_calls is defined and message.tool_calls is not none)) %}
|
| {{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>
|
|
|
| ' }}
|
| {%- if message['content'] is string %}
|
| {{- message['content'] | trim }}
|
| {%- else %}
|
| {%- for item in message['content'] %}
|
| {%- if item.type == 'text' %}
|
| {{- item.text | trim }}
|
| {%- endif %}
|
| {%- endfor %}
|
| {%- endif %}
|
| {{- '<|eot_id|>' }}
|
|
|
|
|
| {%- elif message.tool_calls is defined and message.tool_calls is not none %}
|
| {{- "<|start_header_id|>assistant<|end_header_id|>
|
|
|
| " }}
|
| {%- if message['content'] is string %}
|
| {{- message['content'] | trim }}
|
| {%- else %}
|
| {%- for item in message['content'] %}
|
| {%- if item.type == 'text' %}
|
| {{- item.text | trim }}
|
| {%- if item.text | trim != "" %}
|
| {{- "
|
|
|
| " }}
|
| {%- endif %}
|
| {%- endif %}
|
| {%- endfor %}
|
| {%- endif %}
|
| {{- "[" }}
|
| {%- for tool_call in message.tool_calls %}
|
| {%- set out = tool_call.function|tojson %}
|
| {%- if not tool_call.id is defined %}
|
| {{- out }}
|
| {%- else %}
|
| {{- out[:-1] }}
|
| {{- ', "id": "' + tool_call.id + '"}' }}
|
| {%- endif %}
|
| {%- if not loop.last %}
|
| {{- ", " }}
|
| {%- else %}
|
| {{- "]<|eot_id|>" }}
|
| {%- endif %}
|
| {%- endfor %}
|
|
|
|
|
| {%- elif message.role == "ipython" or message["role"] == "tool_results" or message["role"] == "tool" %}
|
| {{- "<|start_header_id|>ipython<|end_header_id|>
|
|
|
| " }}
|
| {%- if message.tool_call_id is defined and message.tool_call_id != '' %}
|
| {{- '{"content": ' + (message.content | tojson) + ', "call_id": "' + message.tool_call_id + '"}' }}
|
| {%- else %}
|
| {{- '{"content": ' + (message.content | tojson) + '}' }}
|
| {%- endif %}
|
| {{- "<|eot_id|>" }}
|
| {%- endif %}
|
| {%- endfor %}
|
| {%- if add_generation_prompt %}
|
| {{- '<|start_header_id|>assistant<|end_header_id|>
|
|
|
| ' }}
|
| {%- endif %} |