jelegend commited on
Commit
8f232d6
·
verified ·
1 Parent(s): ae1a48c

Upload chat_template.jinja

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