main
jinja 54 lines 1.76 KB
Raw
1 {%- set counter = namespace(index=0) -%}
2 {%- if not tools is defined %}
3 {%- set tools = none %}
4 {%- endif %}
5
6 {%- if messages and messages[0]['role'] == 'system' %}
7 {%- set system_message = messages[0]['content']|trim %}
8 {%- set messages = messages[1:] %}
9 {%- else %}
10 {%- set system_message = "You are a helpful assistant." %}
11 {%- endif %}
12
13 {%- if tools is not none %}
14 {%- set tool_instruction %}
15 You have access to the following tools. When you need to call a tool, you MUST use the following format:
16
17 <tool_call>function_name
18 <arg_key>parameter_name</arg_key>
19 <arg_value>parameter_value</arg_value>
20 </tool_call>
21
22 Important rules:
23 - Always wrap tool calls with <tool_call>...</tool_call> tags
24 - Put the function name on the first line after <tool_call>
25 - Use <arg_key> and <arg_value> tags for each parameter
26 - If a parameter value is a string, keep it as-is. If it's a number or boolean, convert it appropriately
27 - You can make multiple tool calls if needed
28 - If no tool is suitable, respond with regular text
29
30 Available tools:
31 {% endset %}
32 {{- tool_instruction + "\n\n" }}
33 {%- for t in tools %}
34 {{- t | tojson(indent=4) }}
35 {{- "\n\n" }}
36 {%- endfor %}
37 {%- endif %}
38
39 {%- for message in messages -%}
40 {%- if message['role'] == 'user' -%}
41 {{- '[Round ' + counter.index|string + ']\n问:' + message['content'] -}}
42 {%- set counter.index = counter.index + 1 -%}
43 {%- endif -%}
44 {%- if message['role'] == 'assistant' -%}
45 {{- '\n答:' + message['content'] -}}
46 {%- if (loop.last and add_generation_prompt) or not loop.last -%}
47 {{- '\n' -}}
48 {%- endif -%}
49 {%- endif -%}
50 {%- endfor -%}
51
52 {%- if add_generation_prompt and messages[-1]['role'] != 'assistant' -%}
53 {{- '\n答:' -}}
54 {%- endif -%}