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 @@ -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 ,
You can’t perform that action at this time.
0 commit comments