feat: add SystemModelSettingModal (#127)
* feat: add the model * feat: add SystemModelSettingModal
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
import { useSetModalState } from '@/hooks/commonHooks';
|
||||
import { IApiKeySavingParams, useSaveApiKey } from '@/hooks/llmHooks';
|
||||
import {
|
||||
IApiKeySavingParams,
|
||||
ISystemModelSettingSavingParams,
|
||||
useFetchLlmList,
|
||||
useSaveApiKey,
|
||||
useSaveTenantInfo,
|
||||
} from '@/hooks/llmHooks';
|
||||
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
|
||||
import {
|
||||
useFetchTenantInfo,
|
||||
useSelectTenantInfo,
|
||||
} from '@/hooks/userSettingHook';
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
|
||||
@@ -20,7 +30,7 @@ export const useSubmitApiKey = () => {
|
||||
async (apiKey: string) => {
|
||||
const ret = await saveApiKey({ ...savingParams, api_key: apiKey });
|
||||
|
||||
if (ret.retcode === 0) {
|
||||
if (ret === 0) {
|
||||
hideApiKeyModal();
|
||||
}
|
||||
},
|
||||
@@ -48,3 +58,49 @@ export const useSubmitApiKey = () => {
|
||||
showApiKeyModal: onShowApiKeyModal,
|
||||
};
|
||||
};
|
||||
|
||||
export const useSubmitSystemModelSetting = () => {
|
||||
const systemSetting = useSelectTenantInfo();
|
||||
const loading = useOneNamespaceEffectsLoading('settingModel', [
|
||||
'set_tenant_info',
|
||||
]);
|
||||
const saveSystemModelSetting = useSaveTenantInfo();
|
||||
const {
|
||||
visible: systemSettingVisible,
|
||||
hideModal: hideSystemSettingModal,
|
||||
showModal: showSystemSettingModal,
|
||||
} = useSetModalState();
|
||||
|
||||
const onSystemSettingSavingOk = useCallback(
|
||||
async (
|
||||
payload: Omit<ISystemModelSettingSavingParams, 'tenant_id' | 'name'>,
|
||||
) => {
|
||||
const ret = await saveSystemModelSetting({
|
||||
tenant_id: systemSetting.tenant_id,
|
||||
name: systemSetting.name,
|
||||
...payload,
|
||||
});
|
||||
|
||||
if (ret === 0) {
|
||||
hideSystemSettingModal();
|
||||
}
|
||||
},
|
||||
[hideSystemSettingModal, saveSystemModelSetting, systemSetting],
|
||||
);
|
||||
|
||||
return {
|
||||
saveSystemModelSettingLoading: loading,
|
||||
onSystemSettingSavingOk,
|
||||
systemSettingVisible,
|
||||
hideSystemSettingModal,
|
||||
showSystemSettingModal,
|
||||
};
|
||||
};
|
||||
|
||||
export const useFetchSystemModelSettingOnMount = () => {
|
||||
const systemSetting = useSelectTenantInfo();
|
||||
useFetchLlmList();
|
||||
useFetchTenantInfo();
|
||||
|
||||
return systemSetting;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user