zhoukz commited on
Commit
2ba191b
·
unverified ·
1 Parent(s): aababcf

Fix chat template

Browse files
Files changed (1) hide show
  1. chat_template.jinja +25 -7
chat_template.jinja CHANGED
@@ -1,7 +1,25 @@
1
- {% set audio_count = namespace(value=0) %}{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system
2
- You are a helpful assistant.<|im_end|>
3
- {% endif %}<|im_start|>{{ message['role'] }}
4
- {% if message['content'] is string %}{{ message['content'] }}<|im_end|>
5
- {% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_bos|><|IMAGE|><|vision_eos|>{% elif content['type'] == 'audio' or 'audio' in content or 'audio_url' in content %}{% set audio_count.value = audio_count.value + 1 %}{% if add_audio_id %}Audio {{ audio_count.value }}: {% endif %}<|audio_bos|><|AUDIO|><|audio_eos|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_bos|><|VIDEO|><|vision_eos|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>
6
- {% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant
7
- {% endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- for message in messages -%}
2
+ {%- if loop.first and message["role"] != "system" -%}
3
+ {{- "<|im_start|>system\nYou are Qwen, a virtual human developed by the Qwen Team, Alibaba Group, capable of perceiving auditory and visual inputs, as well as generating text and speech.<|im_end|>\n" -}}
4
+ {%- endif -%}
5
+ {{- "<|im_start|>" -}}
6
+ {{- message["role"] -}}
7
+ {{- "\n" -}}
8
+ {%- if message["content"] is string -%}
9
+ {{- message["content"] -}}
10
+ {%- else -%}
11
+ {%- for content in message["content"] -%}
12
+ {%- if content["type"] == "text" -%}
13
+ {{- content["text"] -}}
14
+ {%- elif content["type"] == "audio" -%}
15
+ {{- "<|audio_bos|><|AUDIO|><|audio_eos|>" -}}
16
+ {%- endif -%}
17
+ {%- endfor -%}
18
+ {%- endif -%}
19
+ {%- if not loop.last or loop.last and not continue_final_message -%}
20
+ {{- "<|im_end|>\n" -}}
21
+ {%- endif -%}
22
+ {%- endfor -%}
23
+ {%- if add_generation_prompt -%}
24
+ {{- "<|im_start|>assistant\n" -}}
25
+ {%- endif -%}