From c6e3c33979ab6ed1aa6a834f39c85356320c0f93 Mon Sep 17 00:00:00 2001
From: gerson <1405270578@qq.com>
Date: 星期五, 19 七月 2024 23:02:11 +0800
Subject: [PATCH] 语音对话

---
 src/components/chat/Chat.vue |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index 9f3968b..cc219c9 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -102,9 +102,11 @@
 
 			<div class="sticky bottom-0 w-full p-6 pb-8 bg-[rgb(247,248,250)] flex justify-center">
 				<PlayBar
+					v-model:voicePageIsShow="voicePageIsShow"
 					:isTalking="isTalking"
+					:isHome="false"
 					v-model="messageContent.values"
-					@sendClick="sendChatMessage"
+					@sendClick="sendClick"
 					:style="{ width: chatWidth }"
 				></PlayBar>
 			</div>
@@ -124,7 +126,16 @@
 import { GetHistoryAnswer, QueryHistoryDetail, QuestionAi, SetHistoryAnswerState, getQuestionProcess } from '/@/api/ai/chat';
 import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
 import router from '/@/router';
-import { activeChatRoom, activeLLMId, activeRoomId, activeSampleId, activeSectionAId, roomConfig } from '/@/stores/chatRoom';
+import {
+	activeChatRoom,
+	activeLLMId,
+	activeRoomId,
+	activeSampleId,
+	activeSectionAId,
+	roomConfig,
+	setRoomConfig,
+	getRoomConfig,
+} from '/@/stores/chatRoom';
 import { v4 as uuidv4 } from 'uuid';
 import _ from 'lodash';
 import { ErrorCode } from '/@/utils/request';
@@ -133,7 +144,7 @@
 import CustomDrawer from '/@/components/drawer/CustomDrawer.vue';
 
 const chatWidth = '75%';
-
+const voicePageIsShow = ref(false);
 let isTalking = ref(false);
 let messageContent = ref<ChatContent>({
 	type: AnswerType.Text,
@@ -299,9 +310,11 @@
 	});
 };
 
-const sendChatMessage = async (content: ChatContent = messageContent.value) => {
+const sendChatMessage = async (content: ChatContent = messageContent.value, cb?: any) => {
 	if (!content?.values) return;
-	if (messageList.value.length === 0) {
+
+	const isNewChat = messageList.value.length === 0
+	if (isNewChat) {
 		if (activeSampleId.value) {
 			currentSampleId = activeSampleId.value;
 		}
@@ -329,9 +342,17 @@
 
 		let resMsgContent: ChatContent = null;
 		resMsgContent = await questionAi(content.values);
+		if (isNewChat) {
+			const firstResCb = getRoomConfig(currentRouteId, 'firstResCb');
+			firstResCb(resMsgContent);
+		} else {
+			cb?.(resMsgContent);
+		}
 		userItem.historyId = questionRes.history_id;
 		assistantItem.historyId = questionRes.history_id;
 		appendLastMessageContent(resMsgContent);
+
+		return resMsgContent;
 	} catch (error: any) {
 		// appendLastMessageContent({
 		// 	type: AnswerType.Text,
@@ -341,6 +362,10 @@
 		isTalking.value = false;
 	}
 };
+
+const sendClick = (cb) => {
+	sendChatMessage(messageContent.value, cb);
+};
 const appendLastMessageContent = (content: ChatContent) => {
 	if (messageList.value.at(-1)) {
 		messageList.value.at(-1).content = content;

--
Gitblit v1.9.3