From b4a160b680a4e76e7ba53d7f387bdb87c9bced67 Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Fri, 17 Jan 2025 20:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20api=20key=20in=20ap?= =?UTF-8?q?i=20key=20form=20(#5498)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix api key * fix client fetch --- .../Error/APIKeyForm/ProviderApiKeyForm.tsx | 11 ++---- .../Error/APIKeyForm/useApiKey.ts | 34 +++++++++++++++++++ .../aiInfra/slices/aiProvider/selectors.ts | 28 +++++++-------- src/types/aiProvider.ts | 2 +- 4 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 src/features/Conversation/Error/APIKeyForm/useApiKey.ts diff --git a/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx b/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx index df0b5156f7d8..ad38774fc10d 100644 --- a/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx +++ b/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx @@ -6,11 +6,10 @@ import { useTranslation } from 'react-i18next'; import { useProviderName } from '@/hooks/useProviderName'; import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig'; -import { useUserStore } from '@/store/user'; -import { keyVaultsConfigSelectors } from '@/store/user/selectors'; import { GlobalLLMProviderKey } from '@/types/user/settings'; import { FormAction } from '../style'; +import { useApiKey } from './useApiKey'; interface ProviderApiKeyFormProps { apiKeyPlaceholder?: string; @@ -25,11 +24,7 @@ const ProviderApiKeyForm = memo( const { t: errorT } = useTranslation('error'); const [showProxy, setShow] = useState(false); - const [apiKey, proxyUrl, setConfig] = useUserStore((s) => [ - keyVaultsConfigSelectors.getVaultByProvider(provider)(s)?.apiKey, - keyVaultsConfigSelectors.getVaultByProvider(provider)(s)?.baseURL, - s.updateKeyVaultConfig, - ]); + const { apiKey, baseURL, setConfig } = useApiKey(provider); const { showOpenAIProxyUrl } = useServerConfigStore(featureFlagsSelectors); const providerName = useProviderName(provider); @@ -58,7 +53,7 @@ const ProviderApiKeyForm = memo( }} placeholder={'https://api.openai.com/v1'} type={'block'} - value={proxyUrl} + value={baseURL} /> ) : (