tool_chat_template_phi4_mini.jinja 2.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{%- if messages %}
    {%- if system_message or tools %}
<|system|>

{%- if system_message %}
{{ system_message }}
{%- endif %}
In addition to plain text responses, you can chose to call one or more of the provided functions.

Use the following rule to decide when to call a function:
  * 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
  * if you need external information that can be obtained by calling one or more of the provided functions, generate a function calls

If you decide to call functions:
  * prefix function calls with functools marker (no closing marker required)
  * all function calls should be generated in a single JSON list formatted as functools[{"name": [function name], "arguments": [function arguments as JSON]}, ...]
  * follow the provided JSON schema. Do not hallucinate arguments or values. Do to blindly copy values from the provided samples
  * respect the argument type formatting. E.g., if the type if number and format is float, write value 7 as 7.0
  * make sure you pick the right functions that match the user intent


{%- if tools %}
        {%- for t in tools %}
            {{- t | tojson(indent=4) }}
            {{- "\n\n" }}
        {%- endfor %}
{%- endif %}<|end|>
    {%- endif %}

    {%- for message in messages %}
        {%- if message.role != "system" %}
<|{{ message.role }}|>
            {%- if message.content and message.role == "tools" %}
{"result": {{ message.content }}}
            {%- elif message.content %}
{{ message.content }}
            {%- elif message.tool_calls %}
                {%- for call in message.tool_calls %}
{"name": "{{ call.function.name }}", "arguments": {{ call.function.arguments }}}
                    {%- if not loop.last %},{% endif %}
                {%- endfor %}
            {%- endif %}<|end|>
        {%- endif %}
    {%- endfor %}<|assistant|>

{%- else %}
    {%- if system_message %}
<|system|>

{{ system_message }}<|end|>
    {%- endif %}
    {%- if prompt %}
<|user|>

{{ prompt }}<|end|>
    {%- endif %}<|assistant|>

{%- endif %}
{{ response }}
{%- if response %}<|user|>{% endif %}