HangHor commited on
Commit
4c62fa4
·
verified ·
1 Parent(s): 068d66b

Upload chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +92 -0
chat_template.jinja ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="", is_first_sp=true, is_last_user=false) -%}
5
+ {%- for message in messages -%}
6
+ {%- if message["role"] == "system" -%}
7
+ {%- if ns.is_first_sp -%}
8
+ {%- set ns.system_prompt = ns.system_prompt + message["content"] -%}
9
+ {%- set ns.is_first_sp = false -%}
10
+ {%- else -%}
11
+ {%- set ns.system_prompt = ns.system_prompt + "
12
+
13
+ " + message["content"] -%}
14
+ {%- endif -%}
15
+ {%- endif -%}
16
+ {%- endfor -%}
17
+ {{- bos_token -}}
18
+ {{- ns.system_prompt -}}
19
+ {%- for message in messages -%}
20
+ {%- set content = message["content"] -%}
21
+ {%- if message["role"] == "user" -%}
22
+ {%- set ns.is_tool = false -%}
23
+ {%- set ns.is_first = false -%}
24
+ {%- set ns.is_last_user = true -%}
25
+ {{- "<|User|>" + content -}}
26
+ {%- endif -%}
27
+ {%- if message["role"] == "assistant" -%}
28
+ {%- if "</think>" in content -%}
29
+ {%- set content = content.split("</think>")[-1] -%}
30
+ {%- endif -%}
31
+ {{- "<|assistant|>" -}}
32
+ {%- endif -%}
33
+ {%- if message["role"] == "assistant" and message["tool_calls"] is defined and message["tool_calls"] is not none -%}
34
+ {%- set ns.is_last_user = false -%}
35
+ {%- if ns.is_tool -%}
36
+ {{- "<|tool▁outputs▁end|>" -}}
37
+ {%- endif -%}
38
+ {%- set ns.is_first = false -%}
39
+ {%- set ns.is_tool = false -%}
40
+ {%- set ns.is_output_first = true -%}
41
+ {%- for tool in message["tool_calls"] -%}
42
+ {%- if not ns.is_first -%}
43
+ {%- if content is none -%}
44
+ {{- "<|tool▁calls▁begin|><|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "
45
+ " + "```json" + "
46
+ " + tool["function"]["arguments"] + "
47
+ " + "```" + "<|tool▁call▁end|>" -}}
48
+ {%- else -%}
49
+ {{- content + "<|tool▁calls▁begin|><|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "
50
+ " + "```json" + "
51
+ " + tool["function"]["arguments"] + "
52
+ " + "```" + "<|tool▁call▁end|>" -}}
53
+ {%- endif -%}
54
+ {%- set ns.is_first = true -%}
55
+ {%- else -%}
56
+ {{- "
57
+ " + "<|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "
58
+ " + "```json" + "
59
+ " + tool["function"]["arguments"] + "
60
+ " + "```" + "<|tool▁call▁end|>" -}}
61
+ {%- endif -%}
62
+ {%- endfor -%}
63
+ {{- "<|tool▁calls▁end|><|end▁of▁sentence|>" -}}
64
+ {%- endif -%}
65
+ {%- if message["role"] == "assistant" and (message["tool_calls"] is not defined or message["tool_calls"] is none) -%}
66
+ {%- set ns.is_last_user = false -%}
67
+ {%- if ns.is_tool -%}
68
+ {{- "<|tool▁outputs▁end|>" + content + "<|end▁of▁sentence|>" -}}
69
+ {%- set ns.is_tool = false -%}
70
+ {%- else -%}
71
+ {{- content + "<|end▁of▁sentence|>" -}}
72
+ {%- endif -%}
73
+ {%- endif -%}
74
+ {%- if message["role"] == "tool" -%}
75
+ {%- set ns.is_last_user = false -%}
76
+ {%- set ns.is_tool = true -%}
77
+ {%- if ns.is_output_first -%}
78
+ {{- "<|tool▁outputs▁begin|><|tool▁output▁begin|>" + content + "<|tool▁output▁end|>" -}}
79
+ {%- set ns.is_output_first = false -%}
80
+ {%- else -%}
81
+ {{- "
82
+ <|tool▁output▁begin|>" + content + "<|tool▁output▁end|>" -}}
83
+ {%- endif -%}
84
+ {%- endif -%}
85
+ {%- endfor -%}
86
+ {%- if ns.is_tool -%}
87
+ {{- "<|tool▁outputs▁end|>" -}}
88
+ {%- endif -%}
89
+ {%- if add_generation_prompt and ns.is_last_user and not ns.is_tool -%}
90
+ {{- "<|Assistant|>" -}}
91
+ {%- endif -%}
92
+