🔧 fix: Add missing finish_reason to stream chunks (#5563)

This commit is contained in:
James Lamine 2025-01-30 15:24:43 -05:00 committed by GitHub
parent 85c6a706c3
commit 1226f56d0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();