mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-30 12:45:09 +08:00
### What problem does this PR solve? Feat: Load the dialog page, prohibit calling the dialog/get interface #6798 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
57e760883e
commit
f49588756e
@ -84,7 +84,7 @@ export const useGetChatSearchParams = () => {
|
|||||||
|
|
||||||
//#region dialog
|
//#region dialog
|
||||||
|
|
||||||
export const useFetchNextDialogList = () => {
|
export const useFetchNextDialogList = (pureFetch = false) => {
|
||||||
const { handleClickDialog } = useClickDialogCard();
|
const { handleClickDialog } = useClickDialogCard();
|
||||||
const { dialogId } = useGetChatSearchParams();
|
const { dialogId } = useGetChatSearchParams();
|
||||||
|
|
||||||
@ -103,12 +103,14 @@ export const useFetchNextDialogList = () => {
|
|||||||
|
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
const list: IDialog[] = data.data;
|
const list: IDialog[] = data.data;
|
||||||
if (list.length > 0) {
|
if (!pureFetch) {
|
||||||
if (list.every((x) => x.id !== dialogId)) {
|
if (list.length > 0) {
|
||||||
handleClickDialog(data.data[0].id);
|
if (list.every((x) => x.id !== dialogId)) {
|
||||||
|
handleClickDialog(data.data[0].id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
history.push('/chat');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
history.push('/chat');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
useFetchNextConversation,
|
useFetchNextConversation,
|
||||||
useFetchNextConversationList,
|
useFetchNextConversationList,
|
||||||
useFetchNextDialog,
|
useFetchNextDialog,
|
||||||
|
useFetchNextDialogList,
|
||||||
useGetChatSearchParams,
|
useGetChatSearchParams,
|
||||||
useRemoveNextConversation,
|
useRemoveNextConversation,
|
||||||
useRemoveNextDialog,
|
useRemoveNextDialog,
|
||||||
@ -202,15 +203,24 @@ export const useEditDialog = () => {
|
|||||||
|
|
||||||
//#region conversation
|
//#region conversation
|
||||||
|
|
||||||
|
const useFindPrologueFromDialogList = () => {
|
||||||
|
const { dialogId } = useGetChatSearchParams();
|
||||||
|
const { data: dialogList } = useFetchNextDialogList(true);
|
||||||
|
const prologue = useMemo(() => {
|
||||||
|
return dialogList.find((x) => x.id === dialogId)?.prompt_config.prologue;
|
||||||
|
}, [dialogId, dialogList]);
|
||||||
|
|
||||||
|
return prologue;
|
||||||
|
};
|
||||||
|
|
||||||
export const useSelectDerivedConversationList = () => {
|
export const useSelectDerivedConversationList = () => {
|
||||||
const { t } = useTranslate('chat');
|
const { t } = useTranslate('chat');
|
||||||
|
|
||||||
const [list, setList] = useState<Array<IConversation>>([]);
|
const [list, setList] = useState<Array<IConversation>>([]);
|
||||||
const { data: currentDialog } = useFetchNextDialog();
|
|
||||||
const { data: conversationList, loading } = useFetchNextConversationList();
|
const { data: conversationList, loading } = useFetchNextConversationList();
|
||||||
const { dialogId } = useGetChatSearchParams();
|
const { dialogId } = useGetChatSearchParams();
|
||||||
const prologue = currentDialog?.prompt_config?.prologue ?? '';
|
|
||||||
const { setNewConversationRouteParams } = useSetNewConversationRouteParams();
|
const { setNewConversationRouteParams } = useSetNewConversationRouteParams();
|
||||||
|
const prologue = useFindPrologueFromDialogList();
|
||||||
|
|
||||||
const addTemporaryConversation = useCallback(() => {
|
const addTemporaryConversation = useCallback(() => {
|
||||||
const conversationId = getConversationId();
|
const conversationId = getConversationId();
|
||||||
@ -291,13 +301,11 @@ export const useSelectNextMessages = () => {
|
|||||||
removeMessagesAfterCurrentMessage,
|
removeMessagesAfterCurrentMessage,
|
||||||
} = useSelectDerivedMessages();
|
} = useSelectDerivedMessages();
|
||||||
const { data: conversation, loading } = useFetchNextConversation();
|
const { data: conversation, loading } = useFetchNextConversation();
|
||||||
const { data: dialog } = useFetchNextDialog();
|
|
||||||
const { conversationId, dialogId, isNew } = useGetChatSearchParams();
|
const { conversationId, dialogId, isNew } = useGetChatSearchParams();
|
||||||
|
const prologue = useFindPrologueFromDialogList();
|
||||||
|
|
||||||
const addPrologue = useCallback(() => {
|
const addPrologue = useCallback(() => {
|
||||||
if (dialogId !== '' && isNew === 'true') {
|
if (dialogId !== '' && isNew === 'true') {
|
||||||
const prologue = dialog.prompt_config?.prologue;
|
|
||||||
|
|
||||||
const nextMessage = {
|
const nextMessage = {
|
||||||
role: MessageType.Assistant,
|
role: MessageType.Assistant,
|
||||||
content: prologue,
|
content: prologue,
|
||||||
@ -306,7 +314,7 @@ export const useSelectNextMessages = () => {
|
|||||||
|
|
||||||
setDerivedMessages([nextMessage]);
|
setDerivedMessages([nextMessage]);
|
||||||
}
|
}
|
||||||
}, [isNew, dialog, dialogId, setDerivedMessages]);
|
}, [dialogId, isNew, prologue, setDerivedMessages]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
addPrologue();
|
addPrologue();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user