Skip to content

fix: GoogleGenAiChatModel throws NoSuchElementException on Vertex Gemma MaaS - #6681

Open
renechoi wants to merge 1 commit into
spring-projects:mainfrom
renechoi:fix/issue-6665-gemma-maas-missing-modelversion
Open

fix: GoogleGenAiChatModel throws NoSuchElementException on Vertex Gemma MaaS#6681
renechoi wants to merge 1 commit into
spring-projects:mainfrom
renechoi:fix/issue-6665-gemma-maas-missing-modelversion

Conversation

@renechoi

Copy link
Copy Markdown

Resolves #6665.

Description
GoogleGenAiChatModel currently throws NoSuchElementException when calling .get() on the modelVersion field in GenerateContentResponse if the model does not include it (e.g. Vertex Gemma MaaS models).

This PR guards against NoSuchElementException by replacing the unguarded .get() with .orElse(request.modelName()) so that the metadata parsing gracefully falls back to the requested model name (or remains valid) instead of terminating a successful model generation call with an exception.

Changes

  • Updated GoogleGenAiChatModel.internalCall() to use generateContentResponse.modelVersion().orElse(geminiRequest.modelName()).
  • Updated GoogleGenAiChatModel.internalStream() to use response.modelVersion().orElse(request.modelName()).
  • Added testResponseWithoutModelVersion() to GoogleGenAiChatModelExtendedUsageTests simulating the Gemma MaaS response payload.

…ma MaaS

Vertex Gemma MaaS models omit the modelVersion field in GenerateContentResponse, causing an unguarded Optional.get() to throw NoSuchElementException. This commit uses orElse(request.modelName()) as a fallback to prevent NPEs and ensure successful parsing of valid responses.

Fixes spring-projects#6665

Signed-off-by: renechoi <renechoi90@gmail.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.

GoogleGenAiChatModel throws NoSuchElementException for models that omit modelVersion in GenerateContentResponse (e.g. Vertex Gemma MaaS)

2 participants