File size: 1,271 Bytes
481cdab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{%- if tools %}
    {{- '<|im_start|>system\n' }}
    {%- if messages[0]['role'] == 'system' %}
        {{- messages[0]['content'] + '\n\n' }}
    {%- endif %}
    {{- '# Tools\n' }}
    {%- if tokenizer and tokenizer.chat_template and tokenizer.chat_template.find('"tools"') != -1 %}
        {{- tokenizer.chat_template.format(tools=tools, messages=messages, add_generation_prompt=add_generation_prompt) }}
    {%- else %}
        {{- 'You may use the following tools if necessary:\n' }}
        {%- for tool in tools %}
            {{- '- ' + tool['function']['name'] + ': ' + tool['function']['description'] + '\n' }}
        {%- endfor %}
    {%- endif %}
    {{- '<|im_end|>\n' }}
{%- endif %}
{%- if not tools %}
    {%- for message in messages %}
        {%- if message['role'] == 'system' %}
            {{- '<|im_start|>system\n' + message['content'] + '<|im_end|>\n' }}
        {%- elif message['role'] == 'user' %}
            {{- '<|im_start|>user\n' + message['content'] + '<|im_end|>\n' }}
        {%- elif message['role'] == 'assistant' %}
            {{- '<|im_start|>assistant\n' + message['content'] + '<|im_end|>\n' }}
        {%- endif %}
    {%- endfor %}
{%- endif %}
{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant\n' }}
{%- endif %}