From 7bae41c71fcceaad18ba5f4522e001e2e15ab6e8 Mon Sep 17 00:00:00 2001 From: balibabu <cike8899@users.noreply.github.com> Date: Fri, 29 Mar 2024 09:52:19 +0800 Subject: [PATCH] feat: add base_url to ApiKeyModal (#167) --- web/src/hooks/llmHooks.ts | 2 +- .../setting-model/api-key-modal/index.tsx | 21 +++++++++++++++---- .../pages/user-setting/setting-model/hooks.ts | 9 ++++++-- .../user-setting/setting-model/index.tsx | 2 ++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/web/src/hooks/llmHooks.ts b/web/src/hooks/llmHooks.ts index 7c3e243..3e2e757 100644 --- a/web/src/hooks/llmHooks.ts +++ b/web/src/hooks/llmHooks.ts @@ -163,7 +163,7 @@ export interface IApiKeySavingParams { api_key: string; llm_name?: string; model_type?: string; - api_base?: string; + base_url?: string; } export const useSaveApiKey = () => { diff --git a/web/src/pages/user-setting/setting-model/api-key-modal/index.tsx b/web/src/pages/user-setting/setting-model/api-key-modal/index.tsx index d35186e..b77d68e 100644 --- a/web/src/pages/user-setting/setting-model/api-key-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/api-key-modal/index.tsx @@ -5,17 +5,20 @@ import { useEffect } from 'react'; interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> { loading: boolean; initialValue: string; - onOk: (name: string) => void; + llmFactory: string; + onOk: (name: string, baseUrl: string) => void; showModal?(): void; } type FieldType = { api_key?: string; + base_url?: string; }; const ApiKeyModal = ({ visible, hideModal, + llmFactory, loading, initialValue, onOk, @@ -25,7 +28,7 @@ const ApiKeyModal = ({ const handleOk = async () => { const ret = await form.validateFields(); - return onOk(ret.api_key); + return onOk(ret.api_key, ret.base_url); }; const handleCancel = () => { @@ -55,8 +58,8 @@ const ApiKeyModal = ({ > <Form name="basic" - labelCol={{ span: 4 }} - wrapperCol={{ span: 20 }} + labelCol={{ span: 6 }} + wrapperCol={{ span: 18 }} style={{ maxWidth: 600 }} onFinish={onFinish} onFinishFailed={onFinishFailed} @@ -71,6 +74,16 @@ const ApiKeyModal = ({ > <Input /> </Form.Item> + {llmFactory === 'OpenAI' && ( + <Form.Item<FieldType> + label="Base-Url" + name="base_url" + tooltip="The API key can be obtained by registering the corresponding LLM supplier." + rules={[{ required: true, message: 'Please input base url!' }]} + > + <Input /> + </Form.Item> + )} </Form> </Modal> ); diff --git a/web/src/pages/user-setting/setting-model/hooks.ts b/web/src/pages/user-setting/setting-model/hooks.ts index af400bb..f36aa02 100644 --- a/web/src/pages/user-setting/setting-model/hooks.ts +++ b/web/src/pages/user-setting/setting-model/hooks.ts @@ -28,8 +28,12 @@ export const useSubmitApiKey = () => { } = useSetModalState(); const onApiKeySavingOk = useCallback( - async (apiKey: string) => { - const ret = await saveApiKey({ ...savingParams, api_key: apiKey }); + async (apiKey: string, baseUrl: string) => { + const ret = await saveApiKey({ + ...savingParams, + api_key: apiKey, + base_url: baseUrl, + }); if (ret === 0) { hideApiKeyModal(); @@ -53,6 +57,7 @@ export const useSubmitApiKey = () => { return { saveApiKeyLoading: loading, initialApiKey: '', + llmFactory: savingParams.llm_factory, onApiKeySavingOk, apiKeyVisible, hideApiKeyModal, diff --git a/web/src/pages/user-setting/setting-model/index.tsx b/web/src/pages/user-setting/setting-model/index.tsx index 7186a59..17c7e15 100644 --- a/web/src/pages/user-setting/setting-model/index.tsx +++ b/web/src/pages/user-setting/setting-model/index.tsx @@ -120,6 +120,7 @@ const UserSettingModel = () => { const { saveApiKeyLoading, initialApiKey, + llmFactory, onApiKeySavingOk, apiKeyVisible, hideApiKeyModal, @@ -215,6 +216,7 @@ const UserSettingModel = () => { loading={saveApiKeyLoading} initialValue={initialApiKey} onOk={onApiKeySavingOk} + llmFactory={llmFactory} ></ApiKeyModal> <SystemModelSettingModal visible={systemSettingVisible} -- GitLab