mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? fix: fetch user by @tanstack/react-query #1306 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -1,7 +1,4 @@
|
|||||||
import {
|
import { useSelectParserList } from '@/hooks/user-setting-hooks';
|
||||||
useFetchTenantInfo,
|
|
||||||
useSelectParserList,
|
|
||||||
} from '@/hooks/user-setting-hooks';
|
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
const ParserListMap = new Map([
|
const ParserListMap = new Map([
|
||||||
@ -71,8 +68,6 @@ export const useFetchParserListOnMount = (
|
|||||||
);
|
);
|
||||||
}, [parserList, documentExtension]);
|
}, [parserList, documentExtension]);
|
||||||
|
|
||||||
useFetchTenantInfo();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedTag(parserId);
|
setSelectedTag(parserId);
|
||||||
}, [parserId, documentId]);
|
}, [parserId, documentId]);
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useSelector } from 'umi';
|
|
||||||
|
|
||||||
export const useFetchLlmList = (
|
export const useFetchLlmList = (
|
||||||
modelType?: LlmModelType,
|
modelType?: LlmModelType,
|
||||||
@ -34,14 +33,6 @@ export const useFetchLlmList = (
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSelectLlmInfo = () => {
|
|
||||||
const llmInfo: IThirdOAIModelCollection = useSelector(
|
|
||||||
(state: any) => state.settingModel.llmInfo,
|
|
||||||
);
|
|
||||||
|
|
||||||
return llmInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useSelectLlmOptions = () => {
|
export const useSelectLlmOptions = () => {
|
||||||
const llmInfo: IThirdOAIModelCollection = useFetchLlmList();
|
const llmInfo: IThirdOAIModelCollection = useFetchLlmList();
|
||||||
|
|
||||||
|
|||||||
@ -24,11 +24,7 @@ import { useSetModalState, useTranslate } from './common-hooks';
|
|||||||
import { useSetDocumentParser } from './document-hooks';
|
import { useSetDocumentParser } from './document-hooks';
|
||||||
import { useSetPaginationParams } from './route-hook';
|
import { useSetPaginationParams } from './route-hook';
|
||||||
import { useOneNamespaceEffectsLoading } from './store-hooks';
|
import { useOneNamespaceEffectsLoading } from './store-hooks';
|
||||||
import {
|
import { useFetchTenantInfo, useSaveSetting } from './user-setting-hooks';
|
||||||
useFetchTenantInfo,
|
|
||||||
useSaveSetting,
|
|
||||||
useSelectTenantInfo,
|
|
||||||
} from './user-setting-hooks';
|
|
||||||
|
|
||||||
export const useChangeDocumentParser = (documentId: string) => {
|
export const useChangeDocumentParser = (documentId: string) => {
|
||||||
const setDocumentParser = useSetDocumentParser();
|
const setDocumentParser = useSetDocumentParser();
|
||||||
@ -87,7 +83,7 @@ export const useHandleSearchChange = () => {
|
|||||||
|
|
||||||
export const useChangeLanguage = () => {
|
export const useChangeLanguage = () => {
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
const saveSetting = useSaveSetting();
|
const { saveSetting } = useSaveSetting();
|
||||||
|
|
||||||
const changeLanguage = (lng: string) => {
|
const changeLanguage = (lng: string) => {
|
||||||
i18n.changeLanguage(
|
i18n.changeLanguage(
|
||||||
@ -333,15 +329,8 @@ export const useSelectItem = (defaultId?: string) => {
|
|||||||
return { selectedId, handleItemClick };
|
return { selectedId, handleItemClick };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFetchModelId = (visible: boolean) => {
|
export const useFetchModelId = () => {
|
||||||
const fetchTenantInfo = useFetchTenantInfo(false);
|
const { data: tenantInfo } = useFetchTenantInfo();
|
||||||
const tenantInfo = useSelectTenantInfo();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (visible) {
|
|
||||||
fetchTenantInfo();
|
|
||||||
}
|
|
||||||
}, [visible, fetchTenantInfo]);
|
|
||||||
|
|
||||||
return tenantInfo?.llm_id ?? '';
|
return tenantInfo?.llm_id ?? '';
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,62 +1,68 @@
|
|||||||
|
import { LanguageTranslationMap } from '@/constants/common';
|
||||||
|
import { ResponseGetType } from '@/interfaces/database/base';
|
||||||
import { ITenantInfo } from '@/interfaces/database/knowledge';
|
import { ITenantInfo } from '@/interfaces/database/knowledge';
|
||||||
import { ISystemStatus, IUserInfo } from '@/interfaces/database/userSetting';
|
import { ISystemStatus, IUserInfo } from '@/interfaces/database/userSetting';
|
||||||
import userService from '@/services/user-service';
|
import userService from '@/services/user-service';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { useDispatch, useSelector } from 'umi';
|
import { message } from 'antd';
|
||||||
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export const useFetchUserInfo = () => {
|
export const useFetchUserInfo = (): ResponseGetType<IUserInfo> => {
|
||||||
const dispatch = useDispatch();
|
const { i18n } = useTranslation();
|
||||||
const fetchUserInfo = useCallback(() => {
|
|
||||||
dispatch({ type: 'settingModel/getUserInfo' });
|
|
||||||
}, [dispatch]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const { data, isFetching: loading } = useQuery({
|
||||||
fetchUserInfo();
|
queryKey: ['userInfo'],
|
||||||
}, [fetchUserInfo]);
|
initialData: {},
|
||||||
|
gcTime: 0,
|
||||||
|
queryFn: async () => {
|
||||||
|
const { data } = await userService.user_info();
|
||||||
|
if (data.retcode === 0) {
|
||||||
|
i18n.changeLanguage(
|
||||||
|
LanguageTranslationMap[
|
||||||
|
data.language as keyof typeof LanguageTranslationMap
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return data?.data ?? {};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { data, loading };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSelectUserInfo = () => {
|
export const useFetchTenantInfo = (): ResponseGetType<ITenantInfo> => {
|
||||||
const userInfo: IUserInfo = useSelector(
|
const { data, isFetching: loading } = useQuery({
|
||||||
(state: any) => state.settingModel.userInfo,
|
queryKey: ['tenantInfo'],
|
||||||
);
|
initialData: {},
|
||||||
|
gcTime: 0,
|
||||||
|
queryFn: async () => {
|
||||||
|
const { data: res } = await userService.get_tenant_info();
|
||||||
|
if (res.retcode === 0) {
|
||||||
|
// llm_id is chat_id
|
||||||
|
// asr_id is speech2txt
|
||||||
|
const { data } = res;
|
||||||
|
data.chat_id = data.llm_id;
|
||||||
|
data.speech2text_id = data.asr_id;
|
||||||
|
|
||||||
return userInfo;
|
return data;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const useSelectTenantInfo = () => {
|
return res;
|
||||||
const tenantInfo: ITenantInfo = useSelector(
|
},
|
||||||
(state: any) => state.settingModel.tenantIfo,
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return tenantInfo;
|
return { data, loading };
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchTenantInfo = (isOnMountFetching: boolean = true) => {
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
|
|
||||||
const fetchTenantInfo = useCallback(() => {
|
|
||||||
dispatch({
|
|
||||||
type: 'settingModel/getTenantInfo',
|
|
||||||
});
|
|
||||||
}, [dispatch]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isOnMountFetching) {
|
|
||||||
fetchTenantInfo();
|
|
||||||
}
|
|
||||||
}, [fetchTenantInfo, isOnMountFetching]);
|
|
||||||
|
|
||||||
return fetchTenantInfo;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSelectParserList = (): Array<{
|
export const useSelectParserList = (): Array<{
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
}> => {
|
}> => {
|
||||||
const tenantInfo: ITenantInfo = useSelectTenantInfo();
|
const { data: tenantInfo } = useFetchTenantInfo();
|
||||||
|
|
||||||
const parserList = useMemo(() => {
|
const parserList = useMemo(() => {
|
||||||
const parserArray: Array<string> = tenantInfo?.parser_ids.split(',') ?? [];
|
const parserArray: Array<string> = tenantInfo?.parser_ids?.split(',') ?? [];
|
||||||
return parserArray.map((x) => {
|
return parserArray.map((x) => {
|
||||||
const arr = x.split(':');
|
const arr = x.split(':');
|
||||||
return { value: arr[0], label: arr[1] };
|
return { value: arr[0], label: arr[1] };
|
||||||
@ -67,16 +73,27 @@ export const useSelectParserList = (): Array<{
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useSaveSetting = () => {
|
export const useSaveSetting = () => {
|
||||||
const dispatch = useDispatch();
|
const queryClient = useQueryClient();
|
||||||
|
const { t } = useTranslation();
|
||||||
const saveSetting = useCallback(
|
const {
|
||||||
(userInfo: { new_password: string } | Partial<IUserInfo>): number => {
|
data,
|
||||||
return dispatch<any>({ type: 'settingModel/setting', payload: userInfo });
|
isPending: loading,
|
||||||
|
mutateAsync,
|
||||||
|
} = useMutation({
|
||||||
|
mutationKey: ['saveSetting'],
|
||||||
|
mutationFn: async (
|
||||||
|
userInfo: { new_password: string } | Partial<IUserInfo>,
|
||||||
|
) => {
|
||||||
|
const { data } = await userService.setting(userInfo);
|
||||||
|
if (data.retcode === 0) {
|
||||||
|
message.success(t('message.modified'));
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['userInfo'] });
|
||||||
|
}
|
||||||
|
return data?.retcode;
|
||||||
},
|
},
|
||||||
[dispatch],
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return saveSetting;
|
return { data, loading, saveSetting: mutateAsync };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFetchSystemVersion = () => {
|
export const useFetchSystemVersion = () => {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import User from '../user';
|
|||||||
|
|
||||||
import { LanguageList } from '@/constants/common';
|
import { LanguageList } from '@/constants/common';
|
||||||
import { useChangeLanguage } from '@/hooks/logic-hooks';
|
import { useChangeLanguage } from '@/hooks/logic-hooks';
|
||||||
import { useSelector } from 'umi';
|
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
||||||
import styled from './index.less';
|
import styled from './index.less';
|
||||||
|
|
||||||
const Circle = ({ children, ...restProps }: React.PropsWithChildren) => {
|
const Circle = ({ children, ...restProps }: React.PropsWithChildren) => {
|
||||||
@ -25,9 +25,9 @@ const handleGithubCLick = () => {
|
|||||||
const RightToolBar = () => {
|
const RightToolBar = () => {
|
||||||
const { t } = useTranslate('common');
|
const { t } = useTranslate('common');
|
||||||
const changeLanguage = useChangeLanguage();
|
const changeLanguage = useChangeLanguage();
|
||||||
const { language = 'English' } = useSelector(
|
const {
|
||||||
(state) => state.settingModel.userInfo,
|
data: { language = 'English' },
|
||||||
);
|
} = useFetchUserInfo();
|
||||||
|
|
||||||
const handleItemClick: MenuProps['onClick'] = ({ key }) => {
|
const handleItemClick: MenuProps['onClick'] = ({ key }) => {
|
||||||
changeLanguage(key);
|
changeLanguage(key);
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
import {
|
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
||||||
useFetchUserInfo,
|
|
||||||
useSelectUserInfo,
|
|
||||||
} from '@/hooks/user-setting-hooks';
|
|
||||||
import { Avatar } from 'antd';
|
import { Avatar } from 'antd';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { history } from 'umi';
|
import { history } from 'umi';
|
||||||
@ -9,14 +6,12 @@ import { history } from 'umi';
|
|||||||
import styles from '../../index.less';
|
import styles from '../../index.less';
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const userInfo = useSelectUserInfo();
|
const { data: userInfo } = useFetchUserInfo();
|
||||||
|
|
||||||
const toSetting = () => {
|
const toSetting = () => {
|
||||||
history.push('/user-setting');
|
history.push('/user-setting');
|
||||||
};
|
};
|
||||||
|
|
||||||
useFetchUserInfo();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Avatar
|
<Avatar
|
||||||
size={32}
|
size={32}
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import {
|
|||||||
} from '@/hooks/document-hooks';
|
} from '@/hooks/document-hooks';
|
||||||
import { useGetKnowledgeSearchParams } from '@/hooks/route-hook';
|
import { useGetKnowledgeSearchParams } from '@/hooks/route-hook';
|
||||||
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
||||||
import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
|
|
||||||
import { Pagination } from '@/interfaces/common';
|
import { Pagination } from '@/interfaces/common';
|
||||||
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
|
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
|
||||||
import { getUnSupportedFilesCount } from '@/utils/document-util';
|
import { getUnSupportedFilesCount } from '@/utils/document-util';
|
||||||
@ -25,8 +24,6 @@ export const useFetchDocumentListOnMount = () => {
|
|||||||
const fetchDocumentList = useFetchDocumentList();
|
const fetchDocumentList = useFetchDocumentList();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
useFetchTenantInfo();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (knowledgeId) {
|
if (knowledgeId) {
|
||||||
fetchDocumentList();
|
fetchDocumentList();
|
||||||
|
|||||||
@ -4,10 +4,7 @@ import {
|
|||||||
} from '@/hooks/knowledge-hooks';
|
} from '@/hooks/knowledge-hooks';
|
||||||
import { useSelectLlmOptions } from '@/hooks/llm-hooks';
|
import { useSelectLlmOptions } from '@/hooks/llm-hooks';
|
||||||
import { useNavigateToDataset } from '@/hooks/route-hook';
|
import { useNavigateToDataset } from '@/hooks/route-hook';
|
||||||
import {
|
import { useSelectParserList } from '@/hooks/user-setting-hooks';
|
||||||
useFetchTenantInfo,
|
|
||||||
useSelectParserList,
|
|
||||||
} from '@/hooks/user-setting-hooks';
|
|
||||||
import {
|
import {
|
||||||
getBase64FromUploadFileList,
|
getBase64FromUploadFileList,
|
||||||
getUploadFileListFromBase64,
|
getUploadFileListFromBase64,
|
||||||
@ -43,7 +40,6 @@ export const useFetchKnowledgeConfigurationOnMount = (form: FormInstance) => {
|
|||||||
const parserList = useSelectParserList();
|
const parserList = useSelectParserList();
|
||||||
const embeddingModelOptions = useSelectLlmOptions();
|
const embeddingModelOptions = useSelectLlmOptions();
|
||||||
|
|
||||||
useFetchTenantInfo();
|
|
||||||
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
|
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -69,7 +69,7 @@ const ChatConfigurationModal = ({
|
|||||||
ConfigurationSegmented.AssistantSetting,
|
ConfigurationSegmented.AssistantSetting,
|
||||||
);
|
);
|
||||||
const promptEngineRef = useRef<Array<IPromptConfigParameters>>([]);
|
const promptEngineRef = useRef<Array<IPromptConfigParameters>>([]);
|
||||||
const modelId = useFetchModelId(visible);
|
const modelId = useFetchModelId();
|
||||||
const { t } = useTranslate('chat');
|
const { t } = useTranslate('chat');
|
||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import {
|
|||||||
} from '../hooks';
|
} from '../hooks';
|
||||||
import { buildMessageItemReference } from '../utils';
|
import { buildMessageItemReference } from '../utils';
|
||||||
|
|
||||||
import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
|
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
|
||||||
const ChatContainer = () => {
|
const ChatContainer = () => {
|
||||||
@ -43,7 +43,7 @@ const ChatContainer = () => {
|
|||||||
useGetFileIcon();
|
useGetFileIcon();
|
||||||
const loading = useSelectConversationLoading();
|
const loading = useSelectConversationLoading();
|
||||||
const { t } = useTranslate('chat');
|
const { t } = useTranslate('chat');
|
||||||
const userInfo = useSelectUserInfo();
|
const { data: userInfo } = useFetchUserInfo();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { Button, Drawer, Flex, Input, Spin } from 'antd';
|
|||||||
|
|
||||||
import { useSelectCurrentMessages, useSendMessage } from './hooks';
|
import { useSelectCurrentMessages, useSendMessage } from './hooks';
|
||||||
|
|
||||||
import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
|
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
|
||||||
const FlowChatBox = () => {
|
const FlowChatBox = () => {
|
||||||
@ -32,7 +32,7 @@ const FlowChatBox = () => {
|
|||||||
useClickDrawer();
|
useClickDrawer();
|
||||||
useGetFileIcon();
|
useGetFileIcon();
|
||||||
const { t } = useTranslate('chat');
|
const { t } = useTranslate('chat');
|
||||||
const userInfo = useSelectUserInfo();
|
const { data: userInfo } = useFetchUserInfo();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -69,7 +69,7 @@ export const useSelectCanvasData = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useInitializeOperatorParams = () => {
|
export const useInitializeOperatorParams = () => {
|
||||||
const llmId = useFetchModelId(true);
|
const llmId = useFetchModelId();
|
||||||
|
|
||||||
const initialFormValuesMap = useMemo(() => {
|
const initialFormValuesMap = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
||||||
import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
|
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
||||||
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
|
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
|
||||||
import { Button, Empty, Flex, Input, Space, Spin } from 'antd';
|
import { Button, Empty, Flex, Input, Space, Spin } from 'antd';
|
||||||
import KnowledgeCard from './knowledge-card';
|
import KnowledgeCard from './knowledge-card';
|
||||||
@ -13,7 +13,7 @@ const KnowledgeList = () => {
|
|||||||
const { searchString, handleInputChange } = useSearchKnowledge();
|
const { searchString, handleInputChange } = useSearchKnowledge();
|
||||||
const { loading, list: data } = useNextFetchKnowledgeList();
|
const { loading, list: data } = useNextFetchKnowledgeList();
|
||||||
const list = data.filter((x) => x.name.includes(searchString));
|
const list = data.filter((x) => x.name.includes(searchString));
|
||||||
const userInfo = useSelectUserInfo();
|
const { data: userInfo } = useFetchUserInfo();
|
||||||
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
|
||||||
const {
|
const {
|
||||||
visible,
|
visible,
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
|
||||||
import { Form } from 'antd';
|
import { Form } from 'antd';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
@ -18,9 +17,3 @@ export const useValidateSubmittable = () => {
|
|||||||
|
|
||||||
return { submittable, form };
|
return { submittable, form };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSelectSubmitUserInfoLoading = () =>
|
|
||||||
useOneNamespaceEffectsLoading('settingModel', ['setting']);
|
|
||||||
|
|
||||||
export const useSelectUserInfoLoading = () =>
|
|
||||||
useOneNamespaceEffectsLoading('settingModel', ['getUserInfo']);
|
|
||||||
|
|||||||
@ -1,183 +0,0 @@
|
|||||||
import { LanguageTranslationMap } from '@/constants/common';
|
|
||||||
import { ITenantInfo } from '@/interfaces/database/knowledge';
|
|
||||||
import {
|
|
||||||
IFactory,
|
|
||||||
IMyLlmValue,
|
|
||||||
IThirdOAIModelCollection as IThirdAiModelCollection,
|
|
||||||
} from '@/interfaces/database/llm';
|
|
||||||
import { IUserInfo } from '@/interfaces/database/userSetting';
|
|
||||||
import i18n from '@/locales/config';
|
|
||||||
import userService from '@/services/user-service';
|
|
||||||
import { message } from 'antd';
|
|
||||||
import { DvaModel } from 'umi';
|
|
||||||
|
|
||||||
export interface SettingModelState {
|
|
||||||
llm_factory: string;
|
|
||||||
tenantIfo: Nullable<ITenantInfo>;
|
|
||||||
llmInfo: IThirdAiModelCollection;
|
|
||||||
myLlmList: Record<string, IMyLlmValue>;
|
|
||||||
factoryList: IFactory[];
|
|
||||||
userInfo: IUserInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
const model: DvaModel<SettingModelState> = {
|
|
||||||
namespace: 'settingModel',
|
|
||||||
state: {
|
|
||||||
llm_factory: '',
|
|
||||||
tenantIfo: null,
|
|
||||||
llmInfo: {},
|
|
||||||
myLlmList: {},
|
|
||||||
factoryList: [],
|
|
||||||
userInfo: {} as IUserInfo,
|
|
||||||
},
|
|
||||||
reducers: {
|
|
||||||
updateState(state, { payload }) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
...payload,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
setUserInfo(state, { payload }) {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
userInfo: payload,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
effects: {
|
|
||||||
*setting({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.setting, payload);
|
|
||||||
const { retcode } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
message.success(i18n.t('message.modified'));
|
|
||||||
|
|
||||||
yield put({
|
|
||||||
type: 'getUserInfo',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*getUserInfo({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.user_info, payload);
|
|
||||||
const { retcode, data: res } = data;
|
|
||||||
|
|
||||||
// const userInfo = {
|
|
||||||
// avatar: res.avatar,
|
|
||||||
// name: res.nickname,
|
|
||||||
// email: res.email,
|
|
||||||
// };
|
|
||||||
// authorizationUtil.setUserInfo(userInfo);
|
|
||||||
if (retcode === 0) {
|
|
||||||
i18n.changeLanguage(
|
|
||||||
LanguageTranslationMap[
|
|
||||||
res.language as keyof typeof LanguageTranslationMap
|
|
||||||
],
|
|
||||||
);
|
|
||||||
yield put({ type: 'setUserInfo', payload: res });
|
|
||||||
// localStorage.setItem('userInfo',res.)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*getTenantInfo({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.get_tenant_info, payload);
|
|
||||||
const { retcode, data: res } = data;
|
|
||||||
// llm_id 对应chat_id
|
|
||||||
// asr_id 对应speech2txt
|
|
||||||
|
|
||||||
if (retcode === 0) {
|
|
||||||
res.chat_id = res.llm_id;
|
|
||||||
res.speech2text_id = res.asr_id;
|
|
||||||
yield put({
|
|
||||||
type: 'updateState',
|
|
||||||
payload: {
|
|
||||||
tenantIfo: res,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*set_tenant_info({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.set_tenant_info, payload);
|
|
||||||
const { retcode } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
message.success(i18n.t('message.modified'));
|
|
||||||
|
|
||||||
yield put({
|
|
||||||
type: 'getTenantInfo',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return retcode;
|
|
||||||
},
|
|
||||||
|
|
||||||
*factories_list({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.factories_list);
|
|
||||||
const { retcode, data: res } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
yield put({
|
|
||||||
type: 'updateState',
|
|
||||||
payload: {
|
|
||||||
factoryList: res,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*llm_list({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.llm_list, payload);
|
|
||||||
const { retcode, data: res } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
yield put({
|
|
||||||
type: 'updateState',
|
|
||||||
payload: {
|
|
||||||
llmInfo: res,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*my_llm({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.my_llm);
|
|
||||||
const { retcode, data: res } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
yield put({
|
|
||||||
type: 'updateState',
|
|
||||||
payload: {
|
|
||||||
myLlmList: res,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
*set_api_key({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.set_api_key, payload);
|
|
||||||
const { retcode } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
message.success(i18n.t('message.modified'));
|
|
||||||
|
|
||||||
yield put({ type: 'my_llm' });
|
|
||||||
yield put({ type: 'factories_list' });
|
|
||||||
yield put({
|
|
||||||
type: 'updateState',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return retcode;
|
|
||||||
},
|
|
||||||
*add_llm({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.add_llm, payload);
|
|
||||||
const { retcode } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
message.success(i18n.t('message.modified'));
|
|
||||||
|
|
||||||
yield put({ type: 'my_llm' });
|
|
||||||
yield put({ type: 'factories_list' });
|
|
||||||
}
|
|
||||||
return retcode;
|
|
||||||
},
|
|
||||||
*delete_llm({ payload = {} }, { call, put }) {
|
|
||||||
const { data } = yield call(userService.delete_llm, payload);
|
|
||||||
const { retcode } = data;
|
|
||||||
if (retcode === 0) {
|
|
||||||
message.success(i18n.t('message.deleted'));
|
|
||||||
|
|
||||||
yield put({ type: 'my_llm' });
|
|
||||||
yield put({ type: 'factories_list' });
|
|
||||||
}
|
|
||||||
return retcode;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
export default model;
|
|
||||||
@ -8,12 +8,9 @@ import {
|
|||||||
useSaveTenantInfo,
|
useSaveTenantInfo,
|
||||||
useSelectLlmOptionsByModelType,
|
useSelectLlmOptionsByModelType,
|
||||||
} from '@/hooks/llm-hooks';
|
} from '@/hooks/llm-hooks';
|
||||||
import {
|
import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
|
||||||
useFetchTenantInfo,
|
|
||||||
useSelectTenantInfo,
|
|
||||||
} from '@/hooks/user-setting-hooks';
|
|
||||||
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { ApiKeyPostBody } from '../interface';
|
import { ApiKeyPostBody } from '../interface';
|
||||||
|
|
||||||
type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
|
type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
|
||||||
@ -63,7 +60,7 @@ export const useSubmitApiKey = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useSubmitSystemModelSetting = () => {
|
export const useSubmitSystemModelSetting = () => {
|
||||||
const systemSetting = useSelectTenantInfo();
|
const { data: systemSetting } = useFetchTenantInfo();
|
||||||
const { saveTenantInfo: saveSystemModelSetting, loading } =
|
const { saveTenantInfo: saveSystemModelSetting, loading } =
|
||||||
useSaveTenantInfo();
|
useSaveTenantInfo();
|
||||||
const {
|
const {
|
||||||
@ -98,16 +95,9 @@ export const useSubmitSystemModelSetting = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFetchSystemModelSettingOnMount = (visible: boolean) => {
|
export const useFetchSystemModelSettingOnMount = () => {
|
||||||
const systemSetting = useSelectTenantInfo();
|
const { data: systemSetting } = useFetchTenantInfo();
|
||||||
const allOptions = useSelectLlmOptionsByModelType();
|
const allOptions = useSelectLlmOptionsByModelType();
|
||||||
const fetchTenantInfo = useFetchTenantInfo();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (visible) {
|
|
||||||
fetchTenantInfo();
|
|
||||||
}
|
|
||||||
}, [fetchTenantInfo, visible]);
|
|
||||||
|
|
||||||
return { systemSetting, allOptions };
|
return { systemSetting, allOptions };
|
||||||
};
|
};
|
||||||
|
|||||||
@ -264,12 +264,14 @@ const UserSettingModel = () => {
|
|||||||
onOk={onApiKeySavingOk}
|
onOk={onApiKeySavingOk}
|
||||||
llmFactory={llmFactory}
|
llmFactory={llmFactory}
|
||||||
></ApiKeyModal>
|
></ApiKeyModal>
|
||||||
<SystemModelSettingModal
|
{systemSettingVisible && (
|
||||||
visible={systemSettingVisible}
|
<SystemModelSettingModal
|
||||||
onOk={onSystemSettingSavingOk}
|
visible={systemSettingVisible}
|
||||||
hideModal={hideSystemSettingModal}
|
onOk={onSystemSettingSavingOk}
|
||||||
loading={saveSystemModelSettingLoading}
|
hideModal={hideSystemSettingModal}
|
||||||
></SystemModelSettingModal>
|
loading={saveSystemModelSettingLoading}
|
||||||
|
></SystemModelSettingModal>
|
||||||
|
)}
|
||||||
<OllamaModal
|
<OllamaModal
|
||||||
visible={llmAddingVisible}
|
visible={llmAddingVisible}
|
||||||
hideModal={hideLlmAddingModal}
|
hideModal={hideLlmAddingModal}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ const SystemModelSettingModal = ({
|
|||||||
}: IProps) => {
|
}: IProps) => {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const { systemSetting: initialValues, allOptions } =
|
const { systemSetting: initialValues, allOptions } =
|
||||||
useFetchSystemModelSettingOnMount(visible);
|
useFetchSystemModelSettingOnMount();
|
||||||
const { t } = useTranslate('setting');
|
const { t } = useTranslate('setting');
|
||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
|
||||||
import { useSaveSetting } from '@/hooks/user-setting-hooks';
|
import { useSaveSetting } from '@/hooks/user-setting-hooks';
|
||||||
import { rsaPsw } from '@/utils';
|
import { rsaPsw } from '@/utils';
|
||||||
import { Button, Divider, Form, Input, Space } from 'antd';
|
import { Button, Divider, Form, Input, Space } from 'antd';
|
||||||
@ -19,9 +18,8 @@ const tailLayout = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const UserSettingPassword = () => {
|
const UserSettingPassword = () => {
|
||||||
const loading = useOneNamespaceEffectsLoading('settingModel', ['setting']);
|
|
||||||
const { form, submittable } = useValidateSubmittable();
|
const { form, submittable } = useValidateSubmittable();
|
||||||
const saveSetting = useSaveSetting();
|
const { saveSetting, loading } = useSaveSetting();
|
||||||
const { t } = useTranslate('setting');
|
const { t } = useTranslate('setting');
|
||||||
|
|
||||||
const onFinish = (values: any) => {
|
const onFinish = (values: any) => {
|
||||||
|
|||||||
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { useFetchUserInfo, useSaveSetting } from '@/hooks/user-setting-hooks';
|
||||||
useFetchUserInfo,
|
|
||||||
useSaveSetting,
|
|
||||||
useSelectUserInfo,
|
|
||||||
} from '@/hooks/user-setting-hooks';
|
|
||||||
import {
|
import {
|
||||||
getBase64FromUploadFileList,
|
getBase64FromUploadFileList,
|
||||||
getUploadFileListFromBase64,
|
getUploadFileListFromBase64,
|
||||||
@ -24,11 +20,7 @@ import camelCase from 'lodash/camelCase';
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import SettingTitle from '../components/setting-title';
|
import SettingTitle from '../components/setting-title';
|
||||||
import { TimezoneList } from '../constants';
|
import { TimezoneList } from '../constants';
|
||||||
import {
|
import { useValidateSubmittable } from '../hooks';
|
||||||
useSelectSubmitUserInfoLoading,
|
|
||||||
useSelectUserInfoLoading,
|
|
||||||
useValidateSubmittable,
|
|
||||||
} from '../hooks';
|
|
||||||
|
|
||||||
import { LanguageList } from '@/constants/common';
|
import { LanguageList } from '@/constants/common';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
@ -52,12 +44,9 @@ const tailLayout = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const UserSettingProfile = () => {
|
const UserSettingProfile = () => {
|
||||||
const userInfo = useSelectUserInfo();
|
const { data: userInfo, loading } = useFetchUserInfo();
|
||||||
const saveSetting = useSaveSetting();
|
const { saveSetting, loading: submitLoading } = useSaveSetting();
|
||||||
const submitLoading = useSelectSubmitUserInfoLoading();
|
|
||||||
const { form, submittable } = useValidateSubmittable();
|
const { form, submittable } = useValidateSubmittable();
|
||||||
const loading = useSelectUserInfoLoading();
|
|
||||||
useFetchUserInfo();
|
|
||||||
const { t } = useTranslate('setting');
|
const { t } = useTranslate('setting');
|
||||||
const changeLanguage = useChangeLanguage();
|
const changeLanguage = useChangeLanguage();
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { Button, Card, Flex } from 'antd';
|
import { Button, Card, Flex } from 'antd';
|
||||||
|
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
|
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
|
||||||
const UserSettingTeam = () => {
|
const UserSettingTeam = () => {
|
||||||
const userInfo = useSelectUserInfo();
|
const { data: userInfo } = useFetchUserInfo();
|
||||||
const { t } = useTranslate('setting');
|
const { t } = useTranslate('setting');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
2
web/typings.d.ts
vendored
2
web/typings.d.ts
vendored
@ -3,7 +3,6 @@ import { KFModelState } from '@/pages/add-knowledge/components/knowledge-file/mo
|
|||||||
import { TestingModelState } from '@/pages/add-knowledge/components/knowledge-testing/model';
|
import { TestingModelState } from '@/pages/add-knowledge/components/knowledge-testing/model';
|
||||||
import { kAModelState } from '@/pages/add-knowledge/model';
|
import { kAModelState } from '@/pages/add-knowledge/model';
|
||||||
import { ChatModelState } from '@/pages/chat/model';
|
import { ChatModelState } from '@/pages/chat/model';
|
||||||
import { SettingModelState } from '@/pages/user-setting/model';
|
|
||||||
|
|
||||||
declare module 'lodash';
|
declare module 'lodash';
|
||||||
|
|
||||||
@ -14,7 +13,6 @@ function useSelector<TState = RootState, TSelected = unknown>(
|
|||||||
|
|
||||||
export interface RootState {
|
export interface RootState {
|
||||||
chatModel: ChatModelState;
|
chatModel: ChatModelState;
|
||||||
settingModel: SettingModelState;
|
|
||||||
kFModel: KFModelState;
|
kFModel: KFModelState;
|
||||||
kAModel: kAModelState;
|
kAModel: kAModelState;
|
||||||
chunkModel: ChunkModelState;
|
chunkModel: ChunkModelState;
|
||||||
|
|||||||
Reference in New Issue
Block a user