Text Generation
Transformers
Safetensors
zaya
conversational
ganeshnanduru commited on
Commit
9ec1654
·
verified ·
1 Parent(s): de5f76a

Upload chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +45 -41
chat_template.jinja CHANGED
@@ -1,47 +1,51 @@
1
- {{ bos_token }}
2
- {%- if messages[0]['role'] == 'system' -%}
3
- {%- if messages[0]['content'] is string -%}
4
- {%- set first_user_prefix = messages[0]['content'] + '
5
 
6
- ' -%}
7
- {%- else -%}
8
- {%- set first_user_prefix = messages[0]['content'][0]['text'] + '
9
 
10
- ' -%}
 
 
 
 
11
  {%- endif -%}
12
- {%- set loop_messages = messages[1:] -%}
13
- {%- else -%}
14
- {%- set first_user_prefix = "" -%}
15
- {%- set loop_messages = messages -%}
 
 
 
 
 
 
 
 
 
 
 
 
16
  {%- endif -%}
17
- {%- for message in loop_messages -%}
18
- {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
19
- {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
20
- {%- endif -%}
21
- {%- if (message['role'] == 'assistant') -%}
22
- {%- set role = "model" -%}
23
- {%- else -%}
24
- {%- set role = message['role'] -%}
25
- {%- endif -%}
26
- {{ '<start_of_turn>' + role + '
27
- ' + (first_user_prefix if loop.first else "") }}
28
- {%- if message['content'] is string -%}
29
- {{ message['content'] | trim }}
30
- {%- elif message['content'] is iterable -%}
31
- {%- for item in message['content'] -%}
32
- {%- if item['type'] == 'image' -%}
33
- {{ '<start_of_image>' }}
34
- {%- elif item['type'] == 'text' -%}
35
- {{ item['text'] | trim }}
36
- {%- endif -%}
37
- {%- endfor -%}
38
- {%- else -%}
39
- {{ raise_exception("Invalid content type") }}
40
- {%- endif -%}
41
- {{ '<end_of_turn>
42
- ' }}
43
  {%- endfor -%}
 
44
  {%- if add_generation_prompt -%}
45
- {{'<start_of_turn>model
46
- '}}
47
- {%- endif -%}
 
1
+ {%- if messages[0].role == "system" -%}
2
+ {%- set system_message = messages[0].content -%}
3
+ {%- set custom_instructions = system_message.replace("/no_think", "").replace("/think", "").rstrip() -%}
4
+ {%- endif -%}
5
 
6
+ {%- if custom_instructions -%}
7
+ {{- custom_instructions + "\n\n" -}}
8
+ {%- endif -%}
9
 
10
+ {%- if xml_tools or python_tools or tools -%}
11
+ {{- "### Tools\n\n" -}}
12
+ {%- if xml_tools or tools -%}
13
+ {%- if tools -%}
14
+ {%- set xml_tools = tools -%}
15
  {%- endif -%}
16
+ {%- set ns = namespace(xml_tool_string="You may call one or more functions to assist with the user query.\nYou are provided with function signatures within <tools></tools> XML tags:\n\n<tools>\n") -%}
17
+ {%- for tool in xml_tools[:] -%} {# The slicing makes sure that xml_tools is a list #}
18
+ {%- set ns.xml_tool_string = ns.xml_tool_string ~ (tool | string) ~ "\n" -%}
19
+ {%- endfor -%}
20
+ {%- set xml_tool_string = ns.xml_tool_string + "</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>" -%}
21
+ {{- xml_tool_string -}}
22
+ {%- endif -%}
23
+ {%- if python_tools -%}
24
+ {%- set ns = namespace(python_tool_string="When you send a message containing Python code between '<code>' and '</code>' tags, it will be executed in a stateful Jupyter notebook environment, and you will then be given the output to continued reasoning in an agentic loop.\n\nYou can use the following tools in your python code like regular functions:\n<tools>\n") -%}
25
+ {%- for tool in python_tools[:] -%} {# The slicing makes sure that python_tools is a list #}
26
+ {%- set ns.python_tool_string = ns.python_tool_string ~ (tool | string) ~ "\n" -%}
27
+ {%- endfor -%}
28
+ {%- set python_tool_string = ns.python_tool_string + "</tools>\n\nThe state persists between code executions: so variables that you define in one step are still available thereafter." -%}
29
+ {{- python_tool_string -}}
30
+ {%- endif -%}
31
+ {{- "\n\n" -}}
32
  {%- endif -%}
33
+
34
+
35
+ {# ───── main loop ───── #}
36
+ {%- for message in messages -%}
37
+ {%- set content = message.content if message.content is string else "" -%}
38
+ {%- if message.role == "user" -%}
39
+ {{- message.role + ": " + content + "\n" -}}
40
+ {%- elif message.role == "assistant" -%}
41
+ {% generation %}
42
+ {{- "assistant: " + content.lstrip("\n") + "\n" -}}
43
+ {% endgeneration %}
44
+ {%- elif message.role == "tool" -%}
45
+ {{- "tool: " + content + "\n" -}}
46
+ {%- endif -%}
 
 
 
 
 
 
 
 
 
 
 
 
47
  {%- endfor -%}
48
+ {# ───── generation prompt ───── #}
49
  {%- if add_generation_prompt -%}
50
+ {{- "assistant: " -}}
51
+ {%- endif -%}