feat: add support for the Gemma-3 and Gemini Robotics models via the … - #10069
feat: add support for the Gemma-3 and Gemini Robotics models via the …#10069techstrom wants to merge 7 commits into
Conversation
All issues have been resolved. The PR is ready for merge.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
|
I’ve made the following improvements:
I’d appreciate it if you could review the changes again. |
| // Check if the model is a Gemma 3 model | ||
| const isGemma3 = model.includes("gemma-3") | ||
|
|
||
| // Prepend system instruction to the first user message if it's a Gemma 3 model, | ||
| // as they don't support the system instruction parameter. | ||
| if (isGemma3 && systemInstruction) { | ||
| if (contents.length > 0 && contents[0].role === "user") { | ||
| const firstMessage = contents[0] | ||
| // Create a new text part for the system instruction | ||
| const systemPart = { text: systemInstruction } | ||
| // Prepend it to the existing parts | ||
| firstMessage.parts = [systemPart, ...(firstMessage.parts || [])] | ||
| } else { | ||
| // If no messages or first message is not user (e.g. starts with model), | ||
| // prepend a new user message with the system instruction. | ||
| contents.unshift({ | ||
| role: "user", | ||
| parts: [{ text: systemInstruction }], | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Check if the model is a Gemma 3 model | ||
| const isGemma3 = model.includes("gemma-3") | ||
|
|
||
| // Prepend system instruction to the first user message if it's a Gemma 3 model, | ||
| // as they don't support the system instruction parameter. | ||
| if (isGemma3 && systemInstruction) { | ||
| if (contents.length > 0 && contents[0].role === "user") { | ||
| const firstMessage = contents[0] | ||
| // Create a new text part for the system instruction | ||
| const systemPart = { text: systemInstruction } | ||
| // Prepend it to the existing parts | ||
| firstMessage.parts = [systemPart, ...(firstMessage.parts || [])] | ||
| } else { | ||
| // If no messages or first message is not user (e.g. starts with model), | ||
| // prepend a new user message with the system instruction. | ||
| contents.unshift({ | ||
| role: "user", | ||
| parts: [{ text: systemInstruction }], | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
The Gemma 3 system instruction handling code is duplicated three times (lines 165-185, 187-207, and 209-229). This will cause a TypeScript compilation error because const isGemma3 is declared three times in the same scope. Only the first block should be kept; the other two are exact duplicates that need to be removed.
| // Check if the model is a Gemma 3 model | |
| const isGemma3 = model.includes("gemma-3") | |
| // Prepend system instruction to the first user message if it's a Gemma 3 model, | |
| // as they don't support the system instruction parameter. | |
| if (isGemma3 && systemInstruction) { | |
| if (contents.length > 0 && contents[0].role === "user") { | |
| const firstMessage = contents[0] | |
| // Create a new text part for the system instruction | |
| const systemPart = { text: systemInstruction } | |
| // Prepend it to the existing parts | |
| firstMessage.parts = [systemPart, ...(firstMessage.parts || [])] | |
| } else { | |
| // If no messages or first message is not user (e.g. starts with model), | |
| // prepend a new user message with the system instruction. | |
| contents.unshift({ | |
| role: "user", | |
| parts: [{ text: systemInstruction }], | |
| }) | |
| } | |
| } | |
| // Check if the model is a Gemma 3 model | |
| const isGemma3 = model.includes("gemma-3") | |
| // Prepend system instruction to the first user message if it's a Gemma 3 model, | |
| // as they don't support the system instruction parameter. | |
| if (isGemma3 && systemInstruction) { | |
| if (contents.length > 0 && contents[0].role === "user") { | |
| const firstMessage = contents[0] | |
| // Create a new text part for the system instruction | |
| const systemPart = { text: systemInstruction } | |
| // Prepend it to the existing parts | |
| firstMessage.parts = [systemPart, ...(firstMessage.parts || [])] | |
| } else { | |
| // If no messages or first message is not user (e.g. starts with model), | |
| // prepend a new user message with the system instruction. | |
| contents.unshift({ | |
| role: "user", | |
| parts: [{ text: systemInstruction }], | |
| }) | |
| } | |
| } |
Fix it with Roo Code or mention @roomote and request a fix.
|
Hi, just a gentle ping I’ve rebased this PR to follow the latest release as of Dec 20 (v3.36.16), so it should be fully up to date with the current main branch. No rush at all — I just wanted to check whether there’s anything you’d like me to adjust, or if this change is something you’d be interested in merging. Thanks for your time! |
…l supported languages.
Merge remote-tracking branch 'upstream/main' into gemma3
|
Apologies for the delayed response. Thanks for the contribution. We are not planning to add support for the Gemma 3 or Gemini Robotics models via this API at this time. We have not seen enough demand to justify expanding the supported model set, and the PR goes beyond adding model identifiers by introducing model-specific request reshaping and error handling that makes the provider more complex and harder to maintain. If there is broader demand, please open a feature request issue with the concrete use case, which models need to work, and why they require behavior that differs from the existing provider contract. |
add support for the models: gemma-3-27b-it, gemma-3-12b-it, gemma-3-4b-it and gemini-robotics-er-1.5-preview.
Description
This PR introduces fixes for Gemma 3 model compatibility within the Gemini provider, specifically addressing API error handling and system instruction formatting.
Changes
Gemma 3 System Instruction Handling:
Implemented a check for Gemma 3 models (isGemma3).
Modified the request construction to prepend systemInstruction to the user message for Gemma 3 models, as they do not support the separate systemInstruction field.
Ensured systemInstruction is omitted from the configuration object when using Gemma 3 models to prevent API errors.
Error Handling Improvements:
Added specific error parsing for resource_exhausted (429) errors from the Gemini API.
Mapped these errors to a user-friendly message, including the limit, model name, and retry time.
Version
Validated with version: 3.36.6
Important
Adds support for Gemma 3 and Gemini Robotics models with specific handling for system instructions and improved error handling in the Gemini provider.
gemma-3-27b-it,gemma-3-12b-it,gemma-3-4b-it, andgemini-robotics-er-1.5-previewmodels ingemini.ts.systemInstructionto user messages and omits it from the config to avoid API errors inGeminiHandler.resource_exhausted(429) errors and mapping them to user-friendly messages inGeminiHandler.resource_exhaustederror message tocommon.jsonin bothenandjalocales.This description was created by
for 181f829. You can customize this summary. It will automatically update as commits are pushed.