{ "chat_template": "\n{% set image_token = '' %} {# Standard PaliGemma image token #}\n{% for message in messages %}\n {%- if message['role'] == 'user' -%}\n {{ 'user\n' }}\n {#- Check if there are image content parts -#}\n {%- set has_images = message['content'] | selectattr('type', 'equalto', 'image') | list | length > 0 %}\n {#- Extract text content -#}\n {%- set text_content = message['content'] | selectattr('type', 'equalto', 'text') | map(attribute='text') | join(' ') %}\n\n {#- If images exist, typically place the image token(s) first, followed by a newline #}\n {{ image_token + '\n' }} {# Add the image placeholder token #}\n {{- text_content -}} {# Add the text content #}\n\n {%- elif message['role'] == 'assistant' or message['role'] == 'model' -%}\n {{ 'model\n' }}\n {#- Extract text content for the model's response -#}\n {%- set text_content = message['content'] | selectattr('type', 'equalto', 'text') | map(attribute='text') | join(' ') %}\n {{- text_content -}}\n\n {%- else -%}\n {# Optional: Handle unexpected roles, maybe just print role and content #}\n {{ message['role'] + '\n' }}\n {%- for content in message['content'] -%}\n {%- if content['type'] == 'text' %}{{ content['text'] }}{% endif -%}\n {%- if content['type'] == 'image' %}{{ image_token }}{% endif -%}\n {%- endfor -%}\n {%- endif -%}\n {{ '\n' }} {# Add a newline to separate turns #}\n{% endfor %}\n{%- if add_generation_prompt %}\n {{ 'model\n' }} {# Prompt for the model to generate its response #}\n{% endif %}\n" }