From 7c923ce70ccbd865206f6e3c53cb64fbe6e7b84b Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期三, 26 二月 2025 15:58:23 +0800 Subject: [PATCH] 修复 bug,历史展示 stream --- src/components/chat/hooks/useLoadData.ts | 55 ++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/components/chat/hooks/useLoadData.ts b/src/components/chat/hooks/useLoadData.ts index 3c90982..ce793eb 100644 --- a/src/components/chat/hooks/useLoadData.ts +++ b/src/components/chat/hooks/useLoadData.ts @@ -108,6 +108,26 @@ return content; }; + + /** + * 鑾峰彇姝ラ缁勫垪琛� + * @param reports + * @returns + */ + const getStepGroupList = (reports: any[]) => { + const stepGroupList = (reports ?? []).map((item) => ({ + value: convertProcessToStep(item?.exec_process), + isShow: false, + })); + /** @description 鍏ㄩ儴鏀惧埌绗竴涓� */ + stepGroupList.map((item, index) => { + if (index !== 0) { + stepGroupList[0].value.push(...item.value); + item.value = []; + } + }); + return stepGroupList; + }; const formatShowTimeYear = (str: string) => { const date = moment(str); const now = moment(); @@ -153,8 +173,8 @@ } as ChatMessage; }); const resList = await Promise.all( - (userMsg ?? []).map((item) => { - userItemIdMap.set(item.history_id, item); + (userMsg ?? []).map((item, index) => { + userItemIdMap.set(index, item); return getAnswerById(item.history_id); }) ); @@ -164,21 +184,10 @@ const currentUserMsg = tmpMessageList[insertIndex - 1]; currentUserMsg.content.values = item?.answer?.question ?? currentUserMsg.content.values; - const mapUser = userItemIdMap.get(item.answer?.history_id); + const mapUser = userItemIdMap.get(index); + const historyId = mapUser?.history_id; const answerTime = formatShowTimeYear(mapUser?.create_time); - //#region ====================== 閮藉悎骞跺埌绗竴涓紝鍚庨潰閮芥槸绌哄3瀛� ====================== - const stepGroupList = (item?.answer?.reports ?? []).map((item) => ({ - value: convertProcessToStep(item?.exec_process), - isShow: false, - })); - stepGroupList.map((item, index) => { - if (index !== 0) { - stepGroupList[0].value.push(...item.value); - item.value = []; - } - }); - //#endregion tmpMessageList.splice( insertIndex, @@ -186,7 +195,7 @@ item.answer === null ? null : { - historyId: item.answer?.history_id, + historyId: historyId, role: RoleEnum.assistant, content: parseContent(item?.answer), state: item.answer_state, @@ -196,7 +205,7 @@ // value: convertProcessToStep(item?.exec_process), // isShow: false, // })) - stepGroup: stepGroupList, + stepGroup: getStepGroupList(item?.answer?.reports ?? []), conclusion: item?.answer?.conclusion ?? [], isChecked: false, @@ -220,6 +229,8 @@ } as StepItem; }; const convertProcessToStep = (process: any[], isHistory = true) => { + let streamIsStart = false; + const stepList = (process ?? []).reduce((preVal, curVal) => { if (curVal.mode === 'question') { if (isHistory) return preVal; @@ -232,6 +243,15 @@ type: MultiChatType.Select, }; last.subStep.push(sub); + } else if (curVal.mode === 'begin_stream') { + streamIsStart = true; + const cur = convertProcessItem(curVal); + preVal.push(cur); + } else if (curVal.mode === 'end_stream') { + streamIsStart = false; + } else if (streamIsStart) { + const last = preVal.at(-1); + last.title += curVal.value; } else { const cur = convertProcessItem(curVal); preVal.push(cur); @@ -247,5 +267,6 @@ convertProcessToStep, convertProcessItem, formatShowTimeYear, + getStepGroupList }; }; -- Gitblit v1.9.3