subsectmusic commited on
Commit
076f21c
·
verified ·
1 Parent(s): f499927

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +107 -0
chat_template.jinja ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% if 'role' in messages[0] %}{%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %} {{- '<|im_start|>user' }}
42
+ {%- endif %}
43
+ {{- '\n<tool_response>\n' }}
44
+ {{- message.content }}
45
+ {{- '\n</tool_response>' }}
46
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
47
+ {{- '<|im_end|>\n' }}
48
+ {%- endif %}
49
+ {%- endif %}
50
+ {%- endfor %}
51
+ {%- if add_generation_prompt %}
52
+ {{- '<|im_start|>assistant\n' }}
53
+ {%- endif %}
54
+ {% else %}{%- if tools %}
55
+ {{- '<|im_start|>system\n' }}
56
+ {%- if messages[0]['from'] == 'system' %}
57
+ {{- messages[0]['value'] }}
58
+ {%- else %}
59
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
60
+ {%- endif %}
61
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
62
+ {%- for tool in tools %}
63
+ {{- "\n" }}
64
+ {{- tool | tojson }}
65
+ {%- endfor %}
66
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
67
+ {%- else %}
68
+ {%- if messages[0]['from'] == 'system' %}
69
+ {{- '<|im_start|>system\n' + messages[0]['value'] + '<|im_end|>\n' }}
70
+ {%- else %}
71
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
72
+ {%- endif %}
73
+ {%- endif %}
74
+ {%- for message in messages %}
75
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
76
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
77
+ {%- elif message.role == "assistant" %}
78
+ {{- '<|im_start|>' + message.role }}
79
+ {%- if message.content %}
80
+ {{- '\n' + message.content }}
81
+ {%- endif %}
82
+ {%- for tool_call in message.tool_calls %}
83
+ {%- if tool_call.function is defined %}
84
+ {%- set tool_call = tool_call.function %}
85
+ {%- endif %}
86
+ {{- '\n<tool_call>\n{"name": "' }}
87
+ {{- tool_call.name }}
88
+ {{- '", "arguments": ' }}
89
+ {{- tool_call.arguments | tojson }}
90
+ {{- '}\n</tool_call>' }}
91
+ {%- endfor %}
92
+ {{- '<|im_end|>\n' }}
93
+ {%- elif message.role == "tool" %}
94
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %} {{- '<|im_start|>user' }}
95
+ {%- endif %}
96
+ {{- '\n<tool_response>\n' }}
97
+ {{- message.content }}
98
+ {{- '\n</tool_response>' }}
99
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
100
+ {{- '<|im_end|>\n' }}
101
+ {%- endif %}
102
+ {%- endif %}
103
+ {%- endfor %}
104
+ {%- if add_generation_prompt %}
105
+ {{- '<|im_start|>assistant\n' }}
106
+ {%- endif %}
107
+ {% endif %}