alexgusevski commited on
Commit
048c520
·
verified ·
1 Parent(s): 3069d50

Upload chat_template.jinja with huggingface_hub

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