mconcat commited on
Commit
b276be9
·
verified ·
1 Parent(s): 9ef68c3

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +117 -0
chat_template.jinja ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gMASK]<sop>
2
+ {%- if tools -%}
3
+ {%- macro tool_to_json(tool) -%}
4
+ {%- set ns_tool = namespace(first=true) -%}
5
+ {{ '{' -}}
6
+ {%- for k, v in tool.items() -%}
7
+ {%- if k != 'defer_loading' and k != 'strict' -%}
8
+ {%- if not ns_tool.first -%}{{- ', ' -}}{%- endif -%}
9
+ {%- set ns_tool.first = false -%}
10
+ "{{ k }}": {{ v | tojson(ensure_ascii=False) }}
11
+ {%- endif -%}
12
+ {%- endfor -%}
13
+ {{- '}' -}}
14
+ {%- endmacro -%}
15
+ <|system|>
16
+ # Tools
17
+
18
+ You may call one or more functions to assist with the user query.
19
+
20
+ You are provided with function signatures within <tools></tools> XML tags:
21
+ <tools>
22
+ {% for tool in tools %}
23
+ {%- if 'function' in tool -%}
24
+ {%- set tool = tool['function'] -%}
25
+ {%- endif -%}
26
+ {% if tool.defer_loading is not defined or not tool.defer_loading %}
27
+ {{ tool_to_json(tool) }}
28
+ {% endif %}
29
+ {% endfor %}
30
+ </tools>
31
+
32
+ For each function call, output the function name and arguments within the following XML format:
33
+ <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 -%}
34
+ {%- macro visible_text(content) -%}
35
+ {%- if content is string -%}
36
+ {{- content }}
37
+ {%- elif content is iterable and content is not mapping -%}
38
+ {%- for item in content -%}
39
+ {%- if item is mapping and item.type == 'text' -%}
40
+ {{- item.text }}
41
+ {%- elif item is string -%}
42
+ {{- item }}
43
+ {%- endif -%}
44
+ {%- endfor -%}
45
+ {%- else -%}
46
+ {{- content }}
47
+ {%- endif -%}
48
+ {%- endmacro -%}
49
+ {%- set ns = namespace(last_user_index=-1, thinking_indices='') -%}
50
+ {%- for m in messages %}
51
+ {%- if m.role == 'user' %}
52
+ {%- set ns.last_user_index = loop.index0 -%}
53
+ {%- elif m.role == 'assistant' %}
54
+ {%- if m.reasoning_content is string %}
55
+ {%- set ns.thinking_indices = ns.thinking_indices ~ ',' ~ ns.last_user_index ~ ',' -%}
56
+ {%- endif %}
57
+ {%- endif %}
58
+ {%- endfor %}
59
+ {%- set ns.has_thinking = false -%}
60
+ {%- for m in messages -%}
61
+ {%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}{% set ns.has_thinking = (',' ~ loop.index0 ~ ',') in ns.thinking_indices -%}
62
+ {%- elif m.role == 'assistant' -%}
63
+ <|assistant|>
64
+ {%- set content = visible_text(m.content) %}
65
+ {%- if m.reasoning_content is string %}
66
+ {%- set reasoning_content = m.reasoning_content %}
67
+ {%- elif '</think>' in content %}
68
+ {%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] %}
69
+ {%- set content = content.split('</think>')[-1] %}
70
+ {%- elif loop.index0 > ns.last_user_index and not (enable_thinking is defined and not enable_thinking) %}
71
+ {%- set reasoning_content = '' %}
72
+ {%- elif loop.index0 < ns.last_user_index and ns.has_thinking %}
73
+ {%- set reasoning_content = '' %}
74
+ {%- endif %}
75
+ {%- if ((clear_thinking is defined and not clear_thinking) or loop.index0 > ns.last_user_index) and reasoning_content is defined -%}
76
+ {{ '<think>' + reasoning_content + '</think>'}}
77
+ {%- else -%}
78
+ {{ '</think>' }}
79
+ {%- endif -%}
80
+ {%- if content.strip() -%}
81
+ {{ content.strip() }}
82
+ {%- endif -%}
83
+ {% if m.tool_calls %}
84
+ {% for tc in m.tool_calls %}
85
+ {%- if tc.function %}
86
+ {%- set tc = tc.function %}
87
+ {%- endif %}
88
+ {{- '<tool_call>' + tc.name -}}
89
+ {% 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 %}
90
+ {% endif %}
91
+ {%- elif m.role == 'tool' -%}
92
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
93
+ {{- '<|observation|>' -}}
94
+ {%- endif %}
95
+ {%- if m.content is string -%}
96
+ {{- '<tool_response>' + m.content + '</tool_response>' -}}
97
+ {%- else -%}
98
+ {{- '<tool_response><tools>\n' -}}
99
+ {% for tr in m.content %}
100
+ {%- for tool in tools -%}
101
+ {%- if 'function' in tool -%}
102
+ {%- set tool = tool['function'] -%}
103
+ {%- endif -%}
104
+ {%- if tool.name == tr.name -%}
105
+ {{- tool_to_json(tool) + '\n' -}}
106
+ {%- endif -%}
107
+ {%- endfor -%}
108
+ {%- endfor -%}
109
+ {{- '</tools></tool_response>' -}}
110
+ {% endif -%}
111
+ {%- elif m.role == 'system' -%}
112
+ <|system|>{{ visible_text(m.content) }}
113
+ {%- endif -%}
114
+ {%- endfor -%}
115
+ {%- if add_generation_prompt -%}
116
+ <|assistant|>{{- '</think>' if (enable_thinking is defined and not enable_thinking) else '<think>' -}}
117
+ {%- endif -%}