From 6ef63e2415d9ea6a8cf0575cf4684df1de235cf1 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:02:39 +0000 Subject: [PATCH] Fix smooth streaming --- public/scripts/sse-stream.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/scripts/sse-stream.js b/public/scripts/sse-stream.js index dbe481e78..e56561632 100644 --- a/public/scripts/sse-stream.js +++ b/public/scripts/sse-stream.js @@ -109,7 +109,7 @@ function getDelay(s) { */ async function* parseStreamData(json) { // Cohere - if (typeof json.delta.message === 'object' && ['tool-plan-delta', 'content-delta'].includes(json.type)) { + if (typeof json.delta === 'object' && typeof json.delta.message === 'object' && ['tool-plan-delta', 'content-delta'].includes(json.type)) { const text = json?.delta?.message?.content?.text ?? ''; for (let i = 0; i < text.length; i++) { const str = json.delta.message.content.text[i]; @@ -121,7 +121,7 @@ async function* parseStreamData(json) { return; } // Claude - if (typeof json.delta === 'object' && typeof json.delta.text === 'string') { + else if (typeof json.delta === 'object' && typeof json.delta.text === 'string') { if (json.delta.text.length > 0) { for (let i = 0; i < json.delta.text.length; i++) { const str = json.delta.text[i];