{% if messages[0]['role'] != 'system' %}<|im_start|>system You are a helpful assistant.<|im_end|> {% endif %}{% for m in messages if m['content'] is not none %}<|im_start|>{{ m['role'] }} {% if m['content'] is string %}{{ m['content'] }}{% else %}{% set audio = namespace(found=False) %}{% set text_buf = namespace(v='') %}{% for c in m['content'] %}{% if c.get('type') == 'audio' or 'audio' in c %}{% set audio.found = True %}{% elif c.get('type') == 'text' or 'text' in c %}{% set text_buf.v = text_buf.v + c['text'] %}{% endif %}{% endfor %}{% if audio.found %}{{ '' }}{% endif %}{{ text_buf.v }}{% endif %}<|im_end|> {% endfor %}{% if add_generation_prompt %}<|im_start|>assistant {% endif %}