main
jinja 54 lines 1.61 KB
Raw
1 {%- set ns = namespace(developer_content='', has_tools=false) -%}
2
3 {%- if tools is defined and tools | length > 0 -%}
4 {%- set ns.has_tools = true -%}
5 {%- endif -%}
6
7 {%- for message in messages -%}
8 {%- if message.role == 'developer' or message.role == 'system' -%}
9 <start_of_turn>user
10 {{ message.content }}
11 {%- if ns.has_tools %}
12
13 Available functions:
14 {%- for tool in tools %}
15 {%- if tool.type == 'function' %}
16
17 Function: {{ tool.function.name }}
18 Description: {{ tool.function.description | default('No description provided') }}
19 Parameters: {{ tool.function.parameters | tojson }}
20 {%- endif %}
21 {%- endfor %}
22 {%- endif %}
23 <end_of_turn>
24 {%- elif message.role == 'user' -%}
25 <start_of_turn>user
26 {{ message.content }}<end_of_turn>
27 {%- elif message.role == 'assistant' -%}
28 {%- if message.tool_calls is defined and message.tool_calls | length > 0 -%}
29 <start_of_turn>model
30 {%- for tool_call in message.tool_calls %}
31 <start_function_call>call:{{ tool_call.function.name }}{
32 {%- set args = tool_call.function.arguments -%}
33 {%- if args is string -%}
34 {%- set args = args | fromjson -%}
35 {%- endif -%}
36 {%- for key, value in args.items() -%}
37 {{ key }}:<escape>{{ value }}<escape>{% if not loop.last %},{% endif %}
38 {%- endfor -%}
39 }<end_function_call>
40 {%- endfor %}
41 <end_of_turn>
42 {%- else -%}
43 <start_of_turn>model
44 {{ message.content }}<end_of_turn>
45 {%- endif -%}
46 {%- elif message.role == 'tool' -%}
47 <start_of_turn>user
48 Function result for {{ message.name | default('function') }}: {{ message.content }}<end_of_turn>
49 {%- endif -%}
50 {%- endfor -%}
51
52 {%- if add_generation_prompt -%}
53 <start_of_turn>model
54 {%- endif -%}