Daizee commited on
Commit
56dfb07
·
verified ·
1 Parent(s): 6212924

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +36 -32
chat_template.jinja CHANGED
@@ -1,34 +1,38 @@
1
- {{ bos_token }}
2
- {%- set loop_messages = messages -%}
3
- {%- for message in loop_messages -%}
4
- {%- if message['role'] == 'system' -%}
5
- {%- set role = 'user' -%}
6
- {%- elif message['role'] == 'assistant' -%}
7
- {%- set role = 'model' -%}
8
- {%- else -%}
9
- {%- set role = message['role'] -%}
10
- {%- endif -%}
11
-
12
- {%- if (role == 'user') != (loop.index0 % 2 == 0) -%}
13
- {{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
14
- {%- endif -%}
15
-
16
- {{ '<start_of_turn>' + role + '\n' }}
17
- {%- if message['content'] is string -%}
18
- {{ message['content'] | trim }}
19
- {%- elif message['content'] is iterable -%}
20
- {%- for item in message['content'] -%}
21
- {%- if item['type'] == 'image' -%}
22
- {{ '<start_of_image>' }}
23
- {%- elif item['type'] == 'text' -%}
24
- {{ item['text'] | trim }}
25
- {%- endif -%}
26
- {%- endfor -%}
27
- {%- else -%}
28
- {{ raise_exception("Invalid content type") }}
29
- {%- endif -%}
30
- {{ '<end_of_turn>\n' }}
31
  {%- endfor -%}
32
- {%- if add_generation_prompt -%}
33
- {{'<start_of_turn>model\n'}}
34
  {%- endif -%}
 
 
 
 
 
 
 
 
 
1
+ {%- for m in messages -%}
2
+ {%- if m.role == "system" -%}
3
+ <start_of_turn>user
4
+ {%- set c = m.content -%}
5
+ {%- if c is string -%}
6
+ {{ c }}
7
+ {%- else -%}
8
+ {%- for it in c -%}
9
+ {%- if it.type == "image" -%}
10
+ <start_of_image>
11
+ {%- elif it.type == "text" -%}
12
+ {{ it.text }}
13
+ {%- endif -%}
14
+ {%- endfor -%}
15
+ {%- endif -%}
16
+ <end_of_turn>
17
+ {%- elif m.role == "user" -%}
18
+ <start_of_turn>user
19
+ {%- set c = m.content -%}
20
+ {%- if c is string -%}
21
+ {{ c }}
22
+ {%- else -%}
23
+ {%- for it in c -%}
24
+ {%- if it.type == "image" -%}
25
+ <start_of_image>
26
+ {%- elif it.type == "text" -%}
27
+ {{ it.text }}
28
+ {%- endif -%}
 
 
29
  {%- endfor -%}
 
 
30
  {%- endif -%}
31
+ <end_of_turn>
32
+ {%- elif m.role == "assistant" -%}
33
+ <start_of_turn>model
34
+ {{ m.content }}
35
+ <end_of_turn>
36
+ {%- endif -%}
37
+ {%- endfor -%}
38
+ <start_of_turn>model