From 2db98acd7d2c36fe23756051c2c858ab33244572 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期二, 31 十二月 2024 10:25:35 +0800
Subject: [PATCH] 删除无关代码——关联查询; 整理代码

---
 src/components/chat/Chat.vue               |  144 ++++++++++++++---------------------------------
 src/components/chat/hooks/useScrollLoad.ts |    1 
 src/components/chat/model/types.ts         |    1 
 3 files changed, 44 insertions(+), 102 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index 88d5d8d..4cad518 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -185,22 +185,6 @@
 												:originData="item"
 												:isTalking="isTalking && msgIndex === computedMessageList.length - 1"
 											/>
-											<div
-												v-if="item.role === RoleEnum.assistant && item.content.origin?.ext_call_list"
-												class="flex font-bold items-center mt-6"
-											>
-												<div class="flex-0 mb-auto -mr-4">鍏宠仈鍔熻兘锛�</div>
-												<div class="space-x-5 flex flex-wrap">
-													<div
-														v-for="callItem in item.content.origin?.ext_call_list"
-														:key="callItem.call_ext_id"
-														@click="relativeQueryClick(callItem)"
-														class="cursor-pointer hover:underline first-of-type:ml-5"
-													>
-														{{ callItem.question }}
-													</div>
-												</div>
-											</div>
 										</template>
 										<!-- #endregion -->
 										<!-- </template> -->
@@ -374,8 +358,6 @@
 	activeLLMId,
 	activeRoomId,
 	activeSampleId,
-	activeSectionAId,
-	getRoomConfig,
 	isSharePage,
 	roomConfig,
 } from '/@/stores/chatRoom';
@@ -520,10 +502,8 @@
 
 //#endregion
 
-const DEFAULT_SECTION_A_ID = 'knowledge_base';
 let questionRes = null;
 let position = null;
-let finalCalcSectionAId = null;
 
 let lastAxiosSource: CancelTokenSource = null;
 const questionAi = async (text) => {
@@ -535,18 +515,6 @@
 			prev_question: preQuestion.value,
 		};
 	}
-	let currentSectionAId = '';
-	if (activeSectionAId.value) {
-		currentSectionAId = activeSectionAId.value;
-		activeSectionAId.value = '';
-	} else {
-		const lastSectionAItem = findLast(
-			computedMessageList.value as any,
-			(item) => item.role === RoleEnum.assistant && !!item.sectionAId
-		);
-		currentSectionAId = lastSectionAItem?.sectionAId ?? DEFAULT_SECTION_A_ID;
-	}
-	finalCalcSectionAId = currentSectionAId;
 
 	const params = {
 		question: text,
@@ -766,15 +734,47 @@
 	computedMessageList.value.at(-1).isStopMsg = true;
 };
 
-const sendChatMessage = async (content: ChatContent = messageContent.value, cb?: any, isCallExtParams?: any) => {
+const checkCanSend = (content: ChatContent = messageContent.value) => {
 	if (!content?.values) {
-		return;
+		return false;
 	}
 	if (isTalking.value || chatListLoading.value) {
 		ElMessage.warning('ai 姝e湪鍥炲涓紝璇风◢鍚庡皾璇曟彁闂�');
+		return false;
+	}
+	return true;
+};
+
+const addChatItem = (content: ChatContent) => {
+	isTalking.value = true;
+	const userItem: ChatMessage = { role: RoleEnum.user, content, isChecked: false } as any;
+	const assistantItem: ChatMessage = {
+		role: RoleEnum.assistant,
+		content: {
+			type: AnswerType.Report,
+		},
+		state: AnswerState.Null,
+		stepGroup: [
+			{
+				value: [],
+				isShow: true,
+			},
+		],
+		isStopMsg: false,
+		isChecked: false,
+	} as any;
+	messageList.value.push(userItem);
+	clearMessageContent();
+
+	messageList.value.push(assistantItem);
+	scrollToBottom();
+	return [userItem, assistantItem];
+};
+
+const sendChatMessage = async (content: ChatContent = messageContent.value) => {
+	if (!checkCanSend(content)) {
 		return;
 	}
-
 	const isNewChat = messageList.value.length === 0;
 	if (isNewChat) {
 		if (activeSampleId.value) {
@@ -788,49 +788,18 @@
 	let resMsgContent: ChatContent = null;
 
 	try {
-		isTalking.value = true;
-		const userItem: ChatMessage = { role: RoleEnum.user, content, isChecked: false } as any;
-		const assistantItem: ChatMessage = {
-			role: RoleEnum.assistant,
-			content: {
-				type: AnswerType.Report,
-			},
-			state: AnswerState.Null,
-			stepGroup: [
-				{
-					value: [],
-					isShow: true,
-				},
-			],
-			isStopMsg: false,
-			isChecked: false,
-		} as any;
-		messageList.value.push(userItem);
-		clearMessageContent();
+		const [userItem, assistantItem] = addChatItem(content);
 
-		messageList.value.push(assistantItem);
-		scrollToBottom();
-
-		if (isCallExtParams) {
-			const extRes = await extCallQuery(isCallExtParams);
-			questionRes = extRes;
-			resMsgContent = parseContent(extRes, true);
-		} else {
-			resMsgContent = await questionAi(content.values);
-		}
+		resMsgContent = await questionAi(content.values);
 
 		updateLoadIndex();
-		if (isNewChat) {
-			const firstResCb = getRoomConfig(currentRouteId, 'firstResCb');
-			firstResCb?.(resMsgContent);
-		} else {
-			cb?.(resMsgContent);
-		}
+
 		userItem.historyId = questionRes?.history_id;
 		userItem.content.values = questionRes?.question ?? userItem.content.values;
 		assistantItem.historyId = questionRes?.history_id;
-		assistantItem.sectionAId = finalCalcSectionAId;
-		appendLastMessageContent(resMsgContent);
+		const currentTime = formatShowTimeYear(moment().format('YYYY-MM-DD HH:mm:ss'));
+		assistantItem.createTime = currentTime;
+		assistantItem.content = resMsgContent;
 		setTimeout(() => {
 			// 鏀跺埌鍥炲锛岀户缁粴
 			scrollToBottom();
@@ -838,15 +807,8 @@
 	} catch (error: any) {}
 };
 
-const sendClick = (cb) => {
-	sendChatMessage(messageContent.value, cb);
-};
-const appendLastMessageContent = (content: ChatContent) => {
-	const currentTime = formatShowTimeYear(moment().format('YYYY-MM-DD HH:mm:ss'));
-	if (messageList.value.at(-1)) {
-		messageList.value.at(-1).content = content;
-		messageList.value.at(-1).createTime = currentTime;
-	}
+const sendClick = () => {
+	sendChatMessage(messageContent.value);
 };
 
 const { loadRangeData, onChatListScroll, moreIsLoading, updateLoadIndex } = useScrollLoad({
@@ -867,7 +829,6 @@
 		type: AnswerType.Text,
 		values: activeChatRoom.value?.title,
 	};
-
 	sendChatMessage();
 };
 const scrollToBottom = () => {
@@ -949,23 +910,7 @@
 	}
 	loadAmisSource();
 });
-//#region ====================== 鍏宠仈鏌ヨ ======================
-const relativeQueryClick = async (val) => {
-	sendChatMessage(
-		{
-			type: AnswerType.Text,
-			values: val.question,
-		},
-		undefined,
-		{
-			history_group_id: currentRouteId,
-			question: val.question,
-			call_ext_id: val.call_ext_id,
-			call_ext_args: val.agrs ? JSON.stringify(val.agrs) : null,
-		}
-	);
-};
-//#endregion
+
 //#region ====================== 鍏夋爣杈撳叆涓婁笅绠ご鏄剧ず鍘嗗彶娑堟伅 ======================
 const currentIndex = ref(null);
 const history_data = computed(() => {
@@ -1026,7 +971,6 @@
 //#endregion
 //#region ====================== 鐢ㄦ埛璇㈤棶鐨勯棶棰樿缃负甯哥敤璇� ======================
 const setCommonQuestionInfo = ref({});
-const { toClipboard } = useClipboard();
 
 //鐢ㄦ埛闂璁剧疆涓哄父鐢ㄨ
 const setCommonQuestionClick = (item) => {
diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts
index c3685b7..4d63095 100644
--- a/src/components/chat/hooks/useScrollLoad.ts
+++ b/src/components/chat/hooks/useScrollLoad.ts
@@ -134,7 +134,6 @@
 							role: RoleEnum.assistant,
 							content: parseAnswerContent(item?.answer),
 							state: item.answer_state,
-							sectionAId: mapUser?.section_a_id,
 							createTime: answerTime,
 							isStopMsg: false,
 							stepGroup: (item?.answer?.reports ?? []).map((item) => ({
diff --git a/src/components/chat/model/types.ts b/src/components/chat/model/types.ts
index d6a8f60..0d88a24 100644
--- a/src/components/chat/model/types.ts
+++ b/src/components/chat/model/types.ts
@@ -59,7 +59,6 @@
 	role: RoleEnum;
 	content?: ChatContent;
 	state?: null | '1' | '0';
-	sectionAId?: string;
 	createTime?: string;
 	stepGroup?: { value: StepItem[]; isShow: boolean }[];
 	isStopMsg?: boolean;

--
Gitblit v1.9.3