diff --git a/server/utils/chats/stream.js b/server/utils/chats/stream.js index 293e3b4107263eeeb2a21cb8a2755f273b3ad11f..a6ade1819d243858a8af0259c72e5a9599a371af 100644 --- a/server/utils/chats/stream.js +++ b/server/utils/chats/stream.js @@ -268,6 +268,11 @@ function handleStreamResponses(response, stream, responseProps) { return new Promise(async (resolve) => { let fullText = ""; for await (const chunk of stream) { + if (chunk === undefined) + throw new Error( + "Stream returned undefined chunk. Aborting reply - check model provider logs." + ); + const content = chunk.hasOwnProperty("content") ? chunk.content : chunk; fullText += content; writeResponseChunk(response, {