jennyxue commited on
Commit
15bf10a
·
verified ·
1 Parent(s): a51835c

8bit: chat_template.jinja

Browse files
Files changed (1) hide show
  1. 8bit/chat_template.jinja +61 -0
8bit/chat_template.jinja ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- macro flint_text(t) -%}
2
+ {%- if t is string -%}
3
+ {{- t | replace("\x00", "") | replace("<think>", "") | replace("</think>", "") | replace("<|begin_of_text|>", "&lt;|begin_of_text|&gt;") | replace("<|end_of_text|>", "&lt;|end_of_text|&gt;") | replace("<|system|>", "&lt;|system|&gt;") | replace("<|developer|>", "&lt;|developer|&gt;") | replace("<|user|>", "&lt;|user|&gt;") | replace("<|assistant|>", "&lt;|assistant|&gt;") | replace("<|observation|>", "&lt;|observation|&gt;") -}}
4
+ {%- else -%}
5
+ {{- t -}}
6
+ {%- endif -%}
7
+ {%- endmacro -%}
8
+ {%- set tool_preamble -%}
9
+ {%- if tools %}<|system|>
10
+ # Tools
11
+
12
+ You may call one or more functions to assist with the user query.
13
+
14
+ You are provided with function signatures within <tools></tools> XML tags:
15
+ <tools>
16
+ {%- for tool in tools %}
17
+ {%- set fn = tool.function if tool.function is defined else tool %}
18
+ {{ fn | tojson(ensure_ascii=False) }}
19
+ {%- endfor %}
20
+ </tools>
21
+
22
+ For each function call, output the function name and arguments within the following XML format:
23
+ <tool_call>{function-name}<arg_key>{arg-key-1}</arg_key><arg_value>{arg-value-1}</arg_value>...</tool_call>
24
+ {% endif -%}
25
+ {%- endset -%}
26
+ {%- set ns = namespace(tools_pending=true) -%}
27
+ {%- for m in messages -%}
28
+ {%- if ns.tools_pending and m.role != 'system' -%}
29
+ {{ tool_preamble }}
30
+ {%- set ns.tools_pending = false -%}
31
+ {%- endif -%}
32
+ {%- if m.role == 'system' -%}
33
+ <|system|>{{ flint_text(m.content) }}
34
+ {%- elif m.role == 'developer' -%}
35
+ <|developer|>{{ flint_text(m.content) }}
36
+ {%- elif m.role == 'user' -%}
37
+ <|user|>{{ flint_text(m.content) }}
38
+ {%- elif m.role == 'assistant' -%}
39
+ <|assistant|>
40
+ {%- if m.reasoning_content %}<think>{{ m.reasoning_content }}</think>{% endif -%}
41
+ {%- if m.content %}{{ m.content }}{% endif -%}
42
+ {%- if m.tool_calls -%}
43
+ {%- for tc in m.tool_calls -%}
44
+ {%- set fn = tc.function if tc.function is defined else tc -%}
45
+ <tool_call>{{ fn.name }}
46
+ {%- for k, v in fn.arguments.items() -%}
47
+ <arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>
48
+ {%- endfor -%}
49
+ </tool_call>
50
+ {%- endfor -%}
51
+ {%- endif -%}
52
+ {%- elif m.role == 'tool' -%}
53
+ <|observation|><tool_response>{{ flint_text(m.content) }}</tool_response>
54
+ {%- endif -%}
55
+ {%- endfor -%}
56
+ {%- if ns.tools_pending -%}
57
+ {{ tool_preamble }}
58
+ {%- endif -%}
59
+ {%- if add_generation_prompt -%}
60
+ <|assistant|>
61
+ {%- endif -%}