balibabu commited on
Commit
3fb07ee
·
1 Parent(s): c957852

feat: add base_url to ApiKeyModal (#167)

Browse files
web/src/hooks/llmHooks.ts CHANGED
@@ -163,7 +163,7 @@ export interface IApiKeySavingParams {
163
  api_key: string;
164
  llm_name?: string;
165
  model_type?: string;
166
- api_base?: string;
167
  }
168
 
169
  export const useSaveApiKey = () => {
 
163
  api_key: string;
164
  llm_name?: string;
165
  model_type?: string;
166
+ base_url?: string;
167
  }
168
 
169
  export const useSaveApiKey = () => {
web/src/pages/user-setting/setting-model/api-key-modal/index.tsx CHANGED
@@ -5,17 +5,20 @@ import { useEffect } from 'react';
5
  interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
6
  loading: boolean;
7
  initialValue: string;
8
- onOk: (name: string) => void;
 
9
  showModal?(): void;
10
  }
11
 
12
  type FieldType = {
13
  api_key?: string;
 
14
  };
15
 
16
  const ApiKeyModal = ({
17
  visible,
18
  hideModal,
 
19
  loading,
20
  initialValue,
21
  onOk,
@@ -25,7 +28,7 @@ const ApiKeyModal = ({
25
  const handleOk = async () => {
26
  const ret = await form.validateFields();
27
 
28
- return onOk(ret.api_key);
29
  };
30
 
31
  const handleCancel = () => {
@@ -55,8 +58,8 @@ const ApiKeyModal = ({
55
  >
56
  <Form
57
  name="basic"
58
- labelCol={{ span: 4 }}
59
- wrapperCol={{ span: 20 }}
60
  style={{ maxWidth: 600 }}
61
  onFinish={onFinish}
62
  onFinishFailed={onFinishFailed}
@@ -71,6 +74,16 @@ const ApiKeyModal = ({
71
  >
72
  <Input />
73
  </Form.Item>
 
 
 
 
 
 
 
 
 
 
74
  </Form>
75
  </Modal>
76
  );
 
5
  interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
6
  loading: boolean;
7
  initialValue: string;
8
+ llmFactory: string;
9
+ onOk: (name: string, baseUrl: string) => void;
10
  showModal?(): void;
11
  }
12
 
13
  type FieldType = {
14
  api_key?: string;
15
+ base_url?: string;
16
  };
17
 
18
  const ApiKeyModal = ({
19
  visible,
20
  hideModal,
21
+ llmFactory,
22
  loading,
23
  initialValue,
24
  onOk,
 
28
  const handleOk = async () => {
29
  const ret = await form.validateFields();
30
 
31
+ return onOk(ret.api_key, ret.base_url);
32
  };
33
 
34
  const handleCancel = () => {
 
58
  >
59
  <Form
60
  name="basic"
61
+ labelCol={{ span: 6 }}
62
+ wrapperCol={{ span: 18 }}
63
  style={{ maxWidth: 600 }}
64
  onFinish={onFinish}
65
  onFinishFailed={onFinishFailed}
 
74
  >
75
  <Input />
76
  </Form.Item>
77
+ {llmFactory === 'OpenAI' && (
78
+ <Form.Item<FieldType>
79
+ label="Base-Url"
80
+ name="base_url"
81
+ tooltip="The API key can be obtained by registering the corresponding LLM supplier."
82
+ rules={[{ required: true, message: 'Please input base url!' }]}
83
+ >
84
+ <Input />
85
+ </Form.Item>
86
+ )}
87
  </Form>
88
  </Modal>
89
  );
web/src/pages/user-setting/setting-model/hooks.ts CHANGED
@@ -28,8 +28,12 @@ export const useSubmitApiKey = () => {
28
  } = useSetModalState();
29
 
30
  const onApiKeySavingOk = useCallback(
31
- async (apiKey: string) => {
32
- const ret = await saveApiKey({ ...savingParams, api_key: apiKey });
 
 
 
 
33
 
34
  if (ret === 0) {
35
  hideApiKeyModal();
@@ -53,6 +57,7 @@ export const useSubmitApiKey = () => {
53
  return {
54
  saveApiKeyLoading: loading,
55
  initialApiKey: '',
 
56
  onApiKeySavingOk,
57
  apiKeyVisible,
58
  hideApiKeyModal,
 
28
  } = useSetModalState();
29
 
30
  const onApiKeySavingOk = useCallback(
31
+ async (apiKey: string, baseUrl: string) => {
32
+ const ret = await saveApiKey({
33
+ ...savingParams,
34
+ api_key: apiKey,
35
+ base_url: baseUrl,
36
+ });
37
 
38
  if (ret === 0) {
39
  hideApiKeyModal();
 
57
  return {
58
  saveApiKeyLoading: loading,
59
  initialApiKey: '',
60
+ llmFactory: savingParams.llm_factory,
61
  onApiKeySavingOk,
62
  apiKeyVisible,
63
  hideApiKeyModal,
web/src/pages/user-setting/setting-model/index.tsx CHANGED
@@ -120,6 +120,7 @@ const UserSettingModel = () => {
120
  const {
121
  saveApiKeyLoading,
122
  initialApiKey,
 
123
  onApiKeySavingOk,
124
  apiKeyVisible,
125
  hideApiKeyModal,
@@ -215,6 +216,7 @@ const UserSettingModel = () => {
215
  loading={saveApiKeyLoading}
216
  initialValue={initialApiKey}
217
  onOk={onApiKeySavingOk}
 
218
  ></ApiKeyModal>
219
  <SystemModelSettingModal
220
  visible={systemSettingVisible}
 
120
  const {
121
  saveApiKeyLoading,
122
  initialApiKey,
123
+ llmFactory,
124
  onApiKeySavingOk,
125
  apiKeyVisible,
126
  hideApiKeyModal,
 
216
  loading={saveApiKeyLoading}
217
  initialValue={initialApiKey}
218
  onOk={onApiKeySavingOk}
219
+ llmFactory={llmFactory}
220
  ></ApiKeyModal>
221
  <SystemModelSettingModal
222
  visible={systemSettingVisible}