[BUG] google-genai: generated images in chat responses are silently dropped
Describe the bug
Comparing the two Gemini modules, the new langchain4j-google-genai drops generated
images from chat responses. The older langchain4j-google-ai-gemini surfaces them.
GoogleGenAiContentMapper.toChatResponse handles part.text(), part.audioTranscription(),
part.functionCall() and part.thoughtSignature(). It never reads part.inlineData(). So an
image that arrives in a chat response never lands in AiMessage.attributes, and
AiMessage.images() stays empty.
That mapper is shared, so all three chat models in the module are affected:
GoogleGenAiChatModel(non-streaming)GoogleGenAiStreamingChatModel(streaming)GoogleGenAiBatchChatModel(batch)
The old module does handle it. PartsAndContentsMapper.fromGPartsToAiMessage() writes
inlineData into AiMessage.GENERATED_IMAGES_KEY (that came in with #3641), and
GeminiStreamingResponseBuilder merges that list across chunks rather than overwriting it
(#5972). The new module already reads inlineData in GoogleGenAiImageModel and
GoogleGenAiBatchImageModel, so it looks like only the chat path got missed in the migration.
One more thing on the same path: GoogleGenAiStreamingChatModel (around line 195) still calls
attributes.putAll(aiMessage.attributes()). That's the line #5972 replaced with a merge on the
old side. With putAll, a later chunk replaces whatever an earlier one put under the same key.
Log and Stack trace
Nothing to show. No exception, nothing in the logs. The images just aren't there.
To Reproduce
A unit test is the easy way, no API key needed. Call GoogleGenAiContentMapper.toChatResponse(...)
with a GenerateContentResponse that has an inlineData part among the candidate parts, then
check response.aiMessage().images(). PartsAndContentsMapperTest on the old side (from #3641)
shows how to build one of those responses.
End to end: stream a chat completion from an image-generation model
(gemini-2.5-flash-image). The response carries inlineData for the image, and images()
comes back empty.
Expected behavior
AiMessage.images() should return the image, the same way it does in
langchain4j-google-ai-gemini. The javadoc on that accessor says "At the moment it works for
Gemini only", which is what I'd expect from this module too.
Please complete the following information:
- LangChain4j version: 1.x (
main@ 062f6c5d) - LLM(s) used: Google Gen AI (
langchain4j-google-genai) - Java version: 17
- Spring Boot version (if applicable): n/a
Additional context
- #3641 added the
inlineDatamapping to the old module, along withGeneratedImageHelper - #5972 fixed the streaming merge for the same key
- #4875 is where the chat model was described as the entry point for image work, with
ImageModelfor pure generation and editing GENERATED_IMAGES_KEYand theimages()accessor live inlangchain4j-core
I searched the issues and PRs for this and didn't find anything, so apologies if I missed one.
I'd like to take this one on if it isn't spoken for. It looks small: wire inlineData into
AiMessage.attributes the way PartsAndContentsMapper does it, swap the putAll in the
streaming model for a merge, and add tests for both. I'll put a PR together unless you'd
rather it went a different way.
Source: langchain4j/langchain4j