diff --git a/web/default/src/pages/Channel/EditChannel.js b/web/default/src/pages/Channel/EditChannel.js index f10658c3..a0cb757e 100644 --- a/web/default/src/pages/Channel/EditChannel.js +++ b/web/default/src/pages/Channel/EditChannel.js @@ -1,13 +1,29 @@ import React, { useEffect, useState } from 'react'; -import { Button, Form, Header, Input, Message, Segment } from 'semantic-ui-react'; +import { + Button, + Form, + Header, + Input, + Message, + Segment, + Card, +} from 'semantic-ui-react'; import { useNavigate, useParams } from 'react-router-dom'; -import { API, copy, getChannelModels, showError, showInfo, showSuccess, verifyJSON } from '../../helpers'; +import { + API, + copy, + getChannelModels, + showError, + showInfo, + showSuccess, + verifyJSON, +} from '../../helpers'; import { CHANNEL_OPTIONS } from '../../constants'; const MODEL_MAPPING_EXAMPLE = { 'gpt-3.5-turbo-0301': 'gpt-3.5-turbo', 'gpt-4-0314': 'gpt-4', - 'gpt-4-32k-0314': 'gpt-4-32k' + 'gpt-4-32k-0314': 'gpt-4-32k', }; function type2secretPrompt(type) { @@ -45,7 +61,7 @@ const EditChannel = () => { model_mapping: '', system_prompt: '', models: [], - groups: ['default'] + groups: ['default'], }; const [batch, setBatch] = useState(false); const [inputs, setInputs] = useState(originInputs); @@ -61,7 +77,7 @@ const EditChannel = () => { ak: '', user_id: '', vertex_ai_project_id: '', - vertex_ai_adc: '' + vertex_ai_adc: '', }); const handleInputChange = (e, { name, value }) => { setInputs((inputs) => ({ ...inputs, [name]: value })); @@ -93,7 +109,11 @@ const EditChannel = () => { data.groups = data.group.split(','); } if (data.model_mapping !== '') { - data.model_mapping = JSON.stringify(JSON.parse(data.model_mapping), null, 2); + data.model_mapping = JSON.stringify( + JSON.parse(data.model_mapping), + null, + 2 + ); } setInputs(data); if (data.config !== '') { @@ -112,7 +132,7 @@ const EditChannel = () => { let localModelOptions = res.data.data.map((model) => ({ key: model.id, text: model.id, - value: model.id + value: model.id, })); setOriginModelOptions(localModelOptions); setFullModels(res.data.data.map((model) => model.id)); @@ -124,11 +144,13 @@ const EditChannel = () => { const fetchGroups = async () => { try { let res = await API.get(`/api/group/`); - setGroupOptions(res.data.data.map((group) => ({ - key: group, - text: group, - value: group - }))); + setGroupOptions( + res.data.data.map((group) => ({ + key: group, + text: group, + value: group, + })) + ); } catch (error) { showError(error.message); } @@ -141,7 +163,7 @@ const EditChannel = () => { localModelOptions.push({ key: model, text: model, - value: model + value: model, }); } }); @@ -163,7 +185,11 @@ const EditChannel = () => { if (inputs.key === '') { if (config.ak !== '' && config.sk !== '' && config.region !== '') { inputs.key = `${config.ak}|${config.sk}|${config.region}`; - } else if (config.region !== '' && config.vertex_ai_project_id !== '' && config.vertex_ai_adc !== '') { + } else if ( + config.region !== '' && + config.vertex_ai_project_id !== '' && + config.vertex_ai_adc !== '' + ) { inputs.key = `${config.region}|${config.vertex_ai_project_id}|${config.vertex_ai_adc}`; } } @@ -179,9 +205,12 @@ const EditChannel = () => { showInfo('模型映射必须是合法的 JSON 格式!'); return; } - let localInputs = {...inputs}; + let localInputs = { ...inputs }; if (localInputs.base_url && localInputs.base_url.endsWith('/')) { - localInputs.base_url = localInputs.base_url.slice(0, localInputs.base_url.length - 1); + localInputs.base_url = localInputs.base_url.slice( + 0, + localInputs.base_url.length - 1 + ); } if (localInputs.type === 3 && localInputs.other === '') { localInputs.other = '2024-03-01-preview'; @@ -191,7 +220,10 @@ const EditChannel = () => { localInputs.group = localInputs.groups.join(','); localInputs.config = JSON.stringify(config); if (isEdit) { - res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) }); + res = await API.put(`/api/channel/`, { + ...localInputs, + id: parseInt(channelId), + }); } else { res = await API.post(`/api/channel/`, localInputs); } @@ -217,9 +249,9 @@ const EditChannel = () => { localModelOptions.push({ key: customModel, text: customModel, - value: customModel + value: customModel, }); - setModelOptions(modelOptions => { + setModelOptions((modelOptions) => { return [...modelOptions, ...localModelOptions]; }); setCustomModel(''); @@ -227,34 +259,45 @@ const EditChannel = () => { }; return ( - <> - -
{isEdit ? '更新渠道信息' : '创建新的渠道'}
-
- - - - { - inputs.type === 3 && ( +
+ + + + {isEdit ? '更新渠道信息' : '创建新的渠道'} + + + + + + {inputs.type === 3 && ( <> - 注意,模型部署名称必须和模型名称保持一致,因为 One API 会把请求体中的 model - 参数替换为你的部署名称(模型名称中的点会被剔除),图片演示。 + 注意,模型部署名称必须和模型名称保持一致,因为 + One API 会把请求体中的 model + 参数替换为你的部署名称(模型名称中的点会被剔除), + + 图片演示 + + 。 { - ) - } - { - inputs.type === 8 && ( + )} + {inputs.type === 8 && ( - ) - } - - - - - - - { - inputs.type === 18 && ( + )} + + + + + + + {inputs.type === 18 && ( - ) - } - { - inputs.type === 21 && ( + )} + {inputs.type === 21 && ( { autoComplete='new-password' /> - ) - } - { - inputs.type === 17 && ( + )} + {inputs.type === 17 && ( - ) - } - { - inputs.type === 34 && ( + )} + {inputs.type === 34 && ( - 对于 Coze 而言,模型名称即 Bot ID,你可以添加一个前缀 `bot-`,例如:`bot-123456`。 + 对于 Coze 而言,模型名称即 Bot ID,你可以添加一个前缀 + `bot-`,例如:`bot-123456`。 - ) - } - { - inputs.type === 40 && ( + )} + {inputs.type === 40 && ( - 对于豆包而言,需要手动去 模型推理页面 创建推理接入点,以接入点名称作为模型名称,例如:`ep-20240608051426-tkxvl`。 + 对于豆包而言,需要手动去{' '} + + 模型推理页面 + {' '} + 创建推理接入点,以接入点名称作为模型名称,例如:`ep-20240608051426-tkxvl`。 - ) - } - { - inputs.type !== 43 && ( + )} + {inputs.type !== 43 && ( { options={modelOptions} /> - ) - } - { - inputs.type !== 43 && ( + )} + {inputs.type !== 43 && (
- - - + + + 填入 + } placeholder='输入自定义模型名称' value={customModel} @@ -423,37 +488,44 @@ const EditChannel = () => { }} />
- ) - } - { - inputs.type !== 43 && (<> - - - - - - + )} + {inputs.type !== 43 && ( + <> + + + + + + - ) - } - { - inputs.type === 33 && ( + )} + {inputs.type === 33 && ( { autoComplete='' /> - ) - } - { - inputs.type === 42 && ( + )} + {inputs.type === 42 && ( { label='Google Cloud Application Default Credentials JSON' name='vertex_ai_adc' required - placeholder={'Google Cloud Application Default Credentials JSON'} + placeholder={ + 'Google Cloud Application Default Credentials JSON' + } onChange={handleConfigChange} value={config.vertex_ai_adc} autoComplete='' /> - ) - } - { - inputs.type === 34 && ( + )} + {inputs.type === 34 && ( { onChange={handleConfigChange} value={config.user_id} autoComplete='' - />) - } - { - inputs.type !== 33 && inputs.type !== 42 && (batch ? - - : - - ) - } - { - inputs.type === 37 && ( + )} + {inputs.type !== 33 && + inputs.type !== 42 && + (batch ? ( + + + + ) : ( + + + + ))} + {inputs.type === 37 && ( - ) - } - { - inputs.type !== 33 && !isEdit && ( + )} + {inputs.type !== 33 && !isEdit && ( setBatch(!batch)} /> - ) - } - { - inputs.type !== 3 && inputs.type !== 33 && inputs.type !== 8 && inputs.type !== 22 && ( - - - - ) - } - { - inputs.type === 22 && ( + )} + {inputs.type !== 3 && + inputs.type !== 33 && + inputs.type !== 8 && + inputs.type !== 22 && ( + + + + )} + {inputs.type === 22 && ( - ) - } - - - - - + )} + + + +
+
+
); }; diff --git a/web/default/src/pages/Dashboard/Dashboard.css b/web/default/src/pages/Dashboard/Dashboard.css index 15effbb1..6bb1a40c 100644 --- a/web/default/src/pages/Dashboard/Dashboard.css +++ b/web/default/src/pages/Dashboard/Dashboard.css @@ -54,7 +54,6 @@ justify-content: space-between; align-items: center; font-weight: 600; - padding: 0 8px; gap: 12px; /* 增加标题和数值之间的间距 */ }