inferencerlabs commited on
Commit
ade0ce9
·
verified ·
1 Parent(s): 1ffa2d5

Upload complete model

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