From 2627bea177b22bc803926bba5a29518bfb6ee0eb Mon Sep 17 00:00:00 2001 From: yinbangzhong <zhongbangyin@126.com> Date: 星期六, 24 八月 2024 17:54:54 +0800 Subject: [PATCH] bug fix --- src/views/sessionManager/index.vue | 87 ++++++++++++++++++++++++++++++++++--------- 1 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/views/sessionManager/index.vue b/src/views/sessionManager/index.vue index 96bc8bb..6654627 100644 --- a/src/views/sessionManager/index.vue +++ b/src/views/sessionManager/index.vue @@ -92,25 +92,40 @@ /> </template> <template #content> - <!-- <a-card :class="{ chatItemAnswer: theme === 'light' }">--> - <!-- <div--> - <!-- :class="{ light: theme === 'light' }"--> - <!-- v-html="sessionDetail.content.replace(/\n/g, '<br/>')"--> - <!-- >--> - <!-- </div>--> - <!-- </a-card>--> - <a-textarea - readonly - auto-size - v-model="sessionDetail.content" - :class="{ chatItemAnswer: theme === 'light' }" - :style="{ + <a-card v-if="isExistTip(sessionDetail.content)"> + <div :class="{ chatItemAnswer: theme === 'light' }" + :style="{backgroundColor: theme === 'light' ? '#ffffff' : '#000000'}" style="border: none;display: inline;" v-for="(item,tipIndex) in tipMatch(sessionDetail)" + > + <span v-if="tipIndex == 0"> + {{ sessionDetail.content.substring(0, item.index) }} + <a-tooltip background-color="#3491FA" :content="getTipContent( + messagenList.reference, + index + )"> + <img style="width: 20px;height: 20px" :src="tipImage" /> + </a-tooltip> + </span> + <span v-else> + {{ sessionDetail.content.substring(item.preIndex+item.item.length, item.index) }} + <a-tooltip background-color="#3491FA" :content="getTipContent( + messagenList.reference, + index + )"> + <img style="width: 20px;height: 20px" :src="tipImage" /> + </a-tooltip> + </span> + + </div> + </a-card> + <a-card v-else> + <div :class="{ chatItemAnswer: theme === 'light' }" + :style="{ backgroundColor: theme === 'light' ? '#ffffff' : '#000000', - }" - style="border: none" - > - </a-textarea> + }" style="border: none"> + {{ sessionDetail.content }} + </div> + </a-card> </template> <!-- <div>{{ sessionDetail.role === 'assistant' }}</div> --> <template #actions> @@ -407,6 +422,8 @@ import pdfImg3 from '@/assets/session/execl.png'; import pdfImg4 from '@/assets/session/icon-txt.png'; import pdfImg5 from '@/assets/session/txt.png'; + import tipImage from '@/assets/session/tip.png'; + import { number } from "@intlify/core-base"; // const url = ref('../../assets/session/PDF.png'); @@ -476,8 +493,28 @@ } }; let dataItem = []; - const getTxt = (data, role, message, index) => { + const isExistTip=(message:string):boolean=>{ if (/##[0-9]\$\$/.test(message)) { + return true; + } else { + return false; + } + } + + const tipMatch = (session: any): any[] => { + //match session.content涓殑##[0-9]$$鐨勭储寮� + let indexs: any[] = []; + let preTip=0; + session.content.match(/##([0-9]+)\$\$/g)?.map((item) => { + let i = session.content.indexOf(item); + indexs.push({ index: i, item: item, preIndex: preTip }); + preTip = i; + }); + return indexs; + } + + const getTxt = (data, role, message, index) => { + if (isExistTip(message)) { if (role == 'assistant' && index) { let i = index / 2 - 1 > 0 ? index / 2 - 1 : 0; dataItem = data[i].doc_aggs; @@ -489,6 +526,20 @@ return dataItem; }; + const getTipContent = (data, index): string => { + let maxSimilarityContent = ""; + let i = index / 2 - 1 > 0 ? index / 2 - 1 : 0; + let maxSimilarity = 0; + data[i].chunks.forEach((chunk) => { + if (chunk.similarity > maxSimilarity) { + maxSimilarity = chunk.similarity; + maxSimilarityContent = chunk.content_with_weight; + } + } + ); + return maxSimilarityContent; + }; + const clickHref = (item) => { // return Message.warning('鏆傛棤娉曟煡鐪�'); // window.open(`/api/v1/document/get/${item.doc_id}`, '_blank'); -- Gitblit v1.8.0