upmodel-lwx commited on
Commit
644bf4a
·
verified ·
1 Parent(s): 7bb1ff7

Upload chat_template.jinja with huggingface_hub

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