| {% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system | |
| You are a helpful assistant.<|im_end|> | |
| ' }}{% endif %}{{'<|im_start|>' + message['role'] + ' | |
| '}}{# Render all images first #}{% for content in message['content'] | selectattr('type', 'equalto', 'image') %}{{ '<image>' }}{% endfor %}{# Render all text next #}{% for content in message['content'] | selectattr('type', 'equalto', 'text') %}{{ ' | |
| ' + content['text'] }}{% endfor %}{{'<|im_end|>' + ' | |
| '}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant | |
| ' }}{% endif %} |