Skip to content

Add WebP support for Google GenAI and Vertex AI#6526

Open
jialiuyang wants to merge 1 commit into
spring-projects:mainfrom
jialiuyang:feat/multimodality-webp-support
Open

Add WebP support for Google GenAI and Vertex AI#6526
jialiuyang wants to merge 1 commit into
spring-projects:mainfrom
jialiuyang:feat/multimodality-webp-support

Conversation

@jialiuyang

Copy link
Copy Markdown

Gemini chat models and Vertex AI Multimodal Embedding both accept image/webp inputs, but Spring AI rejected those payloads before they could reach the provider.

Problem

  • MimeTypeDetector (spring-ai-google-genai) registered only png, jpeg, jpg and gif, so any .webp URL/URI/File/Path/Resource/String passed to a Gemini chat client raised Unable to detect the MIME type. Its class javadoc also listed only image/gif, image/png and image/jpeg as supported, which contradicts the upstream Gemini model reference, which has accepted image/webp since 1.5.
  • VertexAiMultimodalEmbeddingModel allowed image/jpeg, image/gif, image/png and image/bmp, and rejected image/webp at SUPPORTED_IMAGE_MIME_SUB_TYPES, throwing Unsupported image mime type even though the Vertex multimodal embedding API supports WebP.

The use case in the linked issue - pre-processing media into WebP and then sending it to a multimodal model through Spring AI - therefore fails on the Spring AI side, not at the provider.

Changes

  • MimeTypeDetector: register webp ? image/webp and add image/webp to the supported-types list in the class javadoc.
  • MimeTypeDetectorTests: include WEBP in the uppercase-extension parameter set and test.webp in the cross-method consistency parameter set. The existing parameterized tests sourced from GEMINI_MIME_TYPES (URL, URI, File, Path, Resource, String) automatically cover the new mapping.
  • VertexAiMultimodalEmbeddingModel: add image/webp to SUPPORTED_IMAGE_MIME_SUB_TYPES.

No public API was added or changed; existing supported MIME types still behave exactly as before.

Testing

./mvnw -pl models/spring-ai-google-genai -am test - parameterized MimeTypeDetectorTests exercise URL/URI/File/Path/Resource/String detection for the new webp mapping. Integration tests against live Gemini/Vertex were not run.

Fixes #6474

Gemini chat models and Vertex AI Multimodal Embedding both accept
image/webp inputs, but Spring AI rejected them before they could
reach the provider:

* MimeTypeDetector registered only png, jpeg, jpg and gif, so any
  .webp resource passed to Gemini chat clients raised "Unable to
  detect the MIME type" during URL, URI, file or resource detection.
* VertexAiMultimodalEmbeddingModel rejected image/webp media at the
  SUPPORTED_IMAGE_MIME_SUB_TYPES check, throwing "Unsupported image
  mime type" before any embedding request was issued.

This adds image/webp to both code paths, updates the MimeTypeDetector
class javadoc, and extends the parameterized MimeTypeDetectorTests so
the new mapping is exercised through every detection entry point.

Fixes spring-projects#6474

Signed-off-by: jialiuyang <495120021@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add WebP image support for multimodality

2 participants