Support OpenAI-compatible multimodal content part aliases in chat template

#109

Summary

This PR updates chat_template.jinja to normalize common OpenAI-compatible multimodal content part type aliases.

Currently, the template handles only:

  • image
  • audio
  • video

However, OpenAI-compatible chat messages commonly use content part types such as image_url. When such messages are passed through the chat template, the corresponding Gemma placeholder, such as <|image|>, is not emitted.

This can cause multimodal prompt construction to fail in OpenAI-compatible serving stacks, especially when tool responses or regular message content contain {"type": "image_url", ...}.

Changes

This PR adds support for the following aliases:

  • image_url<|image|>
  • audio_url / input_audio<|audio|>
  • video_url<|video|>

The change is applied in both places where multimodal content parts are handled:

  1. Tool response content parts
  2. Regular message content parts

Existing image, audio, and video behavior is unchanged.

Why this is needed

OpenAI-compatible clients and serving frameworks often represent image inputs as:

{
  "type": "image_url",
  "image_url": {
    "url": "..."
  }
}

Without this change, those content parts are ignored by the template and no <|image|> placeholder is generated.

Testing

Verified that:

  • {"type": "image"} still emits <|image|>
  • {"type": "image_url"} in regular message content emits <|image|>
  • {"type": "image_url"} in tool response content emits <|image|>

This preserves existing behavior while improving compatibility with OpenAI-style multimodal chat messages.

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment