ssdataanalysis commited on
Commit
b0b16a5
·
verified ·
1 Parent(s): c97d35c

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +66 -0
chat_template.jinja ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if bos_token is defined and bos_token is not none %}{{- bos_token -}}{%- endif %}
2
+ {%- if tools %}
3
+ {{- '<|im_start|>system\n' }}
4
+ {%- if messages|length > 0 and messages[0].role == 'system' %}
5
+ {{- messages[0].content + '\n\n' }}
6
+ {%- endif %}
7
+ {{- "# 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>" }}
8
+ {%- for tool in tools %}
9
+ {{- "\n" }}
10
+ {{- tool | tojson }}
11
+ {%- endfor %}
12
+ {{- "\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" }}
13
+ {%- else %}
14
+ {%- if messages|length > 0 and messages[0].role == 'system' %}
15
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
16
+ {%- endif %}
17
+ {%- endif %}
18
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
19
+ {%- for message in messages[::-1] %}
20
+ {%- set index = (messages|length - 1) - loop.index0 %}
21
+ {%- if ns.multi_step_tool and message.role == "user" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
22
+ {%- set ns.multi_step_tool = false %}
23
+ {%- set ns.last_query_index = index %}
24
+ {%- endif %}
25
+ {%- endfor %}
26
+ {%- for message in messages %}
27
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
28
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
29
+ {%- elif message.role == "assistant" %}
30
+ {%- set content = message.content %}
31
+ {{- '<|im_start|>' + message.role + '\n' + content }}
32
+ {%- if message.tool_calls %}
33
+ {%- for tool_call in message.tool_calls %}
34
+ {%- if (loop.first and content) or (not loop.first) %}
35
+ {{- '\n' }}
36
+ {%- endif %}
37
+ {%- if tool_call.function %}
38
+ {%- set tool_call = tool_call.function %}
39
+ {%- endif %}
40
+ {{- '<tool_call>\n{"name": "' }}
41
+ {{- tool_call.name }}
42
+ {{- '", "arguments": ' }}
43
+ {%- if tool_call.arguments is string %}
44
+ {{- tool_call.arguments }}
45
+ {%- else %}
46
+ {{- tool_call.arguments | tojson }}
47
+ {%- endif %}
48
+ {{- '}\n</tool_call>' }}
49
+ {%- endfor %}
50
+ {%- endif %}
51
+ {{- '<|im_end|>\n' }}
52
+ {%- elif message.role == "tool" %}
53
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
54
+ {{- '<|im_start|>user' }}
55
+ {%- endif %}
56
+ {{- '\n<tool_response>\n' }}
57
+ {{- message.content }}
58
+ {{- '\n</tool_response>' }}
59
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
60
+ {{- '<|im_end|>\n' }}
61
+ {%- endif %}
62
+ {%- endif %}
63
+ {%- endfor %}
64
+ {%- if add_generation_prompt %}
65
+ {{- '<|im_start|>assistant\n' }}
66
+ {%- endif -%}