File size: 2,807 Bytes
6149486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{{ bos_token }}
{%- set ns = namespace(has_tools=false) -%}
{%- if tools is defined and tools|length > 0 -%}
    {%- set ns.has_tools = true -%}
{%- endif -%}

{%- if messages[0]['role'] == 'system' -%}
    {{- '<|system|>\n' + messages[0]['content'] | trim -}}
    {%- if ns.has_tools -%}
        {{- '\n\nKullanılabilir Fonksiyonlar:\n' -}}
        {%- for tool in tools -%}
            {{- '<tool>\n' -}}
            {{- 'Fonksiyon Adı: ' + tool['function']['name'] + '\n' -}}
            {{- 'Açıklama: ' + tool['function']['description'] + '\n' -}}
            {{- 'Parametreler:\n' -}}
            {%- for prop_name, prop_data in tool['function']['parameters']['properties'].items() -%}
                {{- '  - ' + prop_name + ': ' + prop_data['description'] + ' (Tip: ' + prop_data['type'] + ')\n' -}}
            {%- endfor -%}
            {{- '</tool>\n' -}}
        {%- endfor -%}
    {%- endif -%}
    {{- '<|end|>\n' -}}
    {%- set loop_messages = messages[1:] -%}
{%- else -%}
    {%- set loop_messages = messages -%}
    {%- if ns.has_tools -%}
        {{- '<|system|>\nKullanılabilir Fonksiyonlar:\n' -}}
        {%- for tool in tools -%}
            {{- '<tool>\n' -}}
            {{- 'Fonksiyon Adı: ' + tool['function']['name'] + '\n' -}}
            {{- 'Açıklama: ' + tool['function']['description'] + '\n' -}}
            {{- 'Parametreler:\n' -}}
            {%- for prop_name, prop_data in tool['function']['parameters']['properties'].items() -%}
                {{- '  - ' + prop_name + ': ' + prop_data['description'] + ' (Tip: ' + prop_data['type'] + ')\n' -}}
            {%- endfor -%}
            {{- '</tool>\n' -}}
        {%- endfor -%}
        {{- '<|end|>\n' -}}
    {%- endif -%}
{%- endif -%}

{%- for message in loop_messages -%}
    {%- if message['role'] == 'user' -%}
        {{- '<|user|>\n' + message['content'] | trim + '<|end|>\n' -}}
    {%- elif message['role'] == 'assistant' -%}
        {{- '<|assistant|>\n' -}}
        {%- if message['content'] is defined and message['content'] is not none -%}
            {{- message['content'] | trim -}}
        {%- endif -%}
        {%- if message['tool_calls'] is defined and message['tool_calls']|length > 0 -%}
            {%- for tool_call in message['tool_calls'] -%}
                {{- '\n<tool_call>\n{"name": "' + tool_call['function']['name'] + '", "arguments": ' + tool_call['function']['arguments'] | string + '}\n</tool_call>' -}}
            {%- endfor -%}
        {%- endif -%}
        {{- '<|end|>\n' -}}
    {%- elif message['role'] == 'tool' -%}
        {{- '<|tool_response|>\n{"name": "' + message['name'] + '", "content": ' + (message['content'] | string) + '}\n<|end|>\n' -}}
    {%- endif -%}
{%- endfor -%}

{%- if add_generation_prompt -%}
    {{- '<|assistant|>\n' -}}
{%- endif -%}