From b38a262bbcb1eb15eda5e85cb92803e73bef0d9c Mon Sep 17 00:00:00 2001 From: SAY-5 Date: Sat, 2 May 2026 05:08:42 -0700 Subject: [PATCH] fix(fireworks-ai): tolerate empty choices in stream chunks (#1627) Signed-off-by: SAY-5 --- src/providers/fireworks-ai/chatComplete.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/providers/fireworks-ai/chatComplete.ts b/src/providers/fireworks-ai/chatComplete.ts index 5c7fcfe66..5bcb65cf7 100644 --- a/src/providers/fireworks-ai/chatComplete.ts +++ b/src/providers/fireworks-ai/chatComplete.ts @@ -222,6 +222,7 @@ export const FireworksAIChatCompleteStreamChunkTransform: ( return `data: ${chunk}\n\n`; } const parsedChunk: FireworksAIStreamChunk = JSON.parse(chunk); + const choice = parsedChunk.choices?.[0]; return ( `data: ${JSON.stringify({ id: parsedChunk.id, @@ -229,14 +230,16 @@ export const FireworksAIChatCompleteStreamChunkTransform: ( created: parsedChunk.created, model: parsedChunk.model, provider: FIREWORKS_AI, - choices: [ - { - index: parsedChunk.choices[0].index, - delta: parsedChunk.choices[0].delta, - finish_reason: parsedChunk.choices[0].finish_reason, - logprobs: parsedChunk.choices[0].logprobs, - }, - ], + choices: choice + ? [ + { + index: choice.index, + delta: choice.delta, + finish_reason: choice.finish_reason, + logprobs: choice.logprobs, + }, + ] + : [], ...(parsedChunk.usage ? { usage: parsedChunk.usage } : {}), })}` + '\n\n' );