feat: add SystemModelSettingModal (#127)

* feat: add the model

* feat: add SystemModelSettingModal
This commit is contained in:
balibabu
2024-03-15 19:35:59 +08:00
committed by GitHub
parent 2447f95629
commit a0f1e1fa95
10 changed files with 311 additions and 66 deletions

View File

@@ -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;
};