main
jinja 62 lines 2.28 KB
Raw
1 {%- if messages and messages[0]['role'] == 'system' %}
2 {%- set system_message = messages[0]['content']|trim %}
3 {%- set messages = messages[1:] %}
4 {%- else %}
5 {%- set system_message = "You are a helpful assistant." %}
6 {%- endif %}
7
8 {%- if messages %}
9 <|system|>
10 {{ system_message }}
11 {%- if tools %}
12 In addition to plain text responses, you can choose to call one or more of the provided functions.
13
14 Use the following rule to decide when to call a function:
15 * if the response can be generated from your internal knowledge (e.g., as in the case of queries like "What is the capital of Poland?"), do so
16 * if you need external information that can be obtained by calling one or more of the provided functions, generate a function calls
17
18 If you decide to call functions:
19 * prefix function calls with functools marker (no closing marker required)
20 * all function calls should be generated in a single JSON list formatted as functools[{"name": [function name], "arguments": [function arguments as JSON]}, ...]
21 * follow the provided JSON schema. Do not hallucinate arguments or values. Do to blindly copy values from the provided samples
22 * respect the argument type formatting. E.g., if the type is number and format is float, write value 7 as 7.0
23 * make sure you pick the right functions that match the user intent
24
25
26 {%- for t in tools %}
27 {{- t | tojson(indent=4) }}
28 {{- "\n\n" }}
29 {%- endfor %}
30 {%- endif %}<|end|>
31
32 {%- for message in messages %}
33 {%- if message.role != "system" %}
34 <|{{ message.role }}|>
35 {%- if message.content and message.role == "tools" %}
36 {"result": {{ message.content }}}
37 {%- elif message.content %}
38 {{ message.content }}
39 {%- elif message.tool_calls %}
40 {%- for call in message.tool_calls %}
41 {"name": "{{ call.function.name }}", "arguments": {{ call.function.arguments }}}
42 {%- if not loop.last %},{% endif %}
43 {%- endfor %}
44 {%- endif %}<|end|>
45 {%- endif %}
46 {%- endfor %}<|assistant|>
47
48 {%- else %}
49 {%- if system_message %}
50 <|system|>
51
52 {{ system_message }}<|end|>
53 {%- endif %}
54 {%- if prompt %}
55 <|user|>
56
57 {{ prompt }}<|end|>
58 {%- endif %}<|assistant|>
59
60 {%- endif %}
61 {{ response }}
62 {%- if response %}<|user|>{% endif %}