2023-04-23 04:43:10 +00:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2023-07-15 05:51:46 +00:00
|
|
|
|
import { Button, Form, Header, Input, Message, Segment } from 'semantic-ui-react';
|
2023-08-27 08:16:45 +00:00
|
|
|
|
import { useNavigate, useParams } from 'react-router-dom';
|
2023-06-27 05:42:45 +00:00
|
|
|
|
import { API, showError, showInfo, showSuccess, verifyJSON } from '../../helpers';
|
2023-04-23 07:42:23 +00:00
|
|
|
|
import { CHANNEL_OPTIONS } from '../../constants';
|
2023-04-23 04:43:10 +00:00
|
|
|
|
|
2023-06-28 04:56:01 +00:00
|
|
|
|
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'
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-03 07:50:49 +00:00
|
|
|
|
function type2secretPrompt(type) {
|
|
|
|
|
// inputs.type === 15 ? '按照如下格式输入:APIKey|SecretKey' : (inputs.type === 18 ? '按照如下格式输入:APPID|APISecret|APIKey' : '请输入渠道对应的鉴权密钥')
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 15:
|
2023-09-03 13:40:58 +00:00
|
|
|
|
return '按照如下格式输入:APIKey|SecretKey';
|
2023-09-03 07:50:49 +00:00
|
|
|
|
case 18:
|
2023-09-03 13:40:58 +00:00
|
|
|
|
return '按照如下格式输入:APPID|APISecret|APIKey';
|
2023-09-03 07:50:49 +00:00
|
|
|
|
case 22:
|
2023-09-03 13:40:58 +00:00
|
|
|
|
return '按照如下格式输入:APIKey-AppId,例如:fastgpt-0sp2gtvfdgyi4k30jwlgwf1i-64f335d84283f05518e9e041';
|
2023-10-03 06:19:03 +00:00
|
|
|
|
case 23:
|
|
|
|
|
return '按照如下格式输入:AppId|SecretId|SecretKey';
|
2023-09-03 07:50:49 +00:00
|
|
|
|
default:
|
2023-09-03 13:40:58 +00:00
|
|
|
|
return '请输入渠道对应的鉴权密钥';
|
2023-09-03 07:50:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-23 04:43:10 +00:00
|
|
|
|
const EditChannel = () => {
|
|
|
|
|
const params = useParams();
|
2023-08-12 02:49:30 +00:00
|
|
|
|
const navigate = useNavigate();
|
2023-04-23 07:42:23 +00:00
|
|
|
|
const channelId = params.id;
|
2023-05-13 03:36:36 +00:00
|
|
|
|
const isEdit = channelId !== undefined;
|
|
|
|
|
const [loading, setLoading] = useState(isEdit);
|
2023-08-12 02:49:30 +00:00
|
|
|
|
const handleCancel = () => {
|
|
|
|
|
navigate('/channel');
|
|
|
|
|
};
|
2023-08-27 08:16:45 +00:00
|
|
|
|
|
2023-05-13 03:36:36 +00:00
|
|
|
|
const originInputs = {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
name: '',
|
|
|
|
|
type: 1,
|
2023-05-13 03:36:36 +00:00
|
|
|
|
key: '',
|
2023-05-13 04:53:57 +00:00
|
|
|
|
base_url: '',
|
2023-06-07 15:26:00 +00:00
|
|
|
|
other: '',
|
2023-06-28 04:56:01 +00:00
|
|
|
|
model_mapping: '',
|
2023-06-07 15:26:00 +00:00
|
|
|
|
models: [],
|
2023-06-14 04:14:08 +00:00
|
|
|
|
groups: ['default']
|
2023-05-13 03:36:36 +00:00
|
|
|
|
};
|
2023-05-13 09:08:13 +00:00
|
|
|
|
const [batch, setBatch] = useState(false);
|
2023-05-13 03:36:36 +00:00
|
|
|
|
const [inputs, setInputs] = useState(originInputs);
|
2023-07-22 10:56:36 +00:00
|
|
|
|
const [originModelOptions, setOriginModelOptions] = useState([]);
|
2023-06-07 15:26:00 +00:00
|
|
|
|
const [modelOptions, setModelOptions] = useState([]);
|
2023-06-11 03:08:16 +00:00
|
|
|
|
const [groupOptions, setGroupOptions] = useState([]);
|
2023-06-08 01:26:54 +00:00
|
|
|
|
const [basicModels, setBasicModels] = useState([]);
|
|
|
|
|
const [fullModels, setFullModels] = useState([]);
|
2023-07-15 05:51:46 +00:00
|
|
|
|
const [customModel, setCustomModel] = useState('');
|
2023-04-23 04:43:10 +00:00
|
|
|
|
const handleInputChange = (e, { name, value }) => {
|
|
|
|
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
2023-07-29 04:24:23 +00:00
|
|
|
|
if (name === 'type' && inputs.models.length === 0) {
|
|
|
|
|
let localModels = [];
|
|
|
|
|
switch (value) {
|
|
|
|
|
case 14:
|
2023-11-24 13:39:44 +00:00
|
|
|
|
localModels = ['claude-instant-1', 'claude-2', 'claude-2.0', 'claude-2.1'];
|
2023-07-29 04:24:23 +00:00
|
|
|
|
break;
|
|
|
|
|
case 11:
|
|
|
|
|
localModels = ['PaLM-2'];
|
|
|
|
|
break;
|
|
|
|
|
case 15:
|
2023-10-22 10:48:35 +00:00
|
|
|
|
localModels = ['ERNIE-Bot', 'ERNIE-Bot-turbo', 'ERNIE-Bot-4', 'Embedding-V1'];
|
2023-07-29 04:24:23 +00:00
|
|
|
|
break;
|
|
|
|
|
case 17:
|
2023-09-23 14:57:59 +00:00
|
|
|
|
localModels = ['qwen-turbo', 'qwen-plus', 'text-embedding-v1'];
|
2023-07-29 04:24:23 +00:00
|
|
|
|
break;
|
|
|
|
|
case 16:
|
2023-11-05 09:59:38 +00:00
|
|
|
|
localModels = ['chatglm_turbo', 'chatglm_pro', 'chatglm_std', 'chatglm_lite'];
|
2023-07-29 04:24:23 +00:00
|
|
|
|
break;
|
2023-07-29 14:05:15 +00:00
|
|
|
|
case 18:
|
|
|
|
|
localModels = ['SparkDesk'];
|
|
|
|
|
break;
|
2023-08-26 05:30:21 +00:00
|
|
|
|
case 19:
|
2023-10-03 04:52:45 +00:00
|
|
|
|
localModels = ['360GPT_S2_V9', 'embedding-bert-512-v1', 'embedding_s1_v1', 'semantic_similarity_s1_v1'];
|
2023-08-26 05:30:21 +00:00
|
|
|
|
break;
|
2023-10-03 06:19:03 +00:00
|
|
|
|
case 23:
|
|
|
|
|
localModels = ['hunyuan'];
|
|
|
|
|
break;
|
2023-12-17 04:48:32 +00:00
|
|
|
|
case 24:
|
|
|
|
|
localModels = ['gemini-pro'];
|
|
|
|
|
break;
|
2023-07-29 04:24:23 +00:00
|
|
|
|
}
|
|
|
|
|
setInputs((inputs) => ({ ...inputs, models: localModels }));
|
|
|
|
|
}
|
2023-04-23 04:43:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-04-23 07:42:23 +00:00
|
|
|
|
const loadChannel = async () => {
|
|
|
|
|
let res = await API.get(`/api/channel/${channelId}`);
|
2023-04-23 04:43:10 +00:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
if (success) {
|
2023-06-22 12:53:21 +00:00
|
|
|
|
if (data.models === '') {
|
|
|
|
|
data.models = [];
|
2023-06-07 15:26:00 +00:00
|
|
|
|
} else {
|
2023-06-22 12:53:21 +00:00
|
|
|
|
data.models = data.models.split(',');
|
2023-06-07 15:26:00 +00:00
|
|
|
|
}
|
2023-06-22 12:53:21 +00:00
|
|
|
|
if (data.group === '') {
|
|
|
|
|
data.groups = [];
|
2023-06-14 04:14:08 +00:00
|
|
|
|
} else {
|
2023-06-22 12:53:21 +00:00
|
|
|
|
data.groups = data.group.split(',');
|
2023-06-14 04:14:08 +00:00
|
|
|
|
}
|
2023-06-27 05:42:45 +00:00
|
|
|
|
if (data.model_mapping !== '') {
|
|
|
|
|
data.model_mapping = JSON.stringify(JSON.parse(data.model_mapping), null, 2);
|
|
|
|
|
}
|
2023-04-23 04:43:10 +00:00
|
|
|
|
setInputs(data);
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
setLoading(false);
|
|
|
|
|
};
|
2023-06-07 15:26:00 +00:00
|
|
|
|
|
|
|
|
|
const fetchModels = async () => {
|
|
|
|
|
try {
|
|
|
|
|
let res = await API.get(`/api/channel/models`);
|
2023-07-22 10:56:36 +00:00
|
|
|
|
let localModelOptions = res.data.data.map((model) => ({
|
2023-06-07 15:26:00 +00:00
|
|
|
|
key: model.id,
|
|
|
|
|
text: model.id,
|
2023-06-22 12:53:21 +00:00
|
|
|
|
value: model.id
|
2023-07-22 10:56:36 +00:00
|
|
|
|
}));
|
|
|
|
|
setOriginModelOptions(localModelOptions);
|
2023-06-08 01:26:54 +00:00
|
|
|
|
setFullModels(res.data.data.map((model) => model.id));
|
2023-07-22 10:56:36 +00:00
|
|
|
|
setBasicModels(res.data.data.filter((model) => {
|
|
|
|
|
return model.id.startsWith('gpt-3') || model.id.startsWith('text-');
|
|
|
|
|
}).map((model) => model.id));
|
2023-06-07 15:26:00 +00:00
|
|
|
|
} catch (error) {
|
2023-06-08 01:26:54 +00:00
|
|
|
|
showError(error.message);
|
2023-06-07 15:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-11 03:08:16 +00:00
|
|
|
|
const fetchGroups = async () => {
|
|
|
|
|
try {
|
2023-06-11 08:33:40 +00:00
|
|
|
|
let res = await API.get(`/api/group/`);
|
2023-06-11 03:08:16 +00:00
|
|
|
|
setGroupOptions(res.data.data.map((group) => ({
|
|
|
|
|
key: group,
|
|
|
|
|
text: group,
|
2023-06-22 12:53:21 +00:00
|
|
|
|
value: group
|
2023-06-11 03:08:16 +00:00
|
|
|
|
})));
|
|
|
|
|
} catch (error) {
|
|
|
|
|
showError(error.message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-22 10:56:36 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
let localModelOptions = [...originModelOptions];
|
|
|
|
|
inputs.models.forEach((model) => {
|
|
|
|
|
if (!localModelOptions.find((option) => option.key === model)) {
|
|
|
|
|
localModelOptions.push({
|
|
|
|
|
key: model,
|
|
|
|
|
text: model,
|
|
|
|
|
value: model
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
setModelOptions(localModelOptions);
|
|
|
|
|
}, [originModelOptions, inputs.models]);
|
|
|
|
|
|
2023-04-23 04:43:10 +00:00
|
|
|
|
useEffect(() => {
|
2023-05-13 03:36:36 +00:00
|
|
|
|
if (isEdit) {
|
|
|
|
|
loadChannel().then();
|
|
|
|
|
}
|
2023-06-07 15:26:00 +00:00
|
|
|
|
fetchModels().then();
|
2023-06-11 03:08:16 +00:00
|
|
|
|
fetchGroups().then();
|
2023-04-23 04:43:10 +00:00
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const submit = async () => {
|
2023-06-08 01:26:54 +00:00
|
|
|
|
if (!isEdit && (inputs.name === '' || inputs.key === '')) {
|
|
|
|
|
showInfo('请填写渠道名称和渠道密钥!');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-22 12:53:21 +00:00
|
|
|
|
if (inputs.models.length === 0) {
|
|
|
|
|
showInfo('请至少选择一个模型!');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-06-28 04:56:01 +00:00
|
|
|
|
if (inputs.model_mapping !== '' && !verifyJSON(inputs.model_mapping)) {
|
2023-06-27 05:42:45 +00:00
|
|
|
|
showInfo('模型映射必须是合法的 JSON 格式!');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-13 03:36:36 +00:00
|
|
|
|
let localInputs = inputs;
|
2023-09-18 14:49:05 +00:00
|
|
|
|
if (localInputs.base_url && localInputs.base_url.endsWith('/')) {
|
2023-05-13 03:36:36 +00:00
|
|
|
|
localInputs.base_url = localInputs.base_url.slice(0, localInputs.base_url.length - 1);
|
|
|
|
|
}
|
2023-05-19 14:13:29 +00:00
|
|
|
|
if (localInputs.type === 3 && localInputs.other === '') {
|
2023-07-29 11:16:42 +00:00
|
|
|
|
localInputs.other = '2023-06-01-preview';
|
|
|
|
|
}
|
2023-08-19 09:50:34 +00:00
|
|
|
|
if (localInputs.type === 18 && localInputs.other === '') {
|
|
|
|
|
localInputs.other = 'v2.1';
|
|
|
|
|
}
|
2023-05-13 03:36:36 +00:00
|
|
|
|
let res;
|
2023-06-22 12:53:21 +00:00
|
|
|
|
localInputs.models = localInputs.models.join(',');
|
|
|
|
|
localInputs.group = localInputs.groups.join(',');
|
2023-05-13 03:36:36 +00:00
|
|
|
|
if (isEdit) {
|
|
|
|
|
res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) });
|
|
|
|
|
} else {
|
|
|
|
|
res = await API.post(`/api/channel/`, localInputs);
|
2023-04-23 12:35:49 +00:00
|
|
|
|
}
|
2023-04-23 04:43:10 +00:00
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
if (success) {
|
2023-05-13 03:36:36 +00:00
|
|
|
|
if (isEdit) {
|
|
|
|
|
showSuccess('渠道更新成功!');
|
|
|
|
|
} else {
|
|
|
|
|
showSuccess('渠道创建成功!');
|
|
|
|
|
setInputs(originInputs);
|
|
|
|
|
}
|
2023-04-23 04:43:10 +00:00
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-03 13:40:58 +00:00
|
|
|
|
const addCustomModel = () => {
|
|
|
|
|
if (customModel.trim() === '') return;
|
|
|
|
|
if (inputs.models.includes(customModel)) return;
|
|
|
|
|
let localModels = [...inputs.models];
|
|
|
|
|
localModels.push(customModel);
|
|
|
|
|
let localModelOptions = [];
|
|
|
|
|
localModelOptions.push({
|
|
|
|
|
key: customModel,
|
|
|
|
|
text: customModel,
|
|
|
|
|
value: customModel
|
|
|
|
|
});
|
|
|
|
|
setModelOptions(modelOptions => {
|
|
|
|
|
return [...modelOptions, ...localModelOptions];
|
|
|
|
|
});
|
|
|
|
|
setCustomModel('');
|
|
|
|
|
handleInputChange(null, { name: 'models', value: localModels });
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-23 04:43:10 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Segment loading={loading}>
|
2023-05-13 03:36:36 +00:00
|
|
|
|
<Header as='h3'>{isEdit ? '更新渠道信息' : '创建新的渠道'}</Header>
|
2023-05-12 03:44:38 +00:00
|
|
|
|
<Form autoComplete='new-password'>
|
2023-04-23 04:43:10 +00:00
|
|
|
|
<Form.Field>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
<Form.Select
|
|
|
|
|
label='类型'
|
|
|
|
|
name='type'
|
2023-07-04 10:40:36 +00:00
|
|
|
|
required
|
2023-04-23 07:42:23 +00:00
|
|
|
|
options={CHANNEL_OPTIONS}
|
|
|
|
|
value={inputs.type}
|
2023-04-23 04:43:10 +00:00
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
2023-05-13 03:36:36 +00:00
|
|
|
|
{
|
|
|
|
|
inputs.type === 3 && (
|
|
|
|
|
<>
|
|
|
|
|
<Message>
|
2023-06-01 10:15:53 +00:00
|
|
|
|
注意,<strong>模型部署名称必须和模型名称保持一致</strong>,因为 One API 会把请求体中的 model
|
|
|
|
|
参数替换为你的部署名称(模型名称中的点会被剔除),<a target='_blank'
|
|
|
|
|
href='https://github.com/songquanpeng/one-api/issues/133?notification_referrer_id=NT_kwDOAmJSYrM2NjIwMzI3NDgyOjM5OTk4MDUw#issuecomment-1571602271'>图片演示</a>。
|
2023-05-13 03:36:36 +00:00
|
|
|
|
</Message>
|
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='AZURE_OPENAI_ENDPOINT'
|
|
|
|
|
name='base_url'
|
|
|
|
|
placeholder={'请输入 AZURE_OPENAI_ENDPOINT,例如:https://docs-test-001.openai.azure.com'}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.base_url}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
2023-05-13 04:53:57 +00:00
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='默认 API 版本'
|
|
|
|
|
name='other'
|
2023-07-29 11:16:42 +00:00
|
|
|
|
placeholder={'请输入默认 API 版本,例如:2023-06-01-preview,该配置可以被实际的请求查询参数所覆盖'}
|
2023-05-13 04:53:57 +00:00
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.other}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
2023-05-13 03:36:36 +00:00
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-04-23 12:35:49 +00:00
|
|
|
|
{
|
|
|
|
|
inputs.type === 8 && (
|
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='Base URL'
|
|
|
|
|
name='base_url'
|
2023-05-13 03:36:36 +00:00
|
|
|
|
placeholder={'请输入自定义渠道的 Base URL,例如:https://openai.justsong.cn'}
|
2023-04-23 12:35:49 +00:00
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.base_url}
|
2023-05-12 03:44:38 +00:00
|
|
|
|
autoComplete='new-password'
|
2023-04-23 12:35:49 +00:00
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-04-23 04:43:10 +00:00
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
2023-04-23 07:42:23 +00:00
|
|
|
|
label='名称'
|
2023-07-04 10:40:36 +00:00
|
|
|
|
required
|
2023-04-23 07:42:23 +00:00
|
|
|
|
name='name'
|
2023-07-23 04:46:41 +00:00
|
|
|
|
placeholder={'请为渠道命名'}
|
2023-04-23 04:43:10 +00:00
|
|
|
|
onChange={handleInputChange}
|
2023-04-23 07:42:23 +00:00
|
|
|
|
value={inputs.name}
|
2023-05-12 03:44:38 +00:00
|
|
|
|
autoComplete='new-password'
|
2023-04-23 04:43:10 +00:00
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
2023-06-08 01:26:54 +00:00
|
|
|
|
<Form.Field>
|
2023-06-11 03:08:16 +00:00
|
|
|
|
<Form.Dropdown
|
2023-06-08 01:26:54 +00:00
|
|
|
|
label='分组'
|
2023-07-23 04:46:41 +00:00
|
|
|
|
placeholder={'请选择可以使用该渠道的分组'}
|
2023-06-14 04:14:08 +00:00
|
|
|
|
name='groups'
|
2023-07-04 10:40:36 +00:00
|
|
|
|
required
|
2023-06-11 03:08:16 +00:00
|
|
|
|
fluid
|
2023-06-14 04:14:08 +00:00
|
|
|
|
multiple
|
2023-06-11 03:08:16 +00:00
|
|
|
|
selection
|
|
|
|
|
allowAdditions
|
|
|
|
|
additionLabel={'请在系统设置页面编辑分组倍率以添加新的分组:'}
|
2023-06-08 01:26:54 +00:00
|
|
|
|
onChange={handleInputChange}
|
2023-06-14 04:14:08 +00:00
|
|
|
|
value={inputs.groups}
|
2023-06-08 01:26:54 +00:00
|
|
|
|
autoComplete='new-password'
|
2023-06-11 03:08:16 +00:00
|
|
|
|
options={groupOptions}
|
2023-06-08 01:26:54 +00:00
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
2023-08-19 09:50:34 +00:00
|
|
|
|
{
|
|
|
|
|
inputs.type === 18 && (
|
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='模型版本'
|
|
|
|
|
name='other'
|
|
|
|
|
placeholder={'请输入星火大模型版本,注意是接口地址中的版本号,例如:v2.1'}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.other}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-09-03 04:51:59 +00:00
|
|
|
|
{
|
|
|
|
|
inputs.type === 21 && (
|
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='知识库 ID'
|
|
|
|
|
name='other'
|
|
|
|
|
placeholder={'请输入知识库 ID,例如:123456'}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.other}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-12-10 09:22:52 +00:00
|
|
|
|
{
|
|
|
|
|
inputs.type === 17 && (
|
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='插件参数'
|
|
|
|
|
name='other'
|
|
|
|
|
placeholder={'请输入插件参数,即 X-DashScope-Plugin 请求头的取值'}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.other}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-06-07 15:26:00 +00:00
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Dropdown
|
2023-06-08 01:26:54 +00:00
|
|
|
|
label='模型'
|
2023-07-23 04:46:41 +00:00
|
|
|
|
placeholder={'请选择该渠道所支持的模型'}
|
2023-06-07 15:26:00 +00:00
|
|
|
|
name='models'
|
2023-07-04 10:40:36 +00:00
|
|
|
|
required
|
2023-06-07 15:26:00 +00:00
|
|
|
|
fluid
|
|
|
|
|
multiple
|
|
|
|
|
selection
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.models}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
options={modelOptions}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
2023-06-22 12:53:21 +00:00
|
|
|
|
<div style={{ lineHeight: '40px', marginBottom: '12px' }}>
|
2023-06-08 01:26:54 +00:00
|
|
|
|
<Button type={'button'} onClick={() => {
|
|
|
|
|
handleInputChange(null, { name: 'models', value: basicModels });
|
|
|
|
|
}}>填入基础模型</Button>
|
|
|
|
|
<Button type={'button'} onClick={() => {
|
|
|
|
|
handleInputChange(null, { name: 'models', value: fullModels });
|
|
|
|
|
}}>填入所有模型</Button>
|
2023-06-22 12:53:21 +00:00
|
|
|
|
<Button type={'button'} onClick={() => {
|
|
|
|
|
handleInputChange(null, { name: 'models', value: [] });
|
|
|
|
|
}}>清除所有模型</Button>
|
2023-07-15 05:51:46 +00:00
|
|
|
|
<Input
|
|
|
|
|
action={
|
2023-09-03 13:40:58 +00:00
|
|
|
|
<Button type={'button'} onClick={addCustomModel}>填入</Button>
|
2023-07-15 05:51:46 +00:00
|
|
|
|
}
|
|
|
|
|
placeholder='输入自定义模型名称'
|
|
|
|
|
value={customModel}
|
|
|
|
|
onChange={(e, { value }) => {
|
|
|
|
|
setCustomModel(value);
|
|
|
|
|
}}
|
2023-09-03 13:40:58 +00:00
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key === 'Enter') {
|
|
|
|
|
addCustomModel();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
2023-07-15 05:51:46 +00:00
|
|
|
|
/>
|
2023-06-08 01:26:54 +00:00
|
|
|
|
</div>
|
2023-06-27 05:42:45 +00:00
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.TextArea
|
2023-07-29 11:16:42 +00:00
|
|
|
|
label='模型重定向'
|
2023-07-23 04:46:41 +00:00
|
|
|
|
placeholder={`此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称,例如:\n${JSON.stringify(MODEL_MAPPING_EXAMPLE, null, 2)}`}
|
2023-06-27 05:42:45 +00:00
|
|
|
|
name='model_mapping'
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.model_mapping}
|
2023-06-28 04:56:01 +00:00
|
|
|
|
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
|
2023-06-27 05:42:45 +00:00
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
2023-05-13 09:08:13 +00:00
|
|
|
|
{
|
|
|
|
|
batch ? <Form.Field>
|
|
|
|
|
<Form.TextArea
|
|
|
|
|
label='密钥'
|
|
|
|
|
name='key'
|
2023-07-04 10:40:36 +00:00
|
|
|
|
required
|
2023-05-13 09:08:13 +00:00
|
|
|
|
placeholder={'请输入密钥,一行一个'}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.key}
|
|
|
|
|
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field> : <Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='密钥'
|
|
|
|
|
name='key'
|
2023-07-04 10:40:36 +00:00
|
|
|
|
required
|
2023-09-03 07:50:49 +00:00
|
|
|
|
placeholder={type2secretPrompt(inputs.type)}
|
2023-05-13 09:08:13 +00:00
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.key}
|
|
|
|
|
autoComplete='new-password'
|
2023-06-01 10:15:53 +00:00
|
|
|
|
/>
|
2023-05-13 09:08:13 +00:00
|
|
|
|
</Form.Field>
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
!isEdit && (
|
|
|
|
|
<Form.Checkbox
|
|
|
|
|
checked={batch}
|
|
|
|
|
label='批量创建'
|
|
|
|
|
name='batch'
|
|
|
|
|
onChange={() => setBatch(!batch)}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-07-23 04:20:42 +00:00
|
|
|
|
{
|
2023-09-03 07:50:49 +00:00
|
|
|
|
inputs.type !== 3 && inputs.type !== 8 && inputs.type !== 22 && (
|
2023-07-23 04:20:42 +00:00
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
2023-08-06 14:07:31 +00:00
|
|
|
|
label='代理'
|
2023-07-23 04:20:42 +00:00
|
|
|
|
name='base_url'
|
2023-08-06 14:07:31 +00:00
|
|
|
|
placeholder={'此项可选,用于通过代理站来进行 API 调用,请输入代理站地址,格式为:https://domain.com'}
|
2023-07-23 04:20:42 +00:00
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.base_url}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-09-03 07:50:49 +00:00
|
|
|
|
{
|
|
|
|
|
inputs.type === 22 && (
|
|
|
|
|
<Form.Field>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='私有部署地址'
|
|
|
|
|
name='base_url'
|
|
|
|
|
placeholder={'请输入私有部署地址,格式为:https://fastgpt.run/api/openapi'}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
value={inputs.base_url}
|
|
|
|
|
autoComplete='new-password'
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-08-12 02:49:30 +00:00
|
|
|
|
<Button onClick={handleCancel}>取消</Button>
|
2023-07-29 04:24:23 +00:00
|
|
|
|
<Button type={isEdit ? 'button' : 'submit'} positive onClick={submit}>提交</Button>
|
2023-04-23 04:43:10 +00:00
|
|
|
|
</Form>
|
|
|
|
|
</Segment>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default EditChannel;
|