{% for message in messages %}
    {% if message['role'] == 'system' %}
        {{ '<|im_start|>system\n' + message['content'] + '<|im_end|>' }}
    {% elif message['role'] == 'user' %}
        {{ '\n<|im_start|>user\n' + message['content'] + '<|im_end|>' }}
    {% elif message['role'] == 'assistant' %}
        {{ '\n<|im_start|>assistant\n' + message['content'] + '<|im_end|>' }}
    {% endif %}
{% endfor %}
{% if add_generation_prompt %}
    {{ '\n<|im_start|>assistant\n' }}
{% else %}
    {{ '<|im_end|>' }}
{% endif %}
