genkit
genkit copied to clipboard
[JS] Gemini JSON mode can't stream
Describe the bug When generating in JSON mode, the Gemini plugin crashes when trying to send partial responses. This is because we use standard JSON.parse instead of a lenient parser.
To Reproduce
const {stream} = generateStream({
prompt: "Generate a list of 50 contacts for synthetic data testing.",
output: {format: "json", schema: z.object({people: z.array(z.object({name: z.string(), email: z.string()}))})},
});
for await (const chunk of stream()) {
// crashes here
console.log(chunk);
}
Expected behavior A partial object is returned as a chunk.
Still needs fixing in next