Chat perf test (#2252)
* perf: optimize chat init api (#2233) * perf: optimize the chat/init api * perf: 添加团队和分享api的优化 * perf: api写法优化 * perf: api写法优化 * perf: 完善细节 * perf: 添加auth字段 * perf: 优雅的写法🥳 * fix: Fix the bug in debugging Tag (#2250) * fix: 修复调试tag不显示bug * perf * perf: 优化代码 * fix: 返回新对象 * fix: show tag error --------- Co-authored-by: papapatrick <109422393+Patrickill@users.noreply.github.com>
This commit is contained in:
43
projects/app/src/global/core/chat/utils.ts
Normal file
43
projects/app/src/global/core/chat/utils.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
|
||||
import { ChatHistoryItemResType, ChatItemType } from '@fastgpt/global/core/chat/type';
|
||||
import { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||
|
||||
const isLLMNode = (item: ChatHistoryItemResType) =>
|
||||
item.moduleType === FlowNodeTypeEnum.chatNode || item.moduleType === FlowNodeTypeEnum.tools;
|
||||
|
||||
export function transformPreviewHistories(histories: ChatItemType[]) {
|
||||
return histories.map((item) => {
|
||||
return {
|
||||
...addStatisticalDataToHistoryItem(item),
|
||||
responseData: undefined
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function addStatisticalDataToHistoryItem(historyItem: ChatItemType) {
|
||||
if (historyItem.obj !== ChatRoleEnum.AI) return historyItem;
|
||||
if (historyItem.totalQuoteList !== undefined) return historyItem;
|
||||
const flatResData: ChatHistoryItemResType[] =
|
||||
historyItem.responseData
|
||||
?.map((item) => {
|
||||
if (item.pluginDetail || item.toolDetail) {
|
||||
return [item, ...(item.pluginDetail || []), ...(item.toolDetail || [])];
|
||||
}
|
||||
return item;
|
||||
})
|
||||
.flat() || [];
|
||||
return {
|
||||
...historyItem,
|
||||
llmModuleAccount: flatResData.filter(isLLMNode).length,
|
||||
totalQuoteList: flatResData
|
||||
.filter((item) => item.moduleType === FlowNodeTypeEnum.datasetSearchNode)
|
||||
.map((item) => item.quoteList)
|
||||
.flat()
|
||||
.filter(Boolean) as SearchDataResponseItemType[],
|
||||
totalRunningTime: Number(
|
||||
flatResData.reduce((sum, item) => sum + (item.runningTime || 0), 0).toFixed(2)
|
||||
),
|
||||
historyPreviewLength: flatResData.find(isLLMNode)?.historyPreview?.length
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user