fix: ensure Gemini always receives a non-empty contents array (#5229)

This commit is contained in:
toi500 2025-09-18 10:26:44 +02:00 committed by GitHub
parent f560768133
commit fc50f2308b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 0 deletions

View File

@ -770,6 +770,12 @@ export class LangchainChatGoogleGenerativeAI
this.client.systemInstruction = systemInstruction this.client.systemInstruction = systemInstruction
actualPrompt = prompt.slice(1) actualPrompt = prompt.slice(1)
} }
// Ensure actualPrompt is never empty
if (actualPrompt.length === 0) {
actualPrompt = [{ role: 'user', parts: [{ text: '...' }] }]
}
const parameters = this.invocationParams(options) const parameters = this.invocationParams(options)
// Handle streaming // Handle streaming
@ -834,6 +840,12 @@ export class LangchainChatGoogleGenerativeAI
this.client.systemInstruction = systemInstruction this.client.systemInstruction = systemInstruction
actualPrompt = prompt.slice(1) actualPrompt = prompt.slice(1)
} }
// Ensure actualPrompt is never empty
if (actualPrompt.length === 0) {
actualPrompt = [{ role: 'user', parts: [{ text: '...' }] }]
}
const parameters = this.invocationParams(options) const parameters = this.invocationParams(options)
const request = { const request = {
...parameters, ...parameters,