feat: submit api key and add language to Configuration and fetch llm factory list on UserSettingModel mount (#121)
* feat: fetch llm factory list on UserSettingModel mount * feat: add language to Configuration * feat: submit api key
This commit is contained in:
50
web/src/pages/user-setting/setting-model/hooks.ts
Normal file
50
web/src/pages/user-setting/setting-model/hooks.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { useSetModalState } from '@/hooks/commonHooks';
|
||||
import { IApiKeySavingParams, useSaveApiKey } from '@/hooks/llmHooks';
|
||||
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
|
||||
|
||||
export const useSubmitApiKey = () => {
|
||||
const [savingParams, setSavingParams] = useState<SavingParamsState>(
|
||||
{} as SavingParamsState,
|
||||
);
|
||||
const saveApiKey = useSaveApiKey();
|
||||
const {
|
||||
visible: apiKeyVisible,
|
||||
hideModal: hideApiKeyModal,
|
||||
showModal: showApiKeyModal,
|
||||
} = useSetModalState();
|
||||
|
||||
const onApiKeySavingOk = useCallback(
|
||||
async (apiKey: string) => {
|
||||
const ret = await saveApiKey({ ...savingParams, api_key: apiKey });
|
||||
|
||||
if (ret.retcode === 0) {
|
||||
hideApiKeyModal();
|
||||
}
|
||||
},
|
||||
[hideApiKeyModal, saveApiKey, savingParams],
|
||||
);
|
||||
|
||||
const onShowApiKeyModal = useCallback(
|
||||
(savingParams: SavingParamsState) => {
|
||||
setSavingParams(savingParams);
|
||||
showApiKeyModal();
|
||||
},
|
||||
[showApiKeyModal, setSavingParams],
|
||||
);
|
||||
|
||||
const loading = useOneNamespaceEffectsLoading('settingModel', [
|
||||
'set_api_key',
|
||||
]);
|
||||
|
||||
return {
|
||||
saveApiKeyLoading: loading,
|
||||
initialApiKey: '',
|
||||
onApiKeySavingOk,
|
||||
apiKeyVisible,
|
||||
hideApiKeyModal,
|
||||
showApiKeyModal: onShowApiKeyModal,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user