From 3fd148b35f6109d6295f8dd13dc5d7ea06f864cb Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期三, 17 七月 2024 18:05:36 +0800
Subject: [PATCH] askMore

---
 src/components/chat/Chat.vue       |   34 +++++++++++++++++++++++++++++++---
 src/components/chat/model/types.ts |    8 +++++++-
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index 897cbdf..71ac205 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -16,7 +16,7 @@
 						srcset=""
 					/>
 
-					<div class="flex" :class="{ 'w-full': item.role === RoleEnum.assistant }">
+					<div class="inline-flex flex-col" :class="{ 'w-full': item.role === RoleEnum.assistant }">
 						<div class="relative w-full" v-if="item.content?.values">
 							<div
 								class="text-sm rounded-[6px] p-4 leading-relaxed"
@@ -49,7 +49,20 @@
 							</div>
 						</div>
 
-						<Loding v-else :process="process" />
+						<Loding v-else class="w-12" :process="process" />
+					</div>
+				</div>
+				<div v-if="showAskMore" class="ml-4 mt-5 text-sm">
+					<div class="text-gray-600 mb-5">浣犲彲浠ョ户缁棶鎴戯細</div>
+					<div class="space-y-2 inline-flex flex-col">
+						<div
+							v-for="item in computedMessageList.at(-1).content.askMoreList"
+							:key="item.history_id"
+							class="bg-white p-3 hover:bg-[#c5e0ff] hover:text-[#1c86ff] cursor-pointer rounded-lg"
+							@click="askMoreClick(item)"
+						>
+							{{ item.question }}
+						</div>
 					</div>
 				</div>
 			</div>
@@ -78,6 +91,7 @@
 import router from '/@/router';
 import { activeChatRoom, activeLLMId, activeRoomId, activeSampleId, activeSectionAId, roomConfig } from '/@/stores/chatRoom';
 import { v4 as uuidv4 } from 'uuid';
+import _ from 'lodash';
 
 const chatWidth = '75%';
 
@@ -94,11 +108,19 @@
 	return messageList.value.filter((v) => v.role !== RoleEnum.system);
 });
 
+const showAskMore = computed(() => {
+	if (!computedMessageList.value || computedMessageList.value.length === 0) return false;
+	const last = computedMessageList.value.at(-1);
+	const isShow = last?.role === RoleEnum.assistant && last?.content?.values && last.content?.askMoreList?.length > 0;
+	return isShow;
+});
+
 const parseContent = (res) => {
 	let content: ChatContent = {
 		type: AnswerType.Text,
 		values: '鍙戠敓閿欒锛�',
 	};
+
 	switch (res.answer_type) {
 		case AnswerType.RecordSet:
 			content = {
@@ -140,6 +162,7 @@
 			};
 			break;
 	}
+	content.askMoreList = _.orderBy(res.context_history, [(item) => Number(item.radio)], ['desc']);
 	return content;
 };
 //#region ====================== 鏌ヨ杩涘害 ======================
@@ -229,7 +252,7 @@
 };
 
 const sendChatMessage = async (content: ChatContent = messageContent.value) => {
-	if (!messageContent.value?.values) return;
+	if (!content?.values) return;
 	if (messageList.value.length === 0) {
 		if (activeSampleId.value) {
 			currentSampleId = activeSampleId.value;
@@ -276,6 +299,11 @@
 	}
 };
 
+const askMoreClick = (item) => {
+	if (!item.question) return;
+	sendChatMessage({ type: AnswerType.Text, values: item.question });
+};
+
 onMounted(async () => {
 	const res = await QueryHistoryDetail({
 		history_group_id: currentRouteId,
diff --git a/src/components/chat/model/types.ts b/src/components/chat/model/types.ts
index 6c62a81..490d425 100644
--- a/src/components/chat/model/types.ts
+++ b/src/components/chat/model/types.ts
@@ -33,11 +33,17 @@
 };
 
 export type AnswerStateType = typeof AnswerState;
-
+export type ContextHistory = {
+	/** @description 鏁板瓧瀛楃涓� */
+	ratio:string;
+	history_id:string;
+	question:string;
+}
 export type ChatContent = {
 	type: AnswerType;
 	values: any;
 	error?: string;
+	askMoreList?:ContextHistory[];
 };
 
 export interface ChatMessage {

--
Gitblit v1.9.3