aleada commited on
Commit
ce17180
·
verified ·
1 Parent(s): 73b8874

Upload chat_template.jinja

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