Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit e9ac3e6

Browse files
committed
feat: add support for the Gemma-3 and Gemini Robotics models via the Gemini API
1 parent 7c30e1b commit e9ac3e6

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/api/providers/gemini.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
185185
}
186186
}
187187

188+
// Check if the model is a Gemma 3 model
189+
const isGemma3 = model.includes("gemma-3")
190+
191+
// Prepend system instruction to the first user message if it's a Gemma 3 model,
192+
// as they don't support the system instruction parameter.
193+
if (isGemma3 && systemInstruction) {
194+
if (contents.length > 0 && contents[0].role === "user") {
195+
const firstMessage = contents[0]
196+
// Create a new text part for the system instruction
197+
const systemPart = { text: systemInstruction }
198+
// Prepend it to the existing parts
199+
firstMessage.parts = [systemPart, ...firstMessage.parts]
200+
} else {
201+
// If no messages or first message is not user (e.g. starts with model),
202+
// prepend a new user message with the system instruction.
203+
contents.unshift({
204+
role: "user",
205+
parts: [{ text: systemInstruction }],
206+
})
207+
}
208+
}
209+
188210
const config: GenerateContentConfig = {
189211
...(isGemma3 ? {} : { systemInstruction }),
190212
httpOptions: this.options.googleGeminiBaseUrl ? { baseUrl: this.options.googleGeminiBaseUrl } : undefined,

0 commit comments

Comments
 (0)