mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 20:51:48 +00:00
(improvement)(chat|common|headless|webapp) 结果分析,改写伪流式输出,加快响应速度 (#2395)
This commit is contained in:
@@ -10,7 +10,14 @@ import {
|
||||
SimilarQuestionType,
|
||||
} from '../../common/type';
|
||||
import { createContext, useEffect, useRef, useState } from 'react';
|
||||
import { chatExecute, chatParse, queryData, deleteQuery, switchEntity } from '../../service';
|
||||
import {
|
||||
chatExecute,
|
||||
chatParse,
|
||||
queryData,
|
||||
deleteQuery,
|
||||
switchEntity,
|
||||
getExecuteSummary,
|
||||
} from '../../service';
|
||||
import { PARSE_ERROR_TIP, PREFIX_CLS, SEARCH_EXCEPTION_TIP } from '../../common/constants';
|
||||
import { message, Spin } from 'antd';
|
||||
import IconFont from '../IconFont';
|
||||
@@ -169,7 +176,7 @@ const ChatItem: React.FC<Props> = ({
|
||||
setExecuteLoading(true);
|
||||
}
|
||||
try {
|
||||
const res: any = await chatExecute(msg, conversationId!, parseInfoValue, agentId);
|
||||
const res: any = await chatExecute(msg, conversationId!, parseInfoValue, agentId, true);
|
||||
const valid = updateData(res);
|
||||
onMsgDataLoaded?.(
|
||||
{
|
||||
@@ -180,6 +187,20 @@ const ChatItem: React.FC<Props> = ({
|
||||
valid,
|
||||
isRefresh
|
||||
);
|
||||
const queryId = parseInfoValue.queryId; // 伪流式 大模型输出
|
||||
if (queryId != undefined && res.data.queryState != 'INVALID') {
|
||||
const getSummary = async (data: any, queryId: number) => {
|
||||
const res2: any = await getExecuteSummary(queryId);
|
||||
if (res2.data.queryMode == null) {
|
||||
res2.data = { ...data, textSummary: res2.data.textSummary };
|
||||
setData(res2.data);
|
||||
setTimeout(() => getSummary(data, queryId), 500);
|
||||
} else {
|
||||
setData(res2.data);
|
||||
}
|
||||
};
|
||||
setTimeout(() => getSummary(res.data, queryId), 500);
|
||||
}
|
||||
} catch (e) {
|
||||
const tip = SEARCH_EXCEPTION_TIP;
|
||||
setExecuteTip(SEARCH_EXCEPTION_TIP);
|
||||
@@ -423,6 +444,10 @@ const ChatItem: React.FC<Props> = ({
|
||||
return result;
|
||||
}, {});
|
||||
});
|
||||
if (exportData.length === 0) {
|
||||
message.error('该条消息暂不支持该操作');
|
||||
return;
|
||||
}
|
||||
exportCsvFile(exportData);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -79,7 +79,8 @@ export function chatExecute(
|
||||
queryText: string,
|
||||
chatId: number,
|
||||
parseInfo: ChatContextType,
|
||||
agentId?: number
|
||||
agentId?: number,
|
||||
streamingResult?:boolean
|
||||
) {
|
||||
return axios.post<MsgDataType>(`${prefix}/chat/query/execute`, {
|
||||
queryText,
|
||||
@@ -87,6 +88,15 @@ export function chatExecute(
|
||||
chatId: chatId || DEFAULT_CHAT_ID,
|
||||
queryId: parseInfo.queryId,
|
||||
parseId: parseInfo.id,
|
||||
streamingResult:streamingResult
|
||||
});
|
||||
}
|
||||
|
||||
export function getExecuteSummary(
|
||||
queryId: number
|
||||
) {
|
||||
return axios.post<MsgDataType>(`${prefix}/chat/query/getExecuteSummary`, {
|
||||
queryId: queryId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user