fix: guard against missing choices (#817)

- Fixes guard by using optional chaining to safely check
chunk.choices?.[0] before accessing.
- Currently, accessing chunk.choices[0] without checking could throw if
choices was missing from the chunk.
This commit is contained in:
Pranav
2025-05-10 18:16:19 -05:00
committed by GitHub
parent fcc76cf3e7
commit 19262f632f

View File

@@ -487,7 +487,7 @@ async function* streamResponses(
let isToolCall = false;
for await (const chunk of completion as AsyncIterable<OpenAI.ChatCompletionChunk>) {
// console.error('\nCHUNK: ', JSON.stringify(chunk));
const choice = chunk.choices[0];
const choice = chunk.choices?.[0];
if (!choice) {
continue;
}