This repository was archived by the owner on May 15, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments