File size: 3,426 Bytes
f84a99b
4ae20bb
 
 
 
88f5353
4ae20bb
 
 
 
 
 
 
 
 
d0106eb
 
4ae20bb
d0106eb
4ae20bb
 
d0106eb
 
 
 
4ae20bb
d0106eb
 
4ae20bb
 
 
88f5353
4ae20bb
 
f84a99b
4ae20bb
f84a99b
4ae20bb
f84a99b
4ae20bb
 
f84a99b
 
 
 
4e2ee15
f84a99b
 
 
 
 
4ae20bb
f84a99b
4e2ee15
4ae20bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e2ee15
 
 
f84a99b
 
 
 
 
4e2ee15
4ae20bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e2ee15
 
 
f84a99b
 
 
 
 
defc7d7
f70a8d8
 
 
defc7d7
f70a8d8
f84a99b
defc7d7
f84a99b
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{{ bos_token }}
{%- if tools -%}
	{{- '<start_of_turn>' + 'system' + '
' -}}
	{%- if messages[0]['role'] == "system" -%}
        {%- set loop_messages = messages[1:] -%}
        {%- if messages[0]['content'] is string -%}
		    {{- messages[0]['content'] + '
' + '
' -}}
        {%- else -%}
            {{- messages[0]['content'][0]['text'] + '
' + '
' -}}
        {%- endif -%}
    {%- else -%}
    {%- set loop_messages = messages -%}
    {%- endif -%}
	{{-"# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>"-}}
    {%- for tool in tools -%}
    {{- "\n" -}}
	{{- tool | tojson -}}
	{%- endfor -%}
 {{-'
' + "</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>" -}}
    {{- '<end_of_turn>' + '
' -}}
{%- elif messages[0]['role'] == "system" -%}
    {%- set loop_messages = messages[1:] -%}
	{{- '<start_of_turn>' + 'system' + '
' -}}
    {%- if messages[0]['content'] is string -%}
        {{- messages[0]['content'] -}}
    {%- else -%}
        {{- messages[0]['content'][0]['text'] -}}
    {%- endif -%}
    {{- '<end_of_turn>
' }}
{%- else -%}
    {%- set loop_messages = messages -%}
{%- endif -%}
{%- for message in loop_messages -%}
    {%- if message['role'] == 'assistant' or message['role'] == 'model' -%}
        {%- set role = "model" -%}
    {%- else -%}
        {%- set role = message['role'] -%}
    {%- endif -%}
    {{ '<start_of_turn>' + role + '
' }}
    {%- if message['content'] is string -%}
        {%- if role == "model" -%}
{% generation %}
{{- message['content'] | trim -}}
{% if message['tool_calls'] %}
    {% for tool_call in message['tool_calls'] %}
        {% if tool_call['function'] is defined %}
            {% set tool_call = tool_call['function'] %}
        {% endif %}
{{- "
" -}}
<tool_call>
{"name": "{{ tool_call['name'] }}", "arguments": {{ tool_call['arguments'] | tojson }}}
</tool_call>
    {%- endfor -%}
{%- endif -%}
{% endgeneration %}
        {%- else -%}
            {{ message['content'] | trim }}
        {%- endif -%}
    {%- elif message['content'] is iterable -%}
        {%- for item in message['content'] -%}
            {%- if item['type'] == 'image' -%}
                {{ '<start_of_image>' }}
            {%- elif item['type'] == 'text' -%}
                {%- if role == "model" -%}
{% generation %}
{{- item['text'] | trim -}}
{% if message['tool_calls'] %}
    {% for tool_call in message['tool_calls'] %}
        {% if tool_call['function'] is defined %}
            {% set tool_call = tool_call['function'] %}
        {% endif %}
{{- "
" -}}
<tool_call>
{"name": "{{ tool_call['name'] }}", "arguments": {{ tool_call['arguments'] | tojson }}}
</tool_call>
    {%- endfor -%}
{%- endif -%}
{% endgeneration %}
                {%- else -%}
                    {{ item['text'] | trim }}
                {%- endif -%}
            {%- endif -%}
        {%- endfor -%}
    {%- else -%}
        {{ raise_exception("Invalid content type") }}
    {%- endif -%}
{%- if role == "model" -%}
{% generation %}
{{ '<end_of_turn>
' }}{% endgeneration %}
{%- else -%}
{{ '<end_of_turn>
' }}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}
    {{'<start_of_turn>model
'}}
{%- endif -%}