Open
Description
Description of the bug:
when using generateContent, the value of output.candidates[0].content.parts[0].text is sometimes empty. See
Actual vs expected behavior:
async function expected() {
const genAI = new GoogleGenerativeAI(process.env.GEMINI);
const MODEL = "gemini-2.0-flash-001";
const { response: output } = await genAI.getGenerativeModel({
model: MODEL,
systemInstruction: "you are a helpful assistant.",
generationConfig: {
maxOutputTokens: 1000,
temperature: 0,
}
}).generateContent("what is the capital of france?");
console.log(output.candidates[0].content.parts[0].text); // expected The capital of France is Paris.
}
async function actual() {
const genAI = new GoogleGenerativeAI(process.env.GEMINI);
const MODEL = "gemini-2.0-flash-001";
const { response: output } = await genAI.getGenerativeModel({
model: MODEL,
systemInstruction: "you are a helpful assistant.",
generationConfig: {
maxOutputTokens: 1000,
temperature: 0,
}
}).generateContent("what is the capital of france?");
console.log(output.candidates[0].content.parts[0].text); // actual "".
}
Any other information you'd like to share?
I'm struggling to reproduce this error consistently. Sometimes it works on retries. There is no indication from logs that we hit an api rate limit