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

Commit 4eae5a3

Browse files
committed
fix: type error
1 parent 78d6940 commit 4eae5a3

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/api/providers/gemini.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,29 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
196196
// Create a new text part for the system instruction
197197
const systemPart = { text: systemInstruction }
198198
// Prepend it to the existing parts
199-
firstMessage.parts = [systemPart, ...firstMessage.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+
210+
// Check if the model is a Gemma 3 model
211+
const isGemma3 = model.includes("gemma-3")
212+
213+
// Prepend system instruction to the first user message if it's a Gemma 3 model,
214+
// as they don't support the system instruction parameter.
215+
if (isGemma3 && systemInstruction) {
216+
if (contents.length > 0 && contents[0].role === "user") {
217+
const firstMessage = contents[0]
218+
// Create a new text part for the system instruction
219+
const systemPart = { text: systemInstruction }
220+
// Prepend it to the existing parts
221+
firstMessage.parts = [systemPart, ...(firstMessage.parts || [])]
200222
} else {
201223
// If no messages or first message is not user (e.g. starts with model),
202224
// prepend a new user message with the system instruction.

0 commit comments

Comments
 (0)