From 1200d02fbf63937fdca708f0d308c1b4ac012d8e Mon Sep 17 00:00:00 2001 From: Gsh <15170702455@163.com> Date: Wed, 2 Jul 2025 00:11:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=AF=B9=E8=AF=9D=E6=97=B6?= =?UTF-8?q?=E5=8F=AA=E6=8F=90=E4=BE=9B=E6=9C=80=E8=BF=916=E6=9D=A1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/chat/layouts/chatWithId/index.vue | 16 +++++++++++++--- Yi.Ai.Vue3/src/utils/request.ts | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue b/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue index a598c160..9965f0ae 100644 --- a/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue +++ b/Yi.Ai.Vue3/src/pages/chat/layouts/chatWithId/index.vue @@ -82,6 +82,7 @@ watch( if (v) { // 发送消息 console.log('发送消息 v', v); + console.log('发送消息--error', bubbleItems); setTimeout(() => { startSSE(v); }, 350); @@ -167,12 +168,21 @@ async function startSSE(chatContent: string) { // 这里有必要调用一下 BubbleList 组件的滚动到底部 手动触发 自动滚动 bubbleListRef.value?.scrollToBottom(); + console.log('bubbleItems.value--', bubbleItems.value); for await (const chunk of stream({ + // messages: bubbleItems.value + // .filter((item: any) => item.role === 'user') + // .map((item: any) => ({ + // role: item.role, + // content: item.content, + // })), messages: bubbleItems.value - .filter((item: any) => item.role === 'user') - .map((item: any) => ({ + .slice(-6) // 直接取最后6条记录(最近的) + .map((item: MessageItem) => ({ role: item.role, - content: item.content, + content: (item.role === 'ai' || item.role === 'system') && item.content.length > 2000 + ? `${item.content.substring(0, 2000)}...(内容过长,已省略)` + : item.content, })), sessionId: route.params?.id !== 'not_login' ? String(route.params?.id) : undefined, userId: userStore.userInfo?.userId, diff --git a/Yi.Ai.Vue3/src/utils/request.ts b/Yi.Ai.Vue3/src/utils/request.ts index f0900e61..3d68512d 100644 --- a/Yi.Ai.Vue3/src/utils/request.ts +++ b/Yi.Ai.Vue3/src/utils/request.ts @@ -120,6 +120,7 @@ function jwtPlugin(): { if (error.status === 403) { // 弹窗提示 ElMessage.error('业务错误,请稍后再试'); + console.error('Fetch error:', error); } }, };