| {%- for message in messages -%} |
| {%- if loop.first and message["role"] != "system" -%} |
| {{- "<|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" -}} |
| {%- endif -%} |
| {{- "<|im_start|>" -}} |
| {{- message["role"] -}} |
| {{- "\n" -}} |
| {%- if message["content"] is string -%} |
| {{- message["content"] -}} |
| {%- else -%} |
| {%- for content in message["content"] -%} |
| {%- if content["type"] == "text" -%} |
| {{- content["text"] -}} |
| {%- elif content["type"] == "audio" -%} |
| {{- "<|audio_bos|><|AUDIO|><|audio_eos|>" -}} |
| {%- endif -%} |
| {%- endfor -%} |
| {%- endif -%} |
| {%- if not loop.last or loop.last and not continue_final_message -%} |
| {{- "<|im_end|>\n" -}} |
| {%- endif -%} |
| {%- endfor -%} |
| {%- if add_generation_prompt -%} |
| {{- "<|im_start|>assistant\n" -}} |
| {%- endif -%} |
| |