From 768a63bdae68f9440d4b7f5768c3ea7f9308f2ab Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期三, 06 十一月 2024 14:08:58 +0800 Subject: [PATCH] 流更改 --- src/components/chat/Chat.vue | 51 ++++++++++++---- src/components/chat/chatComponents/normalTextCom/NormalTextCom.vue | 2 src/components/chat/hooks/useScrollLoad.ts | 4 src/components/chat/chatComponents/knowledgeCom/KnowledgeCom.vue | 2 src/components/chat/chatComponents/summaryCom/ReportDlg.vue | 2 src/components/chat/chatComponents/common.ts | 3 + src/components/chat/model/types.ts | 5 + src/components/chat/chatComponents/summaryCom/SummaryCom.vue | 55 +++++++++++------- src/theme/app.scss | 6 ++ 9 files changed, 89 insertions(+), 41 deletions(-) diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue index 8d4f7fd..05b6846 100644 --- a/src/components/chat/Chat.vue +++ b/src/components/chat/Chat.vue @@ -84,7 +84,12 @@ </div> </div> <template v-else> - <component :is="answerTypeMapCom[item.content.type]" :data="item.content.values" :originData="item" /> + <component + :conclusion="item.conclusion" + :is="answerTypeMapCom[item.content.type]" + :data="item.content.values" + :originData="item" + /> <div v-if="item.role === RoleEnum.assistant && item.content.origin?.ext_call_list" class="flex font-bold items-center mt-6" @@ -412,20 +417,42 @@ // queryProcess(); resetStep(); let res = null; - await questionStreamByPost(params, (chunkRes) => { - Logger.info('chunk response锛歕n\n' + JSON.stringify(chunkRes)); - if (chunkRes.mode === 'result') { - res = chunkRes.value; - } else { + + const resultP = new Promise(async (resolve, reject) => { + await questionStreamByPost(params, (chunkRes) => { + Logger.info('chunk response锛歕n\n' + JSON.stringify(chunkRes)); + if (chunkRes.mode === 'result') { + res = chunkRes.value; + resolve(res); + chunkRes.value = '鍑嗗鏁版嵁鍒嗘瀽'; + } + + if (chunkRes.mode === 'conclusion') { + computedMessageList.value.at(-1).conclusion = chunkRes.value; + chunkRes.value = '鍒嗘瀽缁撴潫'; + } + + if (chunkRes.mode === 'finish') { + isTalking.value = false; + return; + } + const stepItem = convertProcessItem(chunkRes); computedMessageList.value.at(-1).stepList.push(stepItem); scrollToBottom(); - } - }).finally(() => { - computedMessageList.value.at(-1).stepIsShow = false; - resetStep(); + }) + .catch((err) => { + throw err; + }) + .finally(() => { + isTalking.value = false; + + computedMessageList.value.at(-1).stepIsShow = false; + resetStep(); + }); }); - questionRes = res; + + questionRes = await resultP; const content = parseContent(res); return content; }; @@ -502,8 +529,6 @@ // type: AnswerType.Text, // values: '鍙戠敓閿欒锛�', // }); - } finally { - isTalking.value = false; } }; diff --git a/src/components/chat/chatComponents/common.ts b/src/components/chat/chatComponents/common.ts index ebaddee..14cbd0f 100644 --- a/src/components/chat/chatComponents/common.ts +++ b/src/components/chat/chatComponents/common.ts @@ -55,6 +55,9 @@ originData: { type: Object as PropType<any>, }, + conclusion:{ + type:Array as PropType<Array<any>> + } } as const); export type ChatComPropsType = ExtractPropTypes<typeof chatComProps>; diff --git a/src/components/chat/chatComponents/knowledgeCom/KnowledgeCom.vue b/src/components/chat/chatComponents/knowledgeCom/KnowledgeCom.vue index dff677d..c2fae84 100644 --- a/src/components/chat/chatComponents/knowledgeCom/KnowledgeCom.vue +++ b/src/components/chat/chatComponents/knowledgeCom/KnowledgeCom.vue @@ -1,7 +1,7 @@ <template> <div class="space-y-7"> <div v-for="(item, index) in data" :key="index"> - <div v-html="md.render(item.answer)"></div> + <div class="markdown-it" v-html="md.render(item.answer)"></div> <div class="space-y-1 mt-2"> <div v-for="(cItem, index) in item.contexts" :key="index"> <div class="text-blue-500 cursor-pointer inline-block" @click="pageLinkClick(cItem)"> diff --git a/src/components/chat/chatComponents/normalTextCom/NormalTextCom.vue b/src/components/chat/chatComponents/normalTextCom/NormalTextCom.vue index 46eeafa..ae7dff7 100644 --- a/src/components/chat/chatComponents/normalTextCom/NormalTextCom.vue +++ b/src/components/chat/chatComponents/normalTextCom/NormalTextCom.vue @@ -1,5 +1,5 @@ <template> - <div v-html="md.render(data)"></div> + <div class="markdown-it" v-html="md.render(data)"></div> </template> <script setup lang="ts"> diff --git a/src/components/chat/chatComponents/summaryCom/ReportDlg.vue b/src/components/chat/chatComponents/summaryCom/ReportDlg.vue index 7992052..a56cb92 100644 --- a/src/components/chat/chatComponents/summaryCom/ReportDlg.vue +++ b/src/components/chat/chatComponents/summaryCom/ReportDlg.vue @@ -1,7 +1,7 @@ <template> <yw-dialog headerIcon="ele-Copy" v-model="isShow" :showFooter="false" width="810" :title="title"> <div class="max-h-[2/3vh]"> - <div class="border" v-html="md.render(report ?? '')"></div> + <div class="border markdown-it" v-html="md.render(report ?? '')"></div> <i @click="copyInfo(report ?? '')" class="ywifont ywicon-copy text-blue-400 !text-[25px] cursor-pointer absolute bottom-10 right-10" diff --git a/src/components/chat/chatComponents/summaryCom/SummaryCom.vue b/src/components/chat/chatComponents/summaryCom/SummaryCom.vue index 25b731a..c4ccf4d 100644 --- a/src/components/chat/chatComponents/summaryCom/SummaryCom.vue +++ b/src/components/chat/chatComponents/summaryCom/SummaryCom.vue @@ -2,7 +2,7 @@ <div class="w-full space-y-3"> <template v-if="parsedData && parsedData.length > 0"> <template v-for="(item, index) in parsedData" :key="item.id"> - <el-button type="primary" v-if="showReportIndex.includes(index) && conclusion.length > 0" @click="showAgentReport(index)">鎶ュ憡</el-button> + <!-- <el-button type="primary" v-if="showReportIndex.includes(index) && conclusion.length > 0" @click="showAgentReport(index)">鎶ュ憡</el-button> --> <component ref="componentRef" :id="item.id" @@ -14,9 +14,10 @@ :tableLimitHeight="tableLimitHeight" @updateQuery="(res) => updateRecordSet(index, res)" ></component> + <div class="max-h-[2/3vh] markdown-it" v-if="showReportIndex.includes(index) && conclusion?.length > 0" v-html="md.render(getReport(index))"></div> </template> </template> - <ReportDlg v-model="infoDlgIsShow" :report="report" :agentKey="agentKey"></ReportDlg> + <!-- <ReportDlg v-model="infoDlgIsShow" :report="report" :agentKey="agentKey"></ReportDlg> --> </div> </template> @@ -27,9 +28,9 @@ // import AmisPageTest from './components/amisPage/AmisPageTest.vue'; import ReportDlg from './ReportDlg.vue'; +import { md } from '../../libs/markdown'; const props = defineProps(chatComProps); const tableLimitHeight = document.body.clientHeight * 0.7; - const parsedData = computed<any[]>(() => { const newData = (props.data ?? []).map((item) => { if (item.type === SummaryAnswerType.RecordSet && item.chart === 'table') { @@ -42,16 +43,19 @@ // 闇�瑕佸睍绀� report 鐨� 绱㈠紩 const showReportIndex = computed(() => { - const agentKeySet = new Set(); - const indexList = []; + const agentKeyMap = new Map<string, number>(); parsedData.value.forEach((value, index) => { if (value?.agent_key) { - if (!agentKeySet.has(value.agent_key)) { - agentKeySet.add(value.agent_key); - indexList.push(index); - } + // 鍙栨渶鍚庝竴娆′綔涓虹粨璁� + agentKeyMap.set(value.agent_key, index); + // if (!agentKeySet.has(value.agent_key)) { + // agentKeySet.add(value.agent_key); + // indexList.push(index); + // } } }); + const indexList = Array.from(agentKeyMap.values()); + return indexList; }); @@ -62,19 +66,28 @@ item?.updateAll(triggerIndex, res); } }; -const infoDlgIsShow = ref(false); -const report = ref(null); -const agentKey = ref(''); - -const conclusion = computed(() => props.originData?.content?.origin?.conclusion ?? []); -const showAgentReport = (agentStartIndex) => { - const agent = parsedData.value[agentStartIndex]; - agentKey.value = agent.agent_key; - const foundReport = conclusion.value.find((item) => item.agent_key === agentKey.value); - report.value = foundReport?.report; - - infoDlgIsShow.value = true; +const getReport = (agentEndIndex) => { + const agent = parsedData.value[agentEndIndex]; + const agentKey = agent.agent_key; + // debugger; + const foundReport = props.conclusion.find((item) => item.agent_key === agentKey); + const report = foundReport?.report ??''; + return report }; +// const infoDlgIsShow = ref(false); +// const report = ref(null); + +// const agentKey = ref(''); + +// const conclusion = computed(() => props.originData?.content?.origin?.conclusion ?? []); +// const showAgentReport = (agentStartIndex) => { +// const agent = parsedData.value[agentStartIndex]; +// agentKey.value = agent.agent_key; +// const foundReport = conclusion.value.find((item) => item.agent_key === agentKey.value); +// report.value = foundReport?.report; + +// infoDlgIsShow.value = true; +// }; </script> <style scoped lang="scss"></style> diff --git a/src/components/chat/hooks/useScrollLoad.ts b/src/components/chat/hooks/useScrollLoad.ts index 7cd7fe6..2dcc71d 100644 --- a/src/components/chat/hooks/useScrollLoad.ts +++ b/src/components/chat/hooks/useScrollLoad.ts @@ -79,7 +79,6 @@ const currentUserMsg = tmpMessageList[insertIndex - 1]; currentUserMsg.content.values = item?.answer?.question ?? currentUserMsg.content.values; - const mapUser = userItemIdMap.get(item.answer?.history_id); const answerTime = formatShowTimeYear.value(mapUser?.create_time); @@ -96,7 +95,8 @@ sectionAId: mapUser?.section_a_id, createTime: answerTime, stepList: convertProcessToStep(item?.answer?.exec_process), - stepIsShow:false + stepIsShow:false, + conclusion:item?.answer?.conclusion ??[], } ); i++; diff --git a/src/components/chat/model/types.ts b/src/components/chat/model/types.ts index e02dd02..e26f603 100644 --- a/src/components/chat/model/types.ts +++ b/src/components/chat/model/types.ts @@ -56,8 +56,9 @@ state?: null | '1' | '0'; sectionAId?:string, createTime?:string, - stepList:StepItem[] - stepIsShow:boolean + stepList:StepItem[], + stepIsShow:boolean, + conclusion:any[] } export const roleImageMap = { diff --git a/src/theme/app.scss b/src/theme/app.scss index d31562b..40b0b2b 100644 --- a/src/theme/app.scss +++ b/src/theme/app.scss @@ -6,6 +6,12 @@ box-sizing: border-box; outline: none !important; } +.markdown-it{ + // 涓婇潰鐨� padding 0 浼氬奖鍝� markdown 涓殑鍐呭 + ul{ + padding-inline-start: 40px; + } +} :root { --next-color-white: #ffffff; -- Gitblit v1.9.3