wujingjing
2025-03-04 92d2ea48d343fc00d81905167d033c40200ea716
src/components/chat/Chat.vue
@@ -76,7 +76,7 @@
} from '/@/stores/chatRoom';
import emitter from '/@/utils/mitt';
import { useCompRef } from '/@/utils/types';
import { toMyFixed } from '/@/utils/util';
import { toFormData, toMyFixed } from '/@/utils/util';
import { useLoadData } from './hooks/useLoadData';
import { useSyncMsg } from './hooks/useSyncMsg';
import { getCurrentPosition } from '/@/utils/brower';
@@ -85,7 +85,16 @@
const scrollToBottom = () => {
   containerRef.value?.scrollToBottom();
};
const { loadReplyData, parseContent, parseExtraContent, convertProcessItem, convertProcessToStep, formatShowTimeYear } = useLoadData();
const {
   loadReplyData,
   parseContent,
   parseExtraContent,
   convertProcessItem,
   convertProcessToStep,
   convertAttach,
   formatShowTimeYear,
   getStepGroupList,
} = useLoadData();
const voicePageIsShow = ref(false);
let isTalking = ref(false);
const chatWidth = computed(() => containerRef.value?.chatWidth);
@@ -133,6 +142,10 @@
      raw_mode: roomConfig.value?.[currentRouteId]?.isAnswerByLLM ?? false,
      ...judgeParams,
   } as any;
   const tableList = attachList.value.filter((item) => item.type === 'table').map((item) => item.model);
   if (tableList?.length > 0) {
      params.tables = JSON.stringify(tableList);
   }
   // if (!position) {
   //    const loadingInstance = ElLoadingService({
@@ -158,7 +171,12 @@
      params.sample_id = currentSampleId;
      currentSampleId = '';
   }
   const formDataParams = toFormData(params);
   const fileList = attachList.value.filter((item) => item.type === 'file').map((item) => item.model);
   for (const item of fileList) {
      formDataParams.append('files', item.file);
   }
   clearAttach();
   let lastTimestamp = new Date().getTime();
   questionRes = {};
   let lastIsResult = false;
@@ -178,7 +196,7 @@
         return isEmpty;
      };
      questionStreamByPost(
         params,
         formDataParams,
         (chunkRes) => {
            Logger.info('chunk response:\n\n' + JSON.stringify(chunkRes));
            if (chunkRes.mode === 'result') {
@@ -308,7 +326,7 @@
               });
               lastIsResult = false;
            }
            const lastGroup = computedMessageList.value.at(-1).stepGroup[0];
            const lastGroup = getLastGroup();
            const stepList = lastGroup?.value ?? [];
            const currentTimeStamp = new Date().getTime();
            if (chunkRes.mode === 'finish') {
@@ -323,14 +341,6 @@
               const ms = toMyFixed(currentTimeStamp - lastTimestamp, 2) + ' ms';
               stepList.at(-1).ms = ms;
            } else {
               const stepGroup = computedMessageList.value.at(-1).stepGroup;
               if (stepGroup.length > 1) {
                  const lastStepList = stepGroup.at(-2).value;
                  const ms = toMyFixed(currentTimeStamp - lastTimestamp, 2) + ' ms';
                  lastStepList.at(-1).ms = ms;
               }
            }
            if (!streamOutputIsStart) {
@@ -341,7 +351,9 @@
               stepList.push(stepItem);
            } else {
               const lastItem = stepList.at(-1);
               lastItem.title += chunkRes.value ?? '';
               if (lastItem) {
                  lastItem.title += chunkRes.value ?? '';
               }
            }
            if (chunkRes.mode === 'begin_stream') {
@@ -376,12 +388,14 @@
   const content = parseContent(questionRes, true);
   return content;
};
const clearMessageContent = () =>
   (messageContent.value = {
const playBarRef = useCompRef(PlayBar);
const attachList = computed(() => playBarRef.value?.attachList ?? []);
const clearMessageContent = () => {
   messageContent.value = {
      type: AnswerType.Text,
      values: '',
   });
   };
};
let currentSampleId = '';
@@ -408,7 +422,7 @@
const addChatItem = (content: ChatContent) => {
   isTalking.value = true;
   const userItem: ChatMessage = { role: RoleEnum.user, content, isChecked: false } as any;
   const userItem: ChatMessage = { role: RoleEnum.user, content, isChecked: false, attachList: attachList.value } as any;
   const assistantItem: ChatMessage = {
      role: RoleEnum.assistant,
      content: {
@@ -421,6 +435,7 @@
            isShow: true,
         },
      ],
      isStopMsg: false,
      isChecked: false,
   } as any;
@@ -430,6 +445,13 @@
   messageList.value.push(assistantItem);
   scrollToBottom();
   return [userItem, assistantItem];
};
/**
 * 清除附件
 */
const clearAttach = () => {
   playBarRef.value?.clearAttach();
};
const sendChatMessage = async (content: ChatContent = messageContent.value) => {
@@ -534,6 +556,7 @@
         type: AnswerType.Text,
         values: msgValue.question,
      },
      attachList: convertAttach(msgValue),
      isChecked: false,
   };
@@ -541,10 +564,8 @@
      historyId: msgValue.history_id,
      role: RoleEnum.assistant,
      content: parseContent(msgValue),
      stepGroup: (msgValue?.reports ?? []).map((item) => ({
         value: convertProcessToStep(item?.exec_process),
         isShow: false,
      })),
      stepGroup: getStepGroupList(msgValue?.reports ?? []),
      isStopMsg: false,
      conclusion: msgValue.conclusion ?? [],
@@ -593,7 +614,6 @@
   messageContent.value.values = content;
};
//#endregion
const playBarRef = useCompRef(PlayBar);
//用户问题设置为常用语
const setCommonPhraseClick = (item) => {
   playBarRef.value.addPhrase(item);