From e30217542d6bebba12c773936ae752923c83ba01 Mon Sep 17 00:00:00 2001 From: Liut Date: Wed, 22 Mar 2023 18:49:40 +0800 Subject: [PATCH] fix line end with new-line in some backend (#474) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix line end with new-line in some backend In backend with golang (like https://github.com/sashabaranov/go-openai), the responseText always has '\n'. * feat: 补全遗漏 --------- Co-authored-by: ChenZhaoYu <790348264@qq.com> --- src/views/chat/index.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 9ed9fdd..f0e85dd 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -115,7 +115,7 @@ async function onConversation() { const xhr = event.target const { responseText } = xhr // Always process the final line - const lastIndex = responseText.lastIndexOf('\n') + const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2) let chunk = responseText if (lastIndex !== -1) chunk = responseText.substring(lastIndex) @@ -245,7 +245,7 @@ async function onRegenerate(index: number) { const xhr = event.target const { responseText } = xhr // Always process the final line - const lastIndex = responseText.lastIndexOf('\n') + const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2) let chunk = responseText if (lastIndex !== -1) chunk = responseText.substring(lastIndex)