qingy2024 commited on
Commit
23f36bb
·
verified ·
1 Parent(s): f2f0452

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +62 -0
chat_template.jinja ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if not add_generation_prompt is defined -%}
2
+ {%- set add_generation_prompt = false -%}
3
+ {%- endif -%}
4
+ {%- set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt="") -%}
5
+ {%- for message in messages -%}
6
+ {%- if message["role"] == "system" -%}
7
+ {%- set ns.system_prompt = message["content"] -%}
8
+ {%- endif -%}
9
+ {%- endfor -%}
10
+ {{- bos_token -}}
11
+ {{- ns.system_prompt -}}
12
+ {%- for message in messages -%}
13
+ {%- if message["role"] == "user" -%}
14
+ {%- set ns.is_tool = false -%}
15
+ {{- "<|User|>" + message["content"] -}}
16
+ {%- endif -%}
17
+
18
+ {%- if message["role"] == "assistant" and message["content"] is none -%}
19
+ {%- set ns.is_tool = false -%}
20
+ {%- for tool in message["tool_calls"] -%}
21
+ {%- if not ns.is_first -%}
22
+ {{- "<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
23
+ {%- set ns.is_first = true -%}
24
+ {%- else -%}
25
+ {{- "\n" + "<|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
26
+ {{- "<|tool▁calls▁end|><|end▁of▁sentence|>" -}}
27
+ {%- endif -%}
28
+ {%- endfor -%}
29
+ {%- endif -%}
30
+
31
+ {%- if message["role"] == "assistant" and message["content"] is not none -%}
32
+ {%- if ns.is_tool -%}
33
+ {{- "<|tool▁outputs▁end|>" + message["content"] + "<|end▁of▁sentence|>" -}}
34
+ {%- set ns.is_tool = false -%}
35
+ {%- else -%}
36
+ {%- set content = message["content"] -%}
37
+ {% generation %}
38
+ {{- "<|Assistant|>" + content + "<|end▁of▁sentence|>" -}}
39
+ {% endgeneration %}
40
+ {%- endif -%}
41
+ {%- endif -%}
42
+
43
+ {%- if message["role"] == "tool" -%}
44
+ {%- set ns.is_tool = true -%}
45
+ {%- if ns.is_output_first -%}
46
+ {{- "<|tool▁outputs▁begin|><|tool▁output▁begin|>" + message["content"] + "<|tool▁output▁end|>" -}}
47
+ {%- set ns.is_output_first = false -%}
48
+ {%- else -%}
49
+ {{- "\n<|tool▁output▁begin|>" + message["content"] + "<|tool▁output▁end|>" -}}
50
+ {%- endif -%}
51
+ {%- endif -%}
52
+ {%- endfor -%}
53
+
54
+ {%- if ns.is_tool -%}
55
+ {{- "<|tool▁outputs▁end|>" -}}
56
+ {%- endif -%}
57
+
58
+ {%- if add_generation_prompt and not ns.is_tool -%}
59
+ {% generation %}
60
+ {{- "<|Assistant|><think>\n" -}}
61
+ {% endgeneration %}
62
+ {%- endif -%}