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