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

Commit 0f63a75

Browse files
committed
feat: add support for the Gemma-3 and Gemini Robotics models via the Gemini API
1 parent 09e19fe commit 0f63a75

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
@@ -184,6 +184,28 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
184184
}
185185
}
186186

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

0 commit comments

Comments
 (0)