McG-221 commited on
Commit
1dfea53
·
verified ·
1 Parent(s): d38feaa

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +108 -0
chat_template.jinja ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {{- bos_token }}
2
+ {%- if custom_tools is defined %}
3
+ {%- set tools = custom_tools %}
4
+ {%- endif %}
5
+ {%- if not tools_in_user_message is defined %}
6
+ {%- set tools_in_user_message = true %}
7
+ {%- endif %}
8
+ {%- if not date_string is defined %}
9
+ {%- set date_string = "26 Jul 2024" %}
10
+ {%- endif %}
11
+ {%- if not tools is defined %}
12
+ {%- set tools = none %}
13
+ {%- endif %}
14
+
15
+ {#- This block extracts the system message, so we can slot it into the right place. #}
16
+ {%- if messages[0]['role'] == 'system' %}
17
+ {%- set system_message = messages[0]['content']|trim %}
18
+ {%- set messages = messages[1:] %}
19
+ {%- else %}
20
+ {%- set system_message = "" %}
21
+ {%- endif %}
22
+
23
+ {#- System message + builtin tools #}
24
+ {{- "<|start_header_id|>system<|end_header_id|>\n\n" }}
25
+ {%- if builtin_tools is defined or tools is not none %}
26
+ {{- "Environment: ipython\n" }}
27
+ {%- endif %}
28
+ {%- if builtin_tools is defined %}
29
+ {{- "Tools: " + builtin_tools | reject('equalto', 'code_interpreter') | join(", ") + "\n\n"}}
30
+ {%- endif %}
31
+
32
+ {%- if tools is not none and not tools_in_user_message %}
33
+ {{- "You have access to the following functions. To call a function, please respond with JSON for a function call." }}
34
+ {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
35
+ {{- "Do not use variables.\n\n" }}
36
+ {%- for t in tools %}
37
+ {{- t | tojson(indent=4) }}
38
+ {{- "\n\n" }}
39
+ {%- endfor %}
40
+ {%- endif %}
41
+ {{- system_message }}
42
+ {{- "<|eot_id|>" }}
43
+
44
+ {#- Custom tools are passed in a user message with some extra guidance #}
45
+ {%- if tools_in_user_message and not tools is none %}
46
+ {#- Extract the first user message so we can plug it in here #}
47
+ {%- if messages | length != 0 %}
48
+ {%- set first_user_message = messages[0]['content']|trim %}
49
+ {%- set messages = messages[1:] %}
50
+ {%- else %}
51
+ {{- raise_exception("Cannot put tools in the first user message when there's no first user message!") }}
52
+ {%- endif %}
53
+ {{- '<|start_header_id|>user<|end_header_id|>\n\n' -}}
54
+ {{- "Given the following functions, please respond with a JSON for a function call " }}
55
+ {{- "with its proper arguments that best answers the given prompt.\n\n" }}
56
+ {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
57
+ {{- "Do not use variables.\n\n" }}
58
+ {%- for t in tools %}
59
+ {{- t | tojson(indent=4) }}
60
+ {{- "\n\n" }}
61
+ {%- endfor %}
62
+ {{- first_user_message + "<|eot_id|>"}}
63
+ {%- endif %}
64
+
65
+ {%- for message in messages %}
66
+ {%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %}
67
+ {{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' }}
68
+ {%- elif 'tool_calls' in message %}
69
+ {%- if not message.tool_calls|length == 1 %}
70
+ {{- raise_exception("This model only supports single tool-calls at once!") }}
71
+ {%- endif %}
72
+ {%- set tool_call = message.tool_calls[0].function %}
73
+ {%- if builtin_tools is defined and tool_call.name in builtin_tools %}
74
+ {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
75
+ {{- "<|python_tag|>" + tool_call.name + ".call(" }}
76
+ {%- for arg_name, arg_val in tool_call.arguments | items %}
77
+ {{- arg_name + '="' + arg_val + '"' }}
78
+ {%- if not loop.last %}
79
+ {{- ", " }}
80
+ {%- endif %}
81
+ {%- endfor %}
82
+ {{- ")" }}
83
+ {%- else %}
84
+ {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
85
+ {{- '{"name": "' + tool_call.name + '", ' }}
86
+ {{- '"parameters": ' }}
87
+ {{- tool_call.arguments | tojson }}
88
+ {{- "}" }}
89
+ {%- endif %}
90
+ {%- if builtin_tools is defined %}
91
+ {#- This means we're in ipython mode #}
92
+ {{- "<|eom_id|>" }}
93
+ {%- else %}
94
+ {{- "<|eot_id|>" }}
95
+ {%- endif %}
96
+ {%- elif message.role == "tool" or message.role == "ipython" %}
97
+ {{- "<|start_header_id|>ipython<|end_header_id|>\n\n" }}
98
+ {%- if message.content is mapping or message.content is iterable %}
99
+ {{- message.content | tojson }}
100
+ {%- else %}
101
+ {{- message.content }}
102
+ {%- endif %}
103
+ {{- "<|eot_id|>" }}
104
+ {%- endif %}
105
+ {%- endfor %}
106
+ {%- if add_generation_prompt %}
107
+ {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
108
+ {%- endif %}