Skip to content

feat(google_genai): add Gemma model family support#257

Open
cabljac wants to merge 7 commits into
mainfrom
feat/googleai-gemma-support
Open

feat(google_genai): add Gemma model family support#257
cabljac wants to merge 7 commits into
mainfrom
feat/googleai-gemma-support

Conversation

@cabljac

@cabljac cabljac commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a dedicated GemmaOptions schema (temperature capped at 1.0, matching the Gemma API and the JS GemmaConfigSchema).
  • Adds a googleAI.gemma(name) handle helper alongside the existing .gemini(...) helper.
  • Routes gemma-* model names through CommonGoogleGenPlugin with the right schema and ModelInfo (Gemma 3 variants advertise systemRole: false; Gemma 4 variants keep systemRole: true).
  • Strips ReasoningParts and thoughtSignature metadata from history before calling the Gemma endpoint, matching JS behaviour.
  • Extends the googleai list() discovery filter to surface models/gemma-* with the appropriate schema and supports map.

Closes the P3 parity gap for: gemma-3-1b-it, gemma-3-4b-it, gemma-3-12b-it, gemma-3-27b-it, gemma-3n-e4b-it. Also covers gemma-4-26b-a4b-it and gemma-4-31b-it for full JS parity.

Notes

  • createModel on CommonGoogleGenPlugin gains an optional {ModelInfo? modelInfo} parameter (additive, backwards-compatible). The Vertex AI plugin inherits the common plugin; dart analyze and its test suite remain green.
  • No runtime system-message folding for Gemma 3 — matches JS, which relies on the framework to honour systemRole: false.

Test plan

  • dart analyze clean in packages/genkit_google_genai
  • dart analyze clean in packages/genkit_vertexai
  • dart test passes (41/41) in packages/genkit_google_genai, including 12 new cases in test/gemma_test.dart
  • dart test passes (2/2) in packages/genkit_vertexai
  • Live smoke test against gemma-3-1b-it with GEMINI_API_KEY (not run in this branch)
  • Live multiturn test with a prior ReasoningPart assistant message to confirm the strip

Adds a dedicated GemmaOptions schema (temperature capped at 1.0 per the
Gemma API), a googleAI.gemma(name) handle helper, and routing in the
common plugin so gemma-* model names resolve with the correct config
schema and ModelInfo. Gemma 3 variants advertise systemRole: false to
match the JS plugin; Gemma 4 variants keep systemRole: true.

Runtime strips ReasoningPart and thoughtSignature metadata from
message history before sending to the Gemma endpoint, matching JS
behaviour.

list() now also surfaces models/gemma-* from the discovery API with
the appropriate schema and supports map.

Includes unit tests for the schema, predicates, reasoning-part filter,
plugin handle, and resolver metadata.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Gemma models within the Google GenAI plugin. Key changes include the addition of GemmaOptions for model configuration, logic to identify Gemma model families (specifically handling Gemma 3 differences), and a mechanism to strip reasoning parts from messages when using Gemma models. A review comment suggests making the isGemma identification more robust by checking the model name instead of the options schema.

Comment thread packages/genkit_google_genai/lib/src/common_plugin.dart Outdated
cabljac added 2 commits April 24, 2026 09:53
…chema

More robust against mismatched ModelRef construction (e.g. googleAI.gemini
with a gemma-* name) and matches the JS plugin's runtime behaviour, which
also keys isGemma off the model version string.
@cabljac cabljac force-pushed the feat/googleai-gemma-support branch from 92438d9 to 580248a Compare April 24, 2026 08:56
@CorieW

CorieW commented Apr 24, 2026

Copy link
Copy Markdown
Member

Looks good.

Don't know if it's worth refactoring to move some of the gemma stuff in a gemma.dart file, like in invertase#13? That way, we can keep model-specific stuff separate, which might be beneficial if this plugin is to support all the models the API supports (gemini, veo, gemma, imagen, lyria, deep-research, aqa, nano-banana-pro).

@cabljac

cabljac commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator Author

Looks good.

Don't know if it's worth refactoring to move some of the gemma stuff in a gemma.dart file, like in invertase#13? That way, we can keep model-specific stuff separate, which might be beneficial if this plugin is to support all the models the API supports (gemini, veo, gemma, imagen, lyria, deep-research, aqa, nano-banana-pro).

yeah makes sense! will do

cabljac and others added 2 commits April 27, 2026 09:44
Mirrors the imagen.dart layout (PR #258) so model-family logic lives
in its own file. The generateContent path is still shared with Gemini
via gemmaToGeminiOptions + the existing toGeminiSettings helper, so
the Gemma branch in createModel stays put — only the data (info
constants, predicates, reasoning-strip filter, options mapper) moves.

Renamed _gemmaToGeminiOptions to gemmaToGeminiOptions since it is
now consumed across files. Tests now import from src/gemma.dart.

Sets up the file-per-family pattern for upcoming model families
(veo, lyria, aqa, nano-banana-pro, deep-research).
@CorieW

CorieW commented May 7, 2026

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Gemma models within the Genkit Google GenAI plugin. The changes include adding new model definitions, implementing specific configuration mapping for Gemma, and updating the API client to handle Gemma-specific model metadata and message filtering. The review comments provide actionable suggestions to simplify option parsing logic and to add a validation check for empty message lists to prevent invalid API calls.

Comment thread packages/genkit_google_genai/lib/src/common_plugin.dart Outdated
Comment thread packages/genkit_google_genai/lib/src/common_plugin.dart
@cabljac cabljac marked this pull request as ready for review May 8, 2026 10:03
@cabljac cabljac requested review from kevmoo and pavelgj May 8, 2026 10:04
@pavelgj pavelgj requested a review from ifielker May 8, 2026 13:20
@kevmoo

kevmoo commented May 16, 2026

Copy link
Copy Markdown
Collaborator

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Gemma models within the Google GenAI plugin, including the addition of GemmaOptions, model-specific metadata handling, and logic to strip reasoning parts from messages to meet API requirements. Review feedback suggests extending the message filtering to system instructions and improving the clarity of error messages when all message content is filtered out.

Comment on lines +110 to +112
final messages = isGemma
? stripReasoningParts(nonSystemMessages)
: nonSystemMessages;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While stripReasoningParts is applied to nonSystemMessages, the systemMessage (extracted at line 104) is passed directly to toGeminiPart at line 132 without filtering. If the Gemma API rejects reasoning parts in the system instruction as well, they should be stripped from the system message content to ensure consistency and avoid potential API errors.

Comment on lines +114 to +119
if (isGemma && messages.isEmpty) {
throw GenkitException(
'No valid messages found for the model request.',
status: StatusCodes.INVALID_ARGUMENT,
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check correctly prevents sending an empty contents list to the API after stripping reasoning parts. However, the error message could be more descriptive to help users understand why their request was rejected (e.g., mentioning that Gemma models do not support reasoning parts in history).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants