Uzef commited on
Commit
582dfd1
·
verified ·
1 Parent(s): 4e53561

Create chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +83 -0
chat_template.jinja ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gMASK]<sop>
2
+ {%- if tools -%}
3
+ <|system|>
4
+ # Tools
5
+ You may call one or more functions to assist with the user query.
6
+ You are provided with function signatures within <tools></tools> XML tags:
7
+ <tools>
8
+ {% for tool in tools %}
9
+ {{ tool | tojson(ensure_ascii=False) }}
10
+ {% endfor %}
11
+ </tools>
12
+ For each function call, output the function name and arguments within the following XML format:
13
+ <tool_call>{function-name}<arg_key>{arg-key-1}</arg_key><arg_value>{arg-value-1}</arg_value><arg_key>{arg-key-2}</arg_key><arg_value>{arg-value-2}</arg_value>...</tool_call>{%- endif -%}
14
+ {%- macro visible_text(content) -%}
15
+ {%- if content is string -%}
16
+ {{- content }}
17
+ {%- elif content is iterable and content is not mapping -%}
18
+ {%- for item in content -%}
19
+ {%- if item is mapping and item.type == 'text' -%}
20
+ {{- item.text }}
21
+ {%- elif item is string -%}
22
+ {{- item }}
23
+ {%- endif -%}
24
+ {%- endfor -%}
25
+ {%- else -%}
26
+ {{- content }}
27
+ {%- endif -%}
28
+ {%- endmacro -%}
29
+ {%- set ns = namespace(last_user_index=-1) %}
30
+ {%- for m in messages %}
31
+ {%- if m.role == 'user' %}
32
+ {% set ns.last_user_index = loop.index0 -%}
33
+ {%- endif %}
34
+ {%- endfor %}
35
+ {% for m in messages %}
36
+ {%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}
37
+ {%- elif m.role == 'assistant' -%}
38
+ <|assistant|>
39
+ {%- set reasoning_content = '' %}
40
+ {%- set content = visible_text(m.content) %}
41
+ {%- if m.reasoning_content is string %}
42
+ {%- set reasoning_content = m.reasoning_content %}
43
+ {%- else %}
44
+ {%- if '</think>' in content %}
45
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
46
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
47
+ {%- endif %}
48
+ {%- endif %}
49
+ {%- if ((clear_thinking is defined and not clear_thinking) or loop.index0 > ns.last_user_index) and reasoning_content -%}
50
+ {{ '<think>' + reasoning_content.strip() + '</think>'}}
51
+ {%- else -%}
52
+ {{ '</think>' }}
53
+ {%- endif -%}
54
+ {%- if content.strip() -%}
55
+ {{ content.strip() }}
56
+ {%- endif -%}
57
+ {% if m.tool_calls %}
58
+ {% for tc in m.tool_calls %}
59
+ {%- if tc.function %}
60
+ {%- set tc = tc.function %}
61
+ {%- endif %}
62
+ {{- '<tool_call>' + tc.name -}}
63
+ {% set _args = tc.arguments %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}</tool_call>{% endfor %}
64
+ {% endif %}
65
+ {%- elif m.role == 'tool' -%}
66
+ {%- if m.content is string -%}
67
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
68
+ {{- '<|observation|>' }}
69
+ {%- endif %}
70
+ {{- '<tool_response>' }}
71
+ {{- m.content }}
72
+ {{- '</tool_response>' }}
73
+ {%- else -%}
74
+ <|observation|>{% for tr in m.content %}
75
+ <tool_response>{{ tr.output if tr.output is defined else tr }}</tool_response>{% endfor -%}
76
+ {% endif -%}
77
+ {%- elif m.role == 'system' -%}
78
+ <|system|>{{ visible_text(m.content) }}
79
+ {%- endif -%}
80
+ {%- endfor -%}
81
+ {%- if add_generation_prompt -%}
82
+ <|assistant|>{{- '</think>' if (enable_thinking is defined and not enable_thinking) else '<think>' -}}
83
+ {%- endif -%