diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js index 8329a8b148..4ea4bc8d35 100644 --- a/api/app/clients/OpenAIClient.js +++ b/api/app/clients/OpenAIClient.js @@ -1364,6 +1364,14 @@ ${convo} } for await (const chunk of stream) { + // Add finish_reason: null if missing in any choice + if (chunk.choices) { + chunk.choices.forEach(choice => { + if (!('finish_reason' in choice)) { + choice.finish_reason = null; + } + }); + } this.streamHandler.handle(chunk); if (abortController.signal.aborted) { stream.controller.abort();