manaestras commited on
Commit
b343fa4
·
verified ·
1 Parent(s): 5e8c158

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +112 -0
chat_template.jinja ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% set loop_messages = messages %}
2
+ {% if tools %}
3
+ {% set weekday_map = {'Monday': '星期一', 'Tuesday': '星期二', 'Wednesday': '星期三', 'Thursday': '星期四', 'Friday': '星期五', 'Saturday': '星期六', 'Sunday': '星期日'} %}
4
+ {% set weekday_cn = weekday_map[strftime_now('%A')] %}
5
+ {% set datetime_str = strftime_now('%Y-%m-%d %H:%M:%S') %}
6
+ {% set datetime_str = datetime_str + ' ' + weekday_cn %}
7
+ {% for message in loop_messages %}
8
+ {% if 'content' in message %}
9
+ {% set content = message['content'] %}
10
+ {% else %}
11
+ {% set content = '' %}
12
+ {% endif %}
13
+ {% if loop.index0 == 0 %}
14
+ {% set content_tmp = '你是一位函数组合专家。你会得到一个问题和一组可能的函数。根据问题,你需要进行一个或多个函数/工具调用以实现目的。
15
+ 如果没有一个函数可以使用,请直接使用自然语言回复用户,以助手:开头。
16
+ 如果给定的问题缺少函数所需的参数,请使用自然语言进行提问,向用户询问必要信息,以助手:开头。
17
+ 如果调用结果已经足够回答用户问题,请对历史结果进行总结,使用自然语言回复用户,以助手:开头。
18
+ 你应该只在工具调用部分返回函数调用。如果你决定调用任何函数,你必须将其格式化为<tool_calls>[{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},...]</tool_calls>。你不应该在回复中包含任何其他文本。以下是你可以调用的函数列表,格式为JSON。
19
+ ' %}
20
+ {% set content_tmp = content_tmp + '
21
+ ' + tools | tojson + '
22
+ ' %}
23
+ {% if message['role'] == 'system' %}
24
+ {% set content_tmp = content_tmp + '
25
+ 额外要求:
26
+ ' + content + '
27
+
28
+ 如果你决定返回函数调用,请将其格式化为<tool_calls>[{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},...]</tool_calls>,不得包含其他文本。如果额外要求里有格式要求,请忽略,以此处为准。
29
+ 否则,请参考开头说的三种情况,以助手:开头进行回复。
30
+
31
+ 如果额外要求里有时间信息,就以额外要求里的时间为准,否则,参考当前时间:' + datetime_str %}
32
+ {% set content = '<|startoftext|>' + content_tmp + '<|extra_4|>' %}
33
+ {% elif message['role'] == 'user' %}
34
+ {% set content_tmp = content_tmp + '
35
+ 如果你决定返回函数调用,请将其格式化为<tool_calls>[{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},...]</tool_calls>,不得包含其他文本。
36
+ 否则,请参考开头说的三种情况,以助手:开头进行回复。
37
+
38
+ 当前时间:' + datetime_str %}
39
+ {% set content_tmp = '<|startoftext|>' + content_tmp + '<|extra_4|>'%}
40
+ {% set content = content_tmp + '用户:' + content + '<|extra_0|>' %}
41
+ {% endif %}
42
+ {% else %}
43
+ {% if message['role'] == 'user' %}
44
+ {% set content = '用户:' + content + '<|extra_0|>' %}
45
+ {% elif message['role'] == 'assistant' %}
46
+ {% if 'tool_calls' in message %}
47
+ {% set tool_calls = message['tool_calls'] %}
48
+ {% set ns = namespace(tool_calls="[") %}
49
+ {% for tool_call in tool_calls %}
50
+ {% set function = tool_call['function'] %}
51
+ {% set name = function['name'] %}
52
+ {% set ns.tool_calls = ns.tool_calls + '{"name": "' + name + '", '%}
53
+ {% set arguments = function['arguments'] %}
54
+ {% if arguments is not string %}
55
+ {% set arguments = arguments | tojson %}
56
+ {% endif %}
57
+ {% set ns.tool_calls = ns.tool_calls + '"arguments": ' + arguments + '}' %}
58
+ {% if not loop.last %}
59
+ {% set ns.tool_calls = ns.tool_calls + ', '%}
60
+ {% endif %}
61
+ {% endfor %}
62
+ {% set ns.tool_calls = ns.tool_calls + ']' %}
63
+ {% set content = content + '<tool_calls>' + ns.tool_calls + '</tool_calls>' %}
64
+ {% else %}
65
+ {% set content = '助手:' + content %}
66
+ {% endif %}
67
+ {% set content = content + '<|eos|>' %}
68
+ {% elif message['role'] == 'tool' %}
69
+ {% if content is not string %}
70
+ {set content = content | tojson }
71
+ {% endif %}
72
+ {% set content = '<tool_response>' + content + '</tool_response>' %}
73
+ {% set content = content + '<|extra_0|>' %}
74
+ {% endif %}
75
+ {% endif %}
76
+ {{- content -}}
77
+ {% endfor %}
78
+ {% else %}
79
+ {% set context = {'has_head': true} %}
80
+ {% for message in loop_messages %}
81
+ {% if 'content' in message %}
82
+ {% set content = message['content'] %}
83
+ {% else %}
84
+ {% set content = '' %}
85
+ {% endif %}
86
+ {% if loop.index0 == 0 %}
87
+ {% if content == '' %}
88
+ {% set _ = context.update({'has_head': false}) %}
89
+ {% elif message['role'] == 'system' %}
90
+ {% set content = '<|startoftext|>' + content + '<|extra_4|>' %}
91
+ {% endif %}
92
+ {% endif %}
93
+ {% if message['role'] == 'user' %}
94
+ {% if loop.index0 == 1 and not context.has_head %}
95
+ {% set content = '<|startoftext|>' + content %}
96
+ {% endif %}
97
+ {% if loop.index0 == 1 and context.has_head %}
98
+ {% set content = content + '<|extra_0|>' %}
99
+ {% else %}
100
+ {% set content = '<|startoftext|>' + content + '<|extra_0|>' %}
101
+ {% endif %}
102
+ {% elif message['role'] == 'assistant' %}
103
+ {% set content = content + '<|eos|>' %}
104
+ {% elif message['role'] == 'tool' %}
105
+ {% set content = content + '<|extra_0|>' %}
106
+ {% endif %}
107
+ {{- content -}}
108
+ {% endfor %}
109
+ {% endif %}
110
+ {%- if enable_thinking is defined and enable_thinking is false %}
111
+ {{- '<think>\n\n</think>\n' }}
112
+ {%- endif %}