mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Call the interface to stop the output of the large model #10997 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -54,6 +54,7 @@ export const enum AgentApiAction {
|
|||||||
SetAgentSetting = 'setAgentSetting',
|
SetAgentSetting = 'setAgentSetting',
|
||||||
FetchPrompt = 'fetchPrompt',
|
FetchPrompt = 'fetchPrompt',
|
||||||
CancelDataflow = 'cancelDataflow',
|
CancelDataflow = 'cancelDataflow',
|
||||||
|
CancelCanvas = 'cancelCanvas',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EmptyDsl = {
|
export const EmptyDsl = {
|
||||||
@ -734,3 +735,20 @@ export const useCancelDataflow = () => {
|
|||||||
|
|
||||||
// return { list: data, loading };
|
// return { list: data, loading };
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
export function useCancelConversation() {
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
isPending: loading,
|
||||||
|
mutateAsync,
|
||||||
|
} = useMutation({
|
||||||
|
mutationKey: [AgentApiAction.CancelCanvas],
|
||||||
|
mutationFn: async (taskId: string) => {
|
||||||
|
const ret = await agentService.cancelCanvas(taskId);
|
||||||
|
|
||||||
|
return ret?.data?.code;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { data, loading, cancelConversation: mutateAsync };
|
||||||
|
}
|
||||||
|
|||||||
@ -674,7 +674,6 @@ General:实体和关系提取提示来自 GitHub - microsoft/graphrag:基于
|
|||||||
chatSetting: '聊天设置',
|
chatSetting: '聊天设置',
|
||||||
avatarHidden: '隐藏头像',
|
avatarHidden: '隐藏头像',
|
||||||
locale: '地区',
|
locale: '地区',
|
||||||
tocEnhance: '目录增强',
|
|
||||||
tocEnhanceTip: `解析文档时生成了目录信息(见General方法的‘启用目录抽取’),让大模型返回和用户问题相关的目录项,从而利用目录项拿到相关chunk,对这些chunk在排序中进行加权。这种方法来源于模仿人类查询书本中知识的行为逻辑`,
|
tocEnhanceTip: `解析文档时生成了目录信息(见General方法的‘启用目录抽取’),让大模型返回和用户问题相关的目录项,从而利用目录项拿到相关chunk,对这些chunk在排序中进行加权。这种方法来源于模仿人类查询书本中知识的行为逻辑`,
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
|
|||||||
@ -45,6 +45,7 @@ import {
|
|||||||
useShowDrawer,
|
useShowDrawer,
|
||||||
useShowLogSheet,
|
useShowLogSheet,
|
||||||
} from '../hooks/use-show-drawer';
|
} from '../hooks/use-show-drawer';
|
||||||
|
import { useStopMessageUnmount } from '../hooks/use-stop-message';
|
||||||
import { LogSheet } from '../log-sheet';
|
import { LogSheet } from '../log-sheet';
|
||||||
import RunSheet from '../run-sheet';
|
import RunSheet from '../run-sheet';
|
||||||
import { ButtonEdge } from './edge';
|
import { ButtonEdge } from './edge';
|
||||||
@ -154,8 +155,11 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) {
|
|||||||
currentEventListWithoutMessageById,
|
currentEventListWithoutMessageById,
|
||||||
clearEventList,
|
clearEventList,
|
||||||
currentMessageId,
|
currentMessageId,
|
||||||
|
currentTaskId,
|
||||||
} = useCacheChatLog();
|
} = useCacheChatLog();
|
||||||
|
|
||||||
|
const { stopMessage } = useStopMessageUnmount(chatVisible, currentTaskId);
|
||||||
|
|
||||||
const { showLogSheet, logSheetVisible, hideLogSheet } = useShowLogSheet({
|
const { showLogSheet, logSheetVisible, hideLogSheet } = useShowLogSheet({
|
||||||
setCurrentMessageId,
|
setCurrentMessageId,
|
||||||
});
|
});
|
||||||
@ -171,9 +175,11 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!chatVisible) {
|
if (!chatVisible) {
|
||||||
|
stopMessage(currentTaskId);
|
||||||
clearEventList();
|
clearEventList();
|
||||||
}
|
}
|
||||||
}, [chatVisible, clearEventList]);
|
}, [chatVisible, clearEventList, currentTaskId, stopMessage]);
|
||||||
|
|
||||||
const setLastSendLoadingFunc = (loading: boolean, messageId: string) => {
|
const setLastSendLoadingFunc = (loading: boolean, messageId: string) => {
|
||||||
if (messageId === currentMessageId) {
|
if (messageId === currentMessageId) {
|
||||||
setLastSendLoading(loading);
|
setLastSendLoading(loading);
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import {
|
|||||||
useIsTaskMode,
|
useIsTaskMode,
|
||||||
useSelectBeginNodeDataInputs,
|
useSelectBeginNodeDataInputs,
|
||||||
} from '../hooks/use-get-begin-query';
|
} from '../hooks/use-get-begin-query';
|
||||||
|
import { useStopMessage } from '../hooks/use-stop-message';
|
||||||
import { BeginQuery } from '../interface';
|
import { BeginQuery } from '../interface';
|
||||||
import useGraphStore from '../store';
|
import useGraphStore from '../store';
|
||||||
import { receiveMessageError } from '../utils';
|
import { receiveMessageError } from '../utils';
|
||||||
@ -243,6 +244,14 @@ export const useSendAgentMessage = ({
|
|||||||
fileList,
|
fileList,
|
||||||
} = useSetUploadResponseData();
|
} = useSetUploadResponseData();
|
||||||
|
|
||||||
|
const { stopMessage } = useStopMessage();
|
||||||
|
|
||||||
|
const stopConversation = useCallback(() => {
|
||||||
|
const taskId = answerList.at(0)?.task_id;
|
||||||
|
stopOutputMessage();
|
||||||
|
stopMessage(taskId);
|
||||||
|
}, [answerList, stopMessage, stopOutputMessage]);
|
||||||
|
|
||||||
const sendMessage = useCallback(
|
const sendMessage = useCallback(
|
||||||
async ({
|
async ({
|
||||||
message,
|
message,
|
||||||
@ -321,7 +330,7 @@ export const useSendAgentMessage = ({
|
|||||||
|
|
||||||
// reset session
|
// reset session
|
||||||
const resetSession = useCallback(() => {
|
const resetSession = useCallback(() => {
|
||||||
stopOutputMessage();
|
stopConversation();
|
||||||
resetAnswerList();
|
resetAnswerList();
|
||||||
setSessionId(null);
|
setSessionId(null);
|
||||||
if (isTaskMode) {
|
if (isTaskMode) {
|
||||||
@ -330,7 +339,7 @@ export const useSendAgentMessage = ({
|
|||||||
removeAllMessagesExceptFirst();
|
removeAllMessagesExceptFirst();
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
stopOutputMessage,
|
stopConversation,
|
||||||
resetAnswerList,
|
resetAnswerList,
|
||||||
isTaskMode,
|
isTaskMode,
|
||||||
removeAllMessages,
|
removeAllMessages,
|
||||||
@ -432,7 +441,7 @@ export const useSendAgentMessage = ({
|
|||||||
handlePressEnter,
|
handlePressEnter,
|
||||||
handleInputChange,
|
handleInputChange,
|
||||||
removeMessageById,
|
removeMessageById,
|
||||||
stopOutputMessage,
|
stopOutputMessage: stopConversation,
|
||||||
send,
|
send,
|
||||||
sendFormMessage,
|
sendFormMessage,
|
||||||
resetSession,
|
resetSession,
|
||||||
|
|||||||
@ -73,6 +73,10 @@ export function useCacheChatLog() {
|
|||||||
[messageIdPool],
|
[messageIdPool],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const currentTaskId = useMemo(() => {
|
||||||
|
return eventList.at(-1)?.task_id;
|
||||||
|
}, [eventList]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
eventList,
|
eventList,
|
||||||
currentEventListWithoutMessage,
|
currentEventListWithoutMessage,
|
||||||
@ -84,5 +88,6 @@ export function useCacheChatLog() {
|
|||||||
filterEventListByMessageId,
|
filterEventListByMessageId,
|
||||||
setCurrentMessageId,
|
setCurrentMessageId,
|
||||||
currentMessageId,
|
currentMessageId,
|
||||||
|
currentTaskId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
36
web/src/pages/agent/hooks/use-stop-message.ts
Normal file
36
web/src/pages/agent/hooks/use-stop-message.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { useCancelConversation } from '@/hooks/use-agent-request';
|
||||||
|
import { useCallback, useEffect } from 'react';
|
||||||
|
|
||||||
|
export function useStopMessage() {
|
||||||
|
const { cancelConversation } = useCancelConversation();
|
||||||
|
|
||||||
|
const stopMessage = useCallback(
|
||||||
|
(taskId?: string) => {
|
||||||
|
if (taskId) {
|
||||||
|
cancelConversation(taskId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[cancelConversation],
|
||||||
|
);
|
||||||
|
|
||||||
|
return { stopMessage };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useStopMessageUnmount(chatVisible: boolean, taskId?: string) {
|
||||||
|
const { stopMessage } = useStopMessage();
|
||||||
|
|
||||||
|
const handleBeforeUnload = useCallback(() => {
|
||||||
|
if (chatVisible) {
|
||||||
|
stopMessage(taskId);
|
||||||
|
}
|
||||||
|
}, [chatVisible, stopMessage, taskId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
};
|
||||||
|
}, [handleBeforeUnload]);
|
||||||
|
|
||||||
|
return { stopMessage };
|
||||||
|
}
|
||||||
@ -29,6 +29,7 @@ const {
|
|||||||
fetchExternalAgentInputs,
|
fetchExternalAgentInputs,
|
||||||
prompt,
|
prompt,
|
||||||
cancelDataflow,
|
cancelDataflow,
|
||||||
|
cancelCanvas,
|
||||||
} = api;
|
} = api;
|
||||||
|
|
||||||
const methods = {
|
const methods = {
|
||||||
@ -120,6 +121,10 @@ const methods = {
|
|||||||
url: cancelDataflow,
|
url: cancelDataflow,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
},
|
},
|
||||||
|
cancelCanvas: {
|
||||||
|
url: cancelCanvas,
|
||||||
|
method: 'put',
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const agentService = registerNextServer<keyof typeof methods>(methods);
|
const agentService = registerNextServer<keyof typeof methods>(methods);
|
||||||
|
|||||||
@ -174,6 +174,7 @@ export default {
|
|||||||
debug: `${api_host}/canvas/debug`,
|
debug: `${api_host}/canvas/debug`,
|
||||||
uploadCanvasFile: `${api_host}/canvas/upload`,
|
uploadCanvasFile: `${api_host}/canvas/upload`,
|
||||||
trace: `${api_host}/canvas/trace`,
|
trace: `${api_host}/canvas/trace`,
|
||||||
|
cancelCanvas: (taskId: string) => `${api_host}/canvas/cancel/${taskId}`, // cancel conversation
|
||||||
// agent
|
// agent
|
||||||
inputForm: `${api_host}/canvas/input_form`,
|
inputForm: `${api_host}/canvas/input_form`,
|
||||||
fetchVersionList: (id: string) => `${api_host}/canvas/getlistversion/${id}`,
|
fetchVersionList: (id: string) => `${api_host}/canvas/getlistversion/${id}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user