feat(google_genai): add Gemma model family support#257
Conversation
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.
There was a problem hiding this comment.
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.
…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.
92438d9 to
580248a
Compare
|
Looks good. Don't know if it's worth refactoring to move some of the gemma stuff in a |
yeah makes sense! will do |
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).
|
/gemini review |
There was a problem hiding this comment.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
| final messages = isGemma | ||
| ? stripReasoningParts(nonSystemMessages) | ||
| : nonSystemMessages; |
There was a problem hiding this comment.
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.
| if (isGemma && messages.isEmpty) { | ||
| throw GenkitException( | ||
| 'No valid messages found for the model request.', | ||
| status: StatusCodes.INVALID_ARGUMENT, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Summary
GemmaOptionsschema (temperature capped at 1.0, matching the Gemma API and the JSGemmaConfigSchema).googleAI.gemma(name)handle helper alongside the existing.gemini(...)helper.gemma-*model names throughCommonGoogleGenPluginwith the right schema andModelInfo(Gemma 3 variants advertisesystemRole: false; Gemma 4 variants keepsystemRole: true).ReasoningParts andthoughtSignaturemetadata from history before calling the Gemma endpoint, matching JS behaviour.list()discovery filter to surfacemodels/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 coversgemma-4-26b-a4b-itandgemma-4-31b-itfor full JS parity.Notes
createModelonCommonGoogleGenPlugingains an optional{ModelInfo? modelInfo}parameter (additive, backwards-compatible). The Vertex AI plugin inherits the common plugin;dart analyzeand its test suite remain green.systemRole: false.Test plan
dart analyzeclean inpackages/genkit_google_genaidart analyzeclean inpackages/genkit_vertexaidart testpasses (41/41) inpackages/genkit_google_genai, including 12 new cases intest/gemma_test.dartdart testpasses (2/2) inpackages/genkit_vertexaigemma-3-1b-itwithGEMINI_API_KEY(not run in this branch)ReasoningPartassistant message to confirm the strip