From 4466c5b4ecb47748fb2e88542fe756f2f872980c Mon Sep 17 00:00:00 2001 From: cherishsince Date: Wed, 22 May 2024 10:58:54 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=A7=A3=E5=86=B3todo=E3=80=91AI=20Ch?= =?UTF-8?q?at=20stream=20=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=A4=B4?= =?UTF-8?q?=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/ai/gpt.svg | 1 + src/views/ai/chat/index.vue | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/assets/ai/gpt.svg diff --git a/src/assets/ai/gpt.svg b/src/assets/ai/gpt.svg new file mode 100644 index 00000000..603e2e95 --- /dev/null +++ b/src/assets/ai/gpt.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/views/ai/chat/index.vue b/src/views/ai/chat/index.vue index 0de50b0a..2f16a23f 100644 --- a/src/views/ai/chat/index.vue +++ b/src/views/ai/chat/index.vue @@ -109,6 +109,7 @@ const conversationInProgress = ref(false) // 对话进行中 const conversationInAbortController = ref() // 对话进行中 abort 控制器(控制 stream 对话) const inputTimeout = ref() // 处理输入中回车的定时器 const prompt = ref() // prompt +const userInfo = ref() // 用户信息 const fullText = ref(''); const displayedText = ref(''); @@ -124,6 +125,9 @@ const listLoadingTime = ref() // time定时器,如果加载速度很快 const messageRef = ref() const isComposing = ref(false) // 判断用户是否在输入 +// 默认 role 头像 +const defaultRoleAvatar = 'http://test.yudao.iocoder.cn/eaef5f41acb911dd718429a0702dcc3c61160d16e57ba1d543132fab58934f9f.png' + // =========== 自提滚动效果 const textRoll = async () => { @@ -300,6 +304,7 @@ const doSendStream = async (userMessage: ChatMessageVO) => { conversationId: activeConversationId.value, type: 'user', content: userMessage.content, + userAvatar: userInfo.value?.avatar, createTime: new Date() } as ChatMessageVO) list.value.push({ @@ -307,6 +312,7 @@ const doSendStream = async (userMessage: ChatMessageVO) => { conversationId: activeConversationId.value, type: 'system', content: '思考中...', + roleAvatar: defaultRoleAvatar, createTime: new Date() } as ChatMessageVO) // 滚动到最下面 @@ -388,12 +394,11 @@ const getMessageList = async () => { // 获取列表数据 const messageListRes = await ChatMessageApi.messageList(activeConversationId.value) // 设置用户头像 - const user = await getUserProfile() messageListRes.map(item => { - item.userAvatar = user?.avatar + // 设置 role 默认头像 + item.roleAvatar = item.roleAvatar ? item.roleAvatar : defaultRoleAvatar }) list.value = messageListRes - console.log("设置头像成功", messageListRes) // 滚动到最下面 await nextTick(() => { // 滚动到最后 @@ -524,6 +529,8 @@ onMounted(async () => { // 获取列表数据 listLoading.value = true await getMessageList() + // 获取用户信息 + userInfo.value = await getUserProfile() })