From 40fa0284088a7f6bdf4f717d53f04f4a766cdb51 Mon Sep 17 00:00:00 2001 From: ChenZhaoYu <790348264@qq.com> Date: Fri, 31 Mar 2023 13:37:07 +0800 Subject: [PATCH] fix: some error --- service/src/index.ts | 3 +-- src/utils/request/index.ts | 6 ------ src/views/chat/index.vue | 40 ++++++-------------------------------- 3 files changed, 7 insertions(+), 42 deletions(-) diff --git a/service/src/index.ts b/service/src/index.ts index 3aa97c9..28041d1 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -25,7 +25,7 @@ router.post('/chat-process', [auth, limiter], async (req, res) => { try { const { prompt, options = {}, systemMessage } = req.body as RequestProps let firstChunk = true - const finalResponse = await chatReplyProcess({ + await chatReplyProcess({ message: prompt, lastContext: options, process: (chat: ChatMessage) => { @@ -34,7 +34,6 @@ router.post('/chat-process', [auth, limiter], async (req, res) => { }, systemMessage, }) - res.write(firstChunk ? JSON.stringify(finalResponse) : `\n${JSON.stringify(finalResponse)}`) } catch (error) { res.write(JSON.stringify(error)) diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts index 354bf56..d651bba 100644 --- a/src/utils/request/index.ts +++ b/src/utils/request/index.ts @@ -25,12 +25,6 @@ function http( const successHandler = (res: AxiosResponse>) => { const authStore = useAuthStore() - if (typeof res.data === 'string') { - const lastIndex = (res.data as string).lastIndexOf('\n') - if (lastIndex !== -1) - res.data = JSON.parse((res.data as string).substring(lastIndex)) - } - if (res.data.status === 'Success' || typeof res.data === 'string') return res.data diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index f2743ab..7790f43 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -109,7 +109,7 @@ async function onConversation() { try { let lastText = '' const fetchChatAPIOnce = async () => { - const { data } = await fetchChatAPIProcess({ + await fetchChatAPIProcess({ prompt: message, options, signal: controller.signal, @@ -147,23 +147,11 @@ async function onConversation() { scrollToBottomIfAtBottom() } catch (error) { - // + // } }, }) - updateChat( - +uuid, - dataSources.value.length - 1, - { - dateTime: new Date().toLocaleString(), - text: lastText + data.text ?? '', - inversion: false, - error: false, - loading: false, - conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id }, - requestOptions: { prompt: message, options: { ...options } }, - }, - ) + updateChatSome(+uuid, dataSources.value.length - 1, { loading: false }) } await fetchChatAPIOnce() @@ -252,7 +240,7 @@ async function onRegenerate(index: number) { try { let lastText = '' const fetchChatAPIOnce = async () => { - const { data } = await fetchChatAPIProcess({ + await fetchChatAPIProcess({ prompt: message, options, signal: controller.signal, @@ -292,19 +280,7 @@ async function onRegenerate(index: number) { } }, }) - updateChat( - +uuid, - index, - { - dateTime: new Date().toLocaleString(), - text: lastText + data.text ?? '', - inversion: false, - error: false, - loading: false, - conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id }, - requestOptions: { prompt: message, ...options }, - }, - ) + updateChatSome(+uuid, index, { loading: false }) } await fetchChatAPIOnce() } @@ -499,11 +475,7 @@ onUnmounted(() => { @toggle-using-context="toggleUsingContext" />
-
+