From b0de27a721bff0c91835224e7a17861cb979a71a Mon Sep 17 00:00:00 2001 From: cherishsince Date: Mon, 13 May 2024 17:49:18 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=91=E9=80=81=20stream=20=E4=B8=AD=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=BF=9B=E8=A1=8C=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/ai/chat/index.vue | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/views/ai/chat/index.vue b/src/views/ai/chat/index.vue index 3c74d927..6706f700 100644 --- a/src/views/ai/chat/index.vue +++ b/src/views/ai/chat/index.vue @@ -151,7 +151,12 @@
- 发送 + + {{ conversationInProgress ? '进行中' : '发送'}} + + + 停止 +
@@ -170,6 +175,8 @@ const { copy } = useClipboard(); const searchName = ref('') // 查询的内容 const conversationId = ref('1781604279872581648') // 对话id const conversationInProgress = ref() // 对话进行中 +conversationInProgress.value = false + const conversationInAbortController = ref() // 对话进行中 abort 控制器(控制 stream 对话) const prompt = ref() // prompt @@ -204,6 +211,10 @@ const searchConversation = () => { /** send */ const onSend = async () => { + // 进行中不允许发送 + if (conversationInProgress.value) { + return + } const content = prompt.value; // 清空输入框 prompt.value = '' @@ -322,12 +333,19 @@ const onDelete = async (id) => { message: '删除成功!', type: 'success', }) + // tip:如果 stream 进行中的 message,就需要调用 controller 结束 + stopStream() + // 重新获取 message 列表 + await messageList(); +} + +const stopStream = async () => { // tip:如果 stream 进行中的 message,就需要调用 controller 结束 if (conversationInAbortController.value) { conversationInAbortController.value.abort() } - // 重新获取 message 列表 - await messageList(); + // 设置为 false + conversationInProgress.value = false } /** 初始化 **/