{%- for message in messages -%}
    {{'<|im_start|>' + message['role'] + '\n'}}
    {%- if message['content'] is string -%}
        {{ message['content'] }}
    {%- elif message['content'] is iterable -%}
        {%- for item in message['content'] -%}
            {%- if item['type'].startswith('image') -%}
                {{ '<IMG_CONTEXT>\n' }}
            {%- elif item['type'] == 'video' -%}
                {{ raise_exception('Video data are not yet supported by Oumi for this model.') }}
            {%- elif item['type'] == 'text' -%}
                {{ item['text'] if 'text' in item else item['content'] }}
            {%- endif -%}
        {%- endfor -%}
    {%- endif -%}

    {{'<|im_end|>\n'}}
{%- endfor -%}

{%- if add_generation_prompt -%}
    {{'<|im_start|>assistant\n' }}
{%- endif -%}
