mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-25 09:53:29 +08:00
### What problem does this PR solve?
This reverts commit 1a608ac411.
### Type of change
- [x] Other (please describe):
This commit is contained in:
@@ -67,7 +67,7 @@ export function useDisableDifferenceEmbeddingDataset(name: string) {
|
||||
|
||||
export function KnowledgeBaseFormField({
|
||||
showVariable = false,
|
||||
name = 'dataset_ids',
|
||||
name = 'kb_ids',
|
||||
required = false,
|
||||
}: {
|
||||
showVariable?: boolean;
|
||||
|
||||
@@ -30,12 +30,10 @@ import {
|
||||
import { useHandleSearchStrChange } from './logic-hooks/use-change-search';
|
||||
|
||||
export const enum ChatApiAction {
|
||||
FetchChatList = 'fetchChatList',
|
||||
DeleteChat = 'deleteChat',
|
||||
CreateChat = 'createChat',
|
||||
UpdateChat = 'updateChat',
|
||||
PatchChat = 'patchChat',
|
||||
FetchChat = 'fetchChat',
|
||||
FetchDialogList = 'fetchDialogList',
|
||||
RemoveDialog = 'removeDialog',
|
||||
SetDialog = 'setDialog',
|
||||
FetchDialog = 'fetchDialog',
|
||||
FetchConversationList = 'fetchConversationList',
|
||||
FetchConversation = 'fetchConversation',
|
||||
FetchConversationManually = 'fetchConversationManually',
|
||||
@@ -62,7 +60,7 @@ export const useGetChatSearchParams = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useFetchChatList = () => {
|
||||
export const useFetchDialogList = () => {
|
||||
const { searchString, handleInputChange } = useHandleSearchChange();
|
||||
const { pagination, setPagination } = useGetPaginationWithRouter();
|
||||
const debouncedSearchString = useDebounce(searchString, { wait: 500 });
|
||||
@@ -71,19 +69,19 @@ export const useFetchChatList = () => {
|
||||
data,
|
||||
isFetching: loading,
|
||||
refetch,
|
||||
} = useQuery<{ chats: IDialog[]; total: number }>({
|
||||
} = useQuery<{ dialogs: IDialog[]; total: number }>({
|
||||
queryKey: [
|
||||
ChatApiAction.FetchChatList,
|
||||
ChatApiAction.FetchDialogList,
|
||||
{
|
||||
debouncedSearchString,
|
||||
...pagination,
|
||||
},
|
||||
],
|
||||
initialData: { chats: [], total: 0 },
|
||||
initialData: { dialogs: [], total: 0 },
|
||||
gcTime: 0,
|
||||
refetchOnWindowFocus: false,
|
||||
queryFn: async () => {
|
||||
const { data } = await chatService.listChats(
|
||||
const { data } = await chatService.listDialog(
|
||||
{
|
||||
params: {
|
||||
keywords: debouncedSearchString,
|
||||
@@ -95,7 +93,7 @@ export const useFetchChatList = () => {
|
||||
true,
|
||||
);
|
||||
|
||||
return data?.data ?? { chats: [], total: 0 };
|
||||
return data?.data ?? { dialogs: [], total: 0 };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -117,7 +115,7 @@ export const useFetchChatList = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useDeleteChat = () => {
|
||||
export const useRemoveDialog = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -126,23 +124,22 @@ export const useDeleteChat = () => {
|
||||
isPending: loading,
|
||||
mutateAsync,
|
||||
} = useMutation({
|
||||
mutationKey: [ChatApiAction.DeleteChat],
|
||||
mutationFn: async (chatId: string) => {
|
||||
const { data } = await chatService.deleteChat(chatId);
|
||||
mutationKey: [ChatApiAction.RemoveDialog],
|
||||
mutationFn: async (dialogIds: string[]) => {
|
||||
const { data } = await chatService.removeDialog({ dialogIds });
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [ChatApiAction.FetchChatList],
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: ['fetchDialogList'] });
|
||||
|
||||
message.success(t('message.deleted'));
|
||||
}
|
||||
return data.code;
|
||||
},
|
||||
});
|
||||
|
||||
return { data, loading, deleteChat: mutateAsync };
|
||||
return { data, loading, removeDialog: mutateAsync };
|
||||
};
|
||||
|
||||
export const useCreateChat = () => {
|
||||
export const useSetDialog = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -151,96 +148,31 @@ export const useCreateChat = () => {
|
||||
isPending: loading,
|
||||
mutateAsync,
|
||||
} = useMutation({
|
||||
mutationKey: [ChatApiAction.CreateChat],
|
||||
mutationFn: async (params: Record<string, any>) => {
|
||||
const { data } = await chatService.createChat(params);
|
||||
mutationKey: [ChatApiAction.SetDialog],
|
||||
mutationFn: async (params: Partial<IDialog>) => {
|
||||
const { data } = await chatService.setDialog(params);
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({
|
||||
exact: false,
|
||||
queryKey: [ChatApiAction.FetchChatList],
|
||||
queryKey: [ChatApiAction.FetchDialogList],
|
||||
});
|
||||
message.success(t('message.created'));
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [ChatApiAction.FetchDialog],
|
||||
});
|
||||
|
||||
message.success(
|
||||
t(`message.${params.dialog_id ? 'modified' : 'created'}`),
|
||||
);
|
||||
}
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
return { data, loading, createChat: mutateAsync };
|
||||
return { data, loading, setDialog: mutateAsync };
|
||||
};
|
||||
|
||||
export const useUpdateChat = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const {
|
||||
data,
|
||||
isPending: loading,
|
||||
mutateAsync,
|
||||
} = useMutation({
|
||||
mutationKey: [ChatApiAction.UpdateChat],
|
||||
mutationFn: async ({
|
||||
chatId,
|
||||
params,
|
||||
}: {
|
||||
chatId: string;
|
||||
params: Record<string, any>;
|
||||
}) => {
|
||||
const { data } = await chatService.updateChat(
|
||||
{ url: api.updateChat(chatId), data: params },
|
||||
true,
|
||||
);
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({
|
||||
exact: false,
|
||||
queryKey: [ChatApiAction.FetchChatList],
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: [ChatApiAction.FetchChat] });
|
||||
message.success(t('message.modified'));
|
||||
}
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
return { data, loading, updateChat: mutateAsync };
|
||||
};
|
||||
|
||||
export const usePatchChat = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const {
|
||||
data,
|
||||
isPending: loading,
|
||||
mutateAsync,
|
||||
} = useMutation({
|
||||
mutationKey: [ChatApiAction.PatchChat],
|
||||
mutationFn: async ({
|
||||
chatId,
|
||||
params,
|
||||
}: {
|
||||
chatId: string;
|
||||
params: Record<string, any>;
|
||||
}) => {
|
||||
const { data } = await chatService.patchChat(
|
||||
{ url: api.patchChat(chatId), data: params },
|
||||
true,
|
||||
);
|
||||
if (data.code === 0) {
|
||||
queryClient.invalidateQueries({
|
||||
exact: false,
|
||||
queryKey: [ChatApiAction.FetchChatList],
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: [ChatApiAction.FetchChat] });
|
||||
message.success(t('message.modified'));
|
||||
}
|
||||
return data?.code;
|
||||
},
|
||||
});
|
||||
|
||||
return { data, loading, patchChat: mutateAsync };
|
||||
};
|
||||
|
||||
export const useFetchChat = () => {
|
||||
export const useFetchDialog = () => {
|
||||
const { id } = useParams();
|
||||
|
||||
const {
|
||||
@@ -248,13 +180,17 @@ export const useFetchChat = () => {
|
||||
isFetching: loading,
|
||||
refetch,
|
||||
} = useQuery<IDialog>({
|
||||
queryKey: [ChatApiAction.FetchChat, id],
|
||||
queryKey: [ChatApiAction.FetchDialog, id],
|
||||
gcTime: 0,
|
||||
initialData: {} as IDialog,
|
||||
enabled: !!id,
|
||||
refetchOnWindowFocus: false,
|
||||
queryFn: async () => {
|
||||
const { data } = await chatService.getChat(id);
|
||||
const { data } = await chatService.getDialog(
|
||||
{ params: { dialogId: id } },
|
||||
true,
|
||||
);
|
||||
|
||||
return data?.data ?? ({} as IDialog);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -14,7 +14,6 @@ export interface PromptConfig {
|
||||
reasoning?: boolean;
|
||||
cross_languages?: Array<string>;
|
||||
tavily_api_key?: string;
|
||||
toc_enhance?: boolean;
|
||||
}
|
||||
|
||||
export interface Parameter {
|
||||
@@ -35,8 +34,8 @@ export interface Variable {
|
||||
presence_penalty?: number;
|
||||
temperature?: number;
|
||||
top_p?: number;
|
||||
llm_id?: string;
|
||||
tenant_llm_id?: string;
|
||||
model_type?: string;
|
||||
}
|
||||
|
||||
export interface IDialog {
|
||||
@@ -45,14 +44,14 @@ export interface IDialog {
|
||||
description: string;
|
||||
icon: string;
|
||||
id: string;
|
||||
dialog_id?: string;
|
||||
dataset_ids: string[];
|
||||
dialog_id: string;
|
||||
kb_ids: string[];
|
||||
kb_names: string[];
|
||||
language: string;
|
||||
llm_id: string;
|
||||
tenant_llm_id?: string;
|
||||
llm_setting: Variable;
|
||||
llm_setting_type?: string;
|
||||
llm_setting_type: string;
|
||||
name: string;
|
||||
prompt_config: PromptConfig;
|
||||
prompt_type: string;
|
||||
@@ -64,7 +63,6 @@ export interface IDialog {
|
||||
similarity_threshold: number;
|
||||
top_k: number;
|
||||
top_n: number;
|
||||
rerank_id?: string;
|
||||
meta_data_filter: MetaDataFilter;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { HomeCard } from '@/components/home-card';
|
||||
import { MoreButton } from '@/components/more-button';
|
||||
import { RenameDialog } from '@/components/rename-dialog';
|
||||
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
|
||||
import { useFetchChatList } from '@/hooks/use-chat-request';
|
||||
import { useFetchDialogList } from '@/hooks/use-chat-request';
|
||||
import { useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ChatDropdown } from '../next-chats/chat-dropdown';
|
||||
@@ -16,7 +16,7 @@ export function ChatList({
|
||||
setLoading?: (loading: boolean) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { data, loading } = useFetchChatList();
|
||||
const { data, loading } = useFetchDialogList();
|
||||
const { navigateToChat } = useNavigatePage();
|
||||
|
||||
const {
|
||||
@@ -28,12 +28,12 @@ export function ChatList({
|
||||
chatRenameLoading,
|
||||
} = useRenameChat();
|
||||
useEffect(() => {
|
||||
setListLength(data?.chats?.length || 0);
|
||||
setListLength(data?.dialogs?.length || 0);
|
||||
setLoading?.(loading || false);
|
||||
}, [data, setListLength, loading, setLoading]);
|
||||
return (
|
||||
<>
|
||||
{data.chats.slice(0, 10).map((x) => (
|
||||
{data.dialogs.slice(0, 10).map((x) => (
|
||||
<HomeCard
|
||||
key={x.id}
|
||||
data={{
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { useDeleteChat } from '@/hooks/use-chat-request';
|
||||
import { useRemoveDialog } from '@/hooks/use-chat-request';
|
||||
import { IDialog } from '@/interfaces/database/chat';
|
||||
import { PenLine, Trash2 } from 'lucide-react';
|
||||
import { MouseEventHandler, PropsWithChildren, useCallback } from 'react';
|
||||
@@ -25,7 +25,7 @@ export function ChatDropdown({
|
||||
chat: IDialog;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { deleteChat } = useDeleteChat();
|
||||
const { removeDialog } = useRemoveDialog();
|
||||
|
||||
const handleShowChatRenameModal: MouseEventHandler<HTMLDivElement> =
|
||||
useCallback(
|
||||
@@ -37,8 +37,8 @@ export function ChatDropdown({
|
||||
);
|
||||
|
||||
const handleDelete: MouseEventHandler<HTMLDivElement> = useCallback(() => {
|
||||
deleteChat(chat.id);
|
||||
}, [chat.id, deleteChat]);
|
||||
removeDialog([chat.id]);
|
||||
}, [chat.id, removeDialog]);
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { DatasetMetadata } from '@/constants/chat';
|
||||
import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useFetchChat, useUpdateChat } from '@/hooks/use-chat-request';
|
||||
import { useFetchDialog, useSetDialog } from '@/hooks/use-chat-request';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
removeUselessFieldsFromValues,
|
||||
@@ -28,8 +28,8 @@ type ChatSettingsProps = { hasSingleChatBox: boolean };
|
||||
|
||||
export function ChatSettings({ hasSingleChatBox }: ChatSettingsProps) {
|
||||
const formSchema = useChatSettingSchema();
|
||||
const { data } = useFetchChat();
|
||||
const { updateChat, loading } = useUpdateChat();
|
||||
const { data } = useFetchDialog();
|
||||
const { setDialog, loading } = useSetDialog();
|
||||
const { id } = useParams();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -45,7 +45,7 @@ export function ChatSettings({ hasSingleChatBox }: ChatSettingsProps) {
|
||||
name: '',
|
||||
icon: '',
|
||||
description: '',
|
||||
dataset_ids: [],
|
||||
kb_ids: [],
|
||||
prompt_config: {
|
||||
quote: true,
|
||||
keyword: false,
|
||||
@@ -75,32 +75,22 @@ export function ChatSettings({ hasSingleChatBox }: ChatSettingsProps) {
|
||||
'llm_setting.',
|
||||
);
|
||||
|
||||
updateChat({
|
||||
chatId: id!,
|
||||
params: {
|
||||
...omit(data, [
|
||||
'operator_permission',
|
||||
'tenant_id',
|
||||
'created_by',
|
||||
'create_time',
|
||||
'create_date',
|
||||
'update_time',
|
||||
'update_date',
|
||||
'id',
|
||||
]),
|
||||
...nextValues,
|
||||
},
|
||||
setDialog({
|
||||
...omit(data, 'operator_permission'),
|
||||
...nextValues,
|
||||
dialog_id: id,
|
||||
});
|
||||
}
|
||||
|
||||
function onInvalid(errors: any) {
|
||||
void errors;
|
||||
console.log('Form validation failed:', errors);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const llmSettingEnabledValues = setLLMSettingEnabledValues(
|
||||
data.llm_setting,
|
||||
);
|
||||
|
||||
const nextData = {
|
||||
...data,
|
||||
...llmSettingEnabledValues,
|
||||
|
||||
@@ -42,7 +42,7 @@ export function useChatSettingSchema() {
|
||||
name: z.string().min(1, { message: t('assistantNameMessage') }),
|
||||
icon: z.string(),
|
||||
description: z.string().optional(),
|
||||
dataset_ids: z.array(z.string()).min(0, {
|
||||
kb_ids: z.array(z.string()).min(0, {
|
||||
message: t('knowledgeBasesMessage'),
|
||||
}),
|
||||
prompt_config: promptConfigSchema,
|
||||
|
||||
@@ -21,9 +21,9 @@ import {
|
||||
useScrollToBottom,
|
||||
} from '@/hooks/logic-hooks';
|
||||
import {
|
||||
useFetchChat,
|
||||
useFetchDialog,
|
||||
useGetChatSearchParams,
|
||||
usePatchChat,
|
||||
useSetDialog,
|
||||
} from '@/hooks/use-chat-request';
|
||||
import { useFetchUserInfo } from '@/hooks/use-user-setting-request';
|
||||
import { IClientConversation } from '@/interfaces/database/chat';
|
||||
@@ -102,7 +102,7 @@ const ChatCard = forwardRef(function ChatCard(
|
||||
ref,
|
||||
) {
|
||||
const { id: dialogId } = useParams();
|
||||
const { patchChat } = usePatchChat();
|
||||
const { setDialog } = useSetDialog();
|
||||
|
||||
const { removeMessageById, derivedMessages, handlePressEnter, sendLoading } =
|
||||
useSendSingleMessage({
|
||||
@@ -131,7 +131,7 @@ const ChatCard = forwardRef(function ChatCard(
|
||||
const llmId = useWatch({ control: form.control, name: 'llm_id' });
|
||||
|
||||
const { data: userInfo } = useFetchUserInfo();
|
||||
const { data: currentDialog } = useFetchChat();
|
||||
const { data: currentDialog } = useFetchDialog();
|
||||
|
||||
useSetDefaultModel(form);
|
||||
|
||||
@@ -143,15 +143,13 @@ const ChatCard = forwardRef(function ChatCard(
|
||||
|
||||
const handleApplyConfig = useCallback(() => {
|
||||
const values = form.getValues();
|
||||
patchChat({
|
||||
chatId: dialogId!,
|
||||
params: {
|
||||
...currentDialog,
|
||||
llm_id: values.llm_id,
|
||||
llm_setting: omit(values, 'llm_id'),
|
||||
},
|
||||
setDialog({
|
||||
...currentDialog,
|
||||
llm_id: values.llm_id,
|
||||
llm_setting: omit(values, 'llm_id'),
|
||||
dialog_id: dialogId,
|
||||
});
|
||||
}, [currentDialog, dialogId, form, patchChat]);
|
||||
}, [currentDialog, dialogId, form, setDialog]);
|
||||
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
|
||||
@@ -3,7 +3,10 @@ import MessageItem from '@/components/message-item';
|
||||
import PdfSheet from '@/components/pdf-drawer';
|
||||
import { useClickDrawer } from '@/components/pdf-drawer/hooks';
|
||||
import { MessageType } from '@/constants/chat';
|
||||
import { useFetchChat, useGetChatSearchParams } from '@/hooks/use-chat-request';
|
||||
import {
|
||||
useFetchDialog,
|
||||
useGetChatSearchParams,
|
||||
} from '@/hooks/use-chat-request';
|
||||
import { useFetchUserInfo } from '@/hooks/use-user-setting-request';
|
||||
import { IClientConversation } from '@/interfaces/database/chat';
|
||||
import { buildMessageUuidWithRole } from '@/utils/chat';
|
||||
@@ -44,7 +47,7 @@ export function SingleChatBox({
|
||||
setDerivedMessages,
|
||||
} = useSendMessage(controller);
|
||||
const { data: userInfo } = useFetchUserInfo();
|
||||
const { data: currentDialog } = useFetchChat();
|
||||
const { data: currentDialog } = useFetchDialog();
|
||||
const { createConversationBeforeUploadDocument } =
|
||||
useCreateConversationBeforeUploadDocument();
|
||||
const { conversationId } = useGetChatSearchParams();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { LargeModelFormFieldWithoutFilter } from '@/components/large-model-form-field';
|
||||
import { LlmSettingSchema } from '@/components/llm-setting-items/next';
|
||||
import { Form } from '@/components/ui/form';
|
||||
import { useFetchChat } from '@/hooks/use-chat-request';
|
||||
import { useFetchDialog } from '@/hooks/use-chat-request';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useEffect } from 'react';
|
||||
@@ -10,7 +10,7 @@ import { z } from 'zod';
|
||||
|
||||
export function LLMSelectForm() {
|
||||
const FormSchema = z.object(LlmSettingSchema);
|
||||
const { data } = useFetchChat();
|
||||
const { data } = useFetchDialog();
|
||||
|
||||
const form = useForm<z.infer<typeof FormSchema>>({
|
||||
resolver: zodResolver(FormSchema),
|
||||
@@ -25,6 +25,7 @@ export function LLMSelectForm() {
|
||||
if (!isEmpty(data)) {
|
||||
form.reset({ llm_id: data.llm_id, ...data.llm_setting });
|
||||
}
|
||||
form.reset(data);
|
||||
}, [data, form]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
import { SharedFrom } from '@/constants/chat';
|
||||
import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import {
|
||||
useFetchChat,
|
||||
useFetchDialog,
|
||||
useGetChatSearchParams,
|
||||
useRemoveConversation,
|
||||
} from '@/hooks/use-chat-request';
|
||||
@@ -48,7 +48,7 @@ export function Sessions({ handleConversationCardClick }: SessionProps) {
|
||||
handleInputChange,
|
||||
searchString,
|
||||
} = useSelectDerivedConversationList();
|
||||
const { data } = useFetchChat();
|
||||
const { data } = useFetchDialog();
|
||||
const { visible, switchVisible } = useSetModalState(true);
|
||||
const { removeConversation } = useRemoveConversation();
|
||||
const { setConversationBoth } = useChatUrlParams();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useFetchChat } from '@/hooks/use-chat-request';
|
||||
import { useFetchDialog } from '@/hooks/use-chat-request';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
export function useShowInternet() {
|
||||
const { data: currentDialog } = useFetchChat();
|
||||
const { data: currentDialog } = useFetchDialog();
|
||||
|
||||
return !isEmpty(currentDialog?.prompt_config?.tavily_api_key);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useSetModalState } from '@/hooks/common-hooks';
|
||||
import { useCreateChat, usePatchChat } from '@/hooks/use-chat-request';
|
||||
import { useSetDialog } from '@/hooks/use-chat-request';
|
||||
import { useFetchTenantInfo } from '@/hooks/use-user-setting-request';
|
||||
import { IDialog } from '@/interfaces/database/chat';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { isEmpty, omit } from 'lodash';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
@@ -13,8 +13,7 @@ export const useRenameChat = () => {
|
||||
hideModal: hideChatRenameModal,
|
||||
showModal: showChatRenameModal,
|
||||
} = useSetModalState();
|
||||
const { createChat, loading: createLoading } = useCreateChat();
|
||||
const { patchChat, loading: patchLoading } = usePatchChat();
|
||||
const { setDialog, loading } = useSetDialog();
|
||||
const { t } = useTranslation();
|
||||
const tenantInfo = useFetchTenantInfo();
|
||||
|
||||
@@ -24,7 +23,6 @@ export const useRenameChat = () => {
|
||||
icon: '',
|
||||
language: 'English',
|
||||
description: '',
|
||||
dataset_ids: [],
|
||||
prompt_config: {
|
||||
empty_response: '',
|
||||
prologue: t('chat.setAnOpenerInitial'),
|
||||
@@ -43,28 +41,28 @@ export const useRenameChat = () => {
|
||||
similarity_threshold: 0.2,
|
||||
vector_similarity_weight: 0.3,
|
||||
top_n: 8,
|
||||
top_k: 1024,
|
||||
}),
|
||||
[t, tenantInfo.data.llm_id],
|
||||
);
|
||||
|
||||
const onChatRenameOk = useCallback(
|
||||
async (name: string) => {
|
||||
let ret: number | undefined;
|
||||
if (isEmpty(chat)) {
|
||||
ret = await createChat({ ...InitialData, name });
|
||||
} else {
|
||||
ret = await patchChat({
|
||||
chatId: chat.id,
|
||||
params: { name },
|
||||
});
|
||||
}
|
||||
const nextChat = {
|
||||
...(isEmpty(chat)
|
||||
? InitialData
|
||||
: {
|
||||
...omit(chat, 'nickname', 'tenant_avatar', 'operator_permission'),
|
||||
dialog_id: chat.id,
|
||||
}),
|
||||
name,
|
||||
};
|
||||
const ret = await setDialog(nextChat);
|
||||
|
||||
if (ret === 0) {
|
||||
hideChatRenameModal();
|
||||
}
|
||||
},
|
||||
[chat, InitialData, createChat, patchChat, hideChatRenameModal],
|
||||
[chat, InitialData, setDialog, hideChatRenameModal],
|
||||
);
|
||||
|
||||
const handleShowChatRenameModal = useCallback(
|
||||
@@ -85,7 +83,7 @@ export const useRenameChat = () => {
|
||||
}, [hideChatRenameModal]);
|
||||
|
||||
return {
|
||||
chatRenameLoading: createLoading || patchLoading,
|
||||
chatRenameLoading: loading,
|
||||
initialChatName: chat?.name,
|
||||
onChatRenameOk,
|
||||
chatRenameVisible,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { MessageType } from '@/constants/chat';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import {
|
||||
useFetchChatList,
|
||||
useFetchConversationList,
|
||||
useFetchDialogList,
|
||||
} from '@/hooks/use-chat-request';
|
||||
import { IConversation } from '@/interfaces/database/chat';
|
||||
import { generateConversationId } from '@/utils/chat';
|
||||
@@ -12,10 +12,10 @@ import { useChatUrlParams } from './use-chat-url';
|
||||
|
||||
export const useFindPrologueFromDialogList = () => {
|
||||
const { id: dialogId } = useParams();
|
||||
const { data } = useFetchChatList();
|
||||
const { data } = useFetchDialogList();
|
||||
|
||||
const prologue = useMemo(() => {
|
||||
return data.chats.find((x) => x.id === dialogId)?.prompt_config?.prologue;
|
||||
return data.dialogs.find((x) => x.id === dialogId)?.prompt_config.prologue;
|
||||
}, [dialogId, data]);
|
||||
|
||||
return prologue;
|
||||
|
||||
@@ -5,7 +5,7 @@ import ListFilterBar from '@/components/list-filter-bar';
|
||||
import { RenameDialog } from '@/components/rename-dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';
|
||||
import { useFetchChatList } from '@/hooks/use-chat-request';
|
||||
import { useFetchDialogList } from '@/hooks/use-chat-request';
|
||||
import { pick } from 'lodash';
|
||||
import { Plus } from 'lucide-react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
@@ -16,7 +16,7 @@ import { useRenameChat } from './hooks/use-rename-chat';
|
||||
|
||||
export default function ChatList() {
|
||||
const { data, setPagination, pagination, handleInputChange, searchString } =
|
||||
useFetchChatList();
|
||||
useFetchDialogList();
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
initialChatName,
|
||||
@@ -50,7 +50,7 @@ export default function ChatList() {
|
||||
|
||||
return (
|
||||
<>
|
||||
{data.chats?.length || searchString ? (
|
||||
{data.dialogs?.length || searchString ? (
|
||||
<article className="size-full flex flex-col" data-testid="chats-list">
|
||||
<header className="px-5 pt-8 mb-4">
|
||||
<ListFilterBar
|
||||
@@ -66,10 +66,10 @@ export default function ChatList() {
|
||||
</ListFilterBar>
|
||||
</header>
|
||||
|
||||
{data.chats?.length ? (
|
||||
{data.dialogs?.length ? (
|
||||
<>
|
||||
<CardContainer className="flex-1 overflow-auto px-5">
|
||||
{data.chats.map((x) => (
|
||||
{data.dialogs.map((x) => (
|
||||
<ChatCard
|
||||
key={x.id}
|
||||
data={x}
|
||||
|
||||
@@ -2,13 +2,10 @@ import api from '@/utils/api';
|
||||
import { registerNextServer } from '@/utils/register-server';
|
||||
|
||||
const {
|
||||
createChat,
|
||||
listChats,
|
||||
getChat,
|
||||
updateChat,
|
||||
patchChat,
|
||||
deleteChat,
|
||||
bulkDeleteChats,
|
||||
getDialog,
|
||||
setDialog,
|
||||
// listDialog,
|
||||
removeDialog,
|
||||
getConversation,
|
||||
getConversationSSE,
|
||||
setConversation,
|
||||
@@ -29,38 +26,27 @@ const {
|
||||
ask,
|
||||
mindmap,
|
||||
getRelatedQuestions,
|
||||
listNextDialog,
|
||||
upload_and_parse,
|
||||
fetchExternalChatInfo,
|
||||
} = api;
|
||||
|
||||
const methods = {
|
||||
createChat: {
|
||||
url: createChat,
|
||||
getDialog: {
|
||||
url: getDialog,
|
||||
method: 'get',
|
||||
},
|
||||
setDialog: {
|
||||
url: setDialog,
|
||||
method: 'post',
|
||||
},
|
||||
listChats: {
|
||||
url: listChats,
|
||||
method: 'get',
|
||||
removeDialog: {
|
||||
url: removeDialog,
|
||||
method: 'post',
|
||||
},
|
||||
getChat: {
|
||||
url: getChat,
|
||||
method: 'get',
|
||||
},
|
||||
updateChat: {
|
||||
url: updateChat,
|
||||
method: 'put',
|
||||
},
|
||||
patchChat: {
|
||||
url: patchChat,
|
||||
method: 'patch',
|
||||
},
|
||||
deleteChat: {
|
||||
url: deleteChat,
|
||||
method: 'delete',
|
||||
},
|
||||
bulkDeleteChats: {
|
||||
url: bulkDeleteChats,
|
||||
method: 'delete',
|
||||
listDialog: {
|
||||
url: listNextDialog,
|
||||
method: 'post',
|
||||
},
|
||||
listConversation: {
|
||||
url: listConversation,
|
||||
|
||||
@@ -128,13 +128,10 @@ export default {
|
||||
get_dataset_filter: `${api_host}/document/filter`,
|
||||
|
||||
// chat
|
||||
createChat: `${ExternalApi}${api_host}/chats`,
|
||||
listChats: `${ExternalApi}${api_host}/chats`,
|
||||
getChat: (chatId: string) => `${ExternalApi}${api_host}/chats/${chatId}`,
|
||||
updateChat: (chatId: string) => `${ExternalApi}${api_host}/chats/${chatId}`,
|
||||
patchChat: (chatId: string) => `${ExternalApi}${api_host}/chats/${chatId}`,
|
||||
deleteChat: (chatId: string) => `${ExternalApi}${api_host}/chats/${chatId}`,
|
||||
bulkDeleteChats: `${ExternalApi}${api_host}/chats`,
|
||||
setDialog: `${api_host}/dialog/set`,
|
||||
getDialog: `${api_host}/dialog/get`,
|
||||
removeDialog: `${api_host}/dialog/rm`,
|
||||
listDialog: `${api_host}/dialog/list`,
|
||||
setConversation: `${api_host}/conversation/set`,
|
||||
getConversation: `${api_host}/conversation/get`,
|
||||
getConversationSSE: (dialogId: string) =>
|
||||
@@ -159,6 +156,7 @@ export default {
|
||||
uploadAndParseExternal: `${api_host}/api/document/upload_and_parse`,
|
||||
|
||||
// next chat
|
||||
listNextDialog: `${api_host}/dialog/next`,
|
||||
fetchExternalChatInfo: (id: string) =>
|
||||
`${ExternalApi}${api_host}/chatbots/${id}/info`,
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ const modelParamMap: ModelParamMap = {
|
||||
// API endpoint whitelist - only these endpoints will have tenant parameters added
|
||||
const API_WHITELIST = [
|
||||
'/v1/user/set_tenant_info',
|
||||
'/api/v1/chats',
|
||||
'/v1/dialog/set',
|
||||
'/v1/canvas/set',
|
||||
'/v1/canvas/setting',
|
||||
'/api/v1/searches/',
|
||||
|
||||
Reference in New Issue
Block a user