From df0a461ea2018f99ccbc82148f8ae3f6cddaf23b Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期四, 19 十二月 2024 16:49:02 +0800 Subject: [PATCH] 意图分析拆分 --- src/components/chat/Chat.vue | 259 ++++++++++++++++++++++++++++++--------------------- src/components/chat/hooks/useScrollLoad.ts | 12 + src/components/chat/model/types.ts | 3 3 files changed, 160 insertions(+), 114 deletions(-) diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue index 052ae1a..4fc9ca3 100644 --- a/src/components/chat/Chat.vue +++ b/src/components/chat/Chat.vue @@ -33,92 +33,10 @@ <div class="inline-flex flex-col" :class="{ 'w-full': item.role === RoleEnum.assistant }"> <div class="w-full"> <div class="rounded-[6px] p-4 leading-relaxed bg-white"> - <!-- #region ====================== 鎰忓浘鍒嗘瀽 ======================--> - <div class="flex flex-col" v-if="item?.stepList?.length > 0"> - <!-- #region ====================== 鎰忓浘鍒嗘瀽 ======================--> - <div class="flex items-center"> - <span class="mr-2">鎰忓浘鍒嗘瀽锛�</span> - <div - @click="toggleStepList(item)" - class="cursor-pointer border border-gray-300 border-solid w-fit px-2 flex items-center space-x-2 rounded-lg hover:bg-gray-100 active:bg-gray-200" - > - <span> - {{ toggleStepLabel(item) }} - </span> - <span class="ywifont" :class="{ 'ywicon-unfold': !item.stepIsShow, 'ywicon-fold': item.stepIsShow }"></span> - </div> - </div> - <!-- #endregion --> - - <!-- #region ====================== 杩囩▼杈撳嚭 ======================--> - <el-steps v-show="item.stepIsShow" class="mt-3" direction="vertical" :active="activeStep"> - <el-step - :key="`template-${index}`" - v-for="(subItem, index) in item.stepList" - :title="subItem.title" - :status="stepEnumMap[subItem.status]" - > - <template - #icon - v-if="index + 1 === item.stepList.length && isTalking && msgIndex === computedMessageList.length - 1" - > - <span class="ywifont ywicon-loading1 animate-spin !text-[24px]"></span> - </template> - <template #title> - <span class=""> - {{ subItem.title }} - - <span v-if="subItem.ms" class="text-green-600">{{ `锛�${subItem.ms}锛塦 }}</span></span - > - </template> - - <template #description v-if="subItem?.subStep?.length > 0"> - <div class="my-1 flex flex-col gap-1 text-[14px]"> - <div - :key="`${item.historyId}-${index + 1}-${multiChatIndex + 1}`" - v-for="(multiChatItem, multiChatIndex) in subItem.subStep" - > - <component - v-if="multiChatItem.type === MultiChatType.Select" - :order="`${index + 1}-${multiChatIndex + 1}`" - :item="multiChatItem" - :is="multiChatTypeMapCom[multiChatItem.type]" - :disabled=" - !(index + 1 === item.stepList.length && isTalking && msgIndex === computedMessageList.length - 1) - " - /> - <component - v-else-if="multiChatItem.type === MultiChatType.Result" - :is="answerTypeMapCom['summary']" - :data="multiChatItem.data.content.values" - :originData="multiChatItem.data" - /> - <div v-else-if="multiChatItem.type === MultiChatType.Summary" class="ml-4 mt-5 pb-10"> - <div class="text-gray-600 mb-5">浣犲彲浠ョ户缁棶鎴戯細</div> - <div class="space-y-2 inline-flex flex-col"> - <div - v-for="item in multiChatItem.data.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> - </div> - </template> - </el-step> - </el-steps> - <!-- #endregion --> - </div> - <!-- #endregion --> - <!-- #region ====================== 娑堟伅鍐呭 ======================--> - <template v-if="item.content?.values"> + <!-- <template v-if="item.content?.values"> --> <!-- #region ====================== 鎶ラ敊淇℃伅 ======================--> - <div v-if="item.content.errCode === ErrorCode.Message" class="flex-column w-full"> + <div v-if="item.content?.errCode === ErrorCode.Message" class="flex-column w-full"> <p class="text-red-500"> {{ item.content.errMsg }} </p> @@ -142,17 +60,119 @@ <!-- #region ====================== 鍥炵瓟缁勪欢 ======================--> <template v-else> <template v-if="item.content.type === AnswerType.Report"> - <component - v-for="(subItem, index) in item.content.values" - :key="index" - :reportIndex="index" - :conclusion="subItem.conclusion" - :is="answerTypeMapCom[subItem.content.type]" - :data="subItem.content.values" - :originData="subItem" - :historyId="item.historyId" - :isTalking="isTalking && msgIndex === computedMessageList.length - 1" - /> + <div v-for="(num, index) in item?.stepGroup?.length" :key="index"> + <!-- #region ====================== 鎰忓浘鍒嗘瀽 ======================--> + <div class="flex flex-col" v-if="item?.stepGroup?.[index]?.value?.length > 0"> + <!-- #region ====================== 鎰忓浘鍒嗘瀽 ======================--> + <div class="flex items-center"> + <span class="mr-2">鎰忓浘鍒嗘瀽锛�</span> + <div + @click="toggleStepList(item?.stepGroup?.[index])" + class="cursor-pointer border border-gray-300 border-solid w-fit px-2 flex items-center space-x-2 rounded-lg hover:bg-gray-100 active:bg-gray-200" + > + <span> + {{ toggleStepLabel(item?.stepGroup?.[index]) }} + </span> + <span + class="ywifont" + :class="{ + 'ywicon-unfold': !item?.stepGroup?.[index].isShow, + 'ywicon-fold': item?.stepGroup?.[index].isShow, + }" + ></span> + </div> + </div> + <!-- #endregion --> + + <!-- #region ====================== 杩囩▼杈撳嚭 ======================--> + <el-steps + v-show="item?.stepGroup?.[index].isShow" + class="mt-3" + direction="vertical" + :active="activeStep" + > + <el-step + :key="`template-${stepIndex}`" + v-for="(subItem, stepIndex) in item?.stepGroup?.[index].value" + :title="subItem.title" + :status="stepEnumMap[subItem.status]" + > + <template + #icon + v-if=" + stepIndex + 1 === item?.stepGroup?.[index].value.length && + isTalking && + msgIndex === computedMessageList.length - 1 + " + > + <span class="ywifont ywicon-loading1 animate-spin !text-[24px]"></span> + </template> + <template #title> + <span class=""> + {{ subItem.title }} + + <span v-if="subItem.ms" class="text-green-600">{{ `锛�${subItem.ms}锛塦 }}</span></span + > + </template> + + <template #description v-if="subItem?.subStep?.length > 0"> + <div class="my-1 flex flex-col gap-1 text-[14px]"> + <div + :key="`${item.historyId}-${stepIndex + 1}-${multiChatIndex + 1}`" + v-for="(multiChatItem, multiChatIndex) in subItem.subStep" + > + <component + v-if="multiChatItem.type === MultiChatType.Select" + :order="`${stepIndex + 1}-${multiChatIndex + 1}`" + :item="multiChatItem" + :is="multiChatTypeMapCom[multiChatItem.type]" + :disabled=" + !( + stepIndex + 1 === item?.stepGroup?.[index].value.length && + isTalking && + msgIndex === computedMessageList.length - 1 + ) + " + /> + <component + v-else-if="multiChatItem.type === MultiChatType.Result" + :is="answerTypeMapCom['summary']" + :data="multiChatItem.data.content.values" + :originData="multiChatItem.data" + /> + <div v-else-if="multiChatItem.type === MultiChatType.Summary" class="ml-4 mt-5 pb-10"> + <div class="text-gray-600 mb-5">浣犲彲浠ョ户缁棶鎴戯細</div> + <div class="space-y-2 inline-flex flex-col"> + <div + v-for="item in multiChatItem.data.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> + </div> + </template> + </el-step> + </el-steps> + <!-- #endregion --> + </div> + <!-- #endregion --> + + <component + v-if="item.content?.values?.[index]" + :reportIndex="index" + :conclusion="item.content.values[index].conclusion" + :is="answerTypeMapCom[item.content.values[index].content.type]" + :data="item.content.values[index].content.values" + :originData="item.content.values[index]" + :historyId="item.historyId" + :isTalking="isTalking && msgIndex === computedMessageList.length - 1" + /> + </div> </template> <component v-else @@ -181,7 +201,7 @@ </div> </template> <!-- #endregion --> - </template> + <!-- </template> --> <!-- #endregion --> <!-- #region ====================== 闄勫姞鍐呭 ======================--> @@ -435,7 +455,6 @@ break; case AnswerType.Summary: - content = { type: AnswerType.Summary, values: res.summary?.map((item) => { @@ -485,9 +504,9 @@ activeStep.value = -1; }; -const toggleStepLabel = (item: ChatMessage) => (item.stepIsShow ? '鏀惰捣' : '灞曞紑'); -const toggleStepList = (item: ChatMessage) => { - item.stepIsShow = !item.stepIsShow; +const toggleStepLabel = (item: any) => (item.isShow ? '鏀惰捣' : '灞曞紑'); +const toggleStepList = (item: any) => { + item.isShow = !item.isShow; }; //#endregion @@ -563,8 +582,13 @@ }; questionRes = resReport; resolve(resReport); + // 寮�濮嬪鍔犳柊鐨� stepGroup + computedMessageList.value.at(-1).stepGroup.push({ + value: [], + isShow: true, + }); } else { - const lastMsg = computedMessageList.value.at(-1); + const lastMsg = computedMessageList.value.at(-1); // 宸茬粡瑙f瀽杩囦竴娆� reports lastMsg.content.values.push({ @@ -616,7 +640,8 @@ } if (chunkRes.mode === 'question') { - const stepList = computedMessageList.value.at(-1).stepList; + const lastGroup = computedMessageList.value.at(-1).stepGroup.at(-1); + const stepList = lastGroup?.value ?? []; const lastStepItem = stepList.at(-1); if (!lastStepItem.subStep) { lastStepItem.subStep = []; @@ -628,7 +653,9 @@ scrollToBottom(); return; } - const stepList = computedMessageList.value.at(-1).stepList; + + const lastGroup = computedMessageList.value.at(-1).stepGroup.at(-1); + const stepList = lastGroup?.value ?? []; const currentTimeStamp = new Date().getTime(); const ms = toMyFixed(currentTimeStamp - lastTimestamp, 2) + ' ms'; if (chunkRes.mode === 'finish') { @@ -639,12 +666,19 @@ if (stepList?.length >= 1) { stepList.at(-1).ms = ms; + }else{ + const stepGroup = computedMessageList.value.at(-1).stepGroup + if(stepGroup.length > 1){ + const lastStepList = stepGroup.at(-2).value; + lastStepList.at(-1).ms = ms; + } } lastTimestamp = currentTimeStamp; const stepItem = convertProcessItem(chunkRes); stepList.push(stepItem); - + // 寮哄埗瑙﹀彂鏇存柊 + scrollToBottom(); }, { @@ -656,7 +690,10 @@ }) .finally(() => { isTalking.value = false; - computedMessageList.value.at(-1).stepIsShow = false; + // 鏀惰捣鎵�鏈� stepGroup + computedMessageList.value.at(-1).stepGroup.forEach((item) => { + item.isShow = false; + }); resetStep(); }); @@ -711,10 +748,16 @@ const userItem: ChatMessage = { role: RoleEnum.user, content, isChecked: false } as any; const assistantItem: ChatMessage = { role: RoleEnum.assistant, - content: null, + content: { + type: AnswerType.Report, + }, state: AnswerState.Null, - stepList: [], - stepIsShow: true, + stepGroup: [ + { + value: [], + isShow: true, + }, + ], isStopMsg: false, isChecked: false, } as any; diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts index de7cc1b..a9fbb78 100644 --- a/src/components/chat/hooks/useScrollLoad.ts +++ b/src/components/chat/hooks/useScrollLoad.ts @@ -114,9 +114,11 @@ state: item.answer_state, sectionAId: mapUser?.section_a_id, createTime: answerTime, - stepList: convertProcessToStep(item?.answer?.reports?.[0]?.exec_process), - stepIsShow: false, isStopMsg: false, + stepGroup: (item?.answer?.reports ?? []).map((item) => ({ + value: convertProcessToStep(item?.exec_process), + isShow: false, + })), conclusion: item?.answer?.conclusion ?? [], isChecked: false, @@ -155,8 +157,10 @@ historyId: msgValue.history_id, role: RoleEnum.assistant, content: parseAnswerContent(msgValue), - stepList: convertProcessToStep(msgValue?.reports?.[0]?.exec_process), - stepIsShow: false, + stepGroup: (msgValue?.reports ?? []).map((item) => ({ + value: convertProcessToStep(item?.exec_process), + isShow: false, + })), isStopMsg: false, conclusion: msgValue.conclusion ?? [], diff --git a/src/components/chat/model/types.ts b/src/components/chat/model/types.ts index 2c3851d..215f6a5 100644 --- a/src/components/chat/model/types.ts +++ b/src/components/chat/model/types.ts @@ -58,8 +58,7 @@ state?: null | '1' | '0'; sectionAId?: string; createTime?: string; - stepList?: StepItem[]; - stepIsShow?: boolean; + stepGroup?: { value: StepItem[]; isShow: boolean }[]; isStopMsg?: boolean; /** @description 鏄惁琚�夋嫨鍒嗕韩 */ isChecked: boolean; -- Gitblit v1.9.3