2024-03-23 21:24:39 +08:00
|
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
|
|
|
|
|
import { useNavigate, useParams } from 'react-router-dom';
|
2024-12-13 19:03:14 +08:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-03-23 21:24:39 +08:00
|
|
|
|
import {
|
|
|
|
|
|
API,
|
|
|
|
|
|
isMobile,
|
|
|
|
|
|
showError,
|
|
|
|
|
|
showInfo,
|
|
|
|
|
|
showSuccess,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
verifyJSON
|
2024-03-23 21:24:39 +08:00
|
|
|
|
} from '../../helpers';
|
|
|
|
|
|
import { CHANNEL_OPTIONS } from '../../constants';
|
|
|
|
|
|
import Title from '@douyinfe/semi-ui/lib/es/typography/title';
|
|
|
|
|
|
import {
|
|
|
|
|
|
SideSheet,
|
|
|
|
|
|
Space,
|
|
|
|
|
|
Spin,
|
|
|
|
|
|
Button,
|
2024-05-21 22:16:20 +08:00
|
|
|
|
Tooltip,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
Input,
|
|
|
|
|
|
Typography,
|
|
|
|
|
|
Select,
|
|
|
|
|
|
TextArea,
|
|
|
|
|
|
Checkbox,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
Banner
|
2024-03-23 21:24:39 +08:00
|
|
|
|
} from '@douyinfe/semi-ui';
|
2024-04-23 11:44:40 +08:00
|
|
|
|
import { Divider } from 'semantic-ui-react';
|
2024-05-12 19:07:33 +08:00
|
|
|
|
import { getChannelModels, loadChannelModels } from '../../components/utils.js';
|
2024-05-21 17:57:19 +08:00
|
|
|
|
import axios from 'axios';
|
2023-04-23 12:43:10 +08:00
|
|
|
|
|
2023-06-28 12:56:01 +08:00
|
|
|
|
const MODEL_MAPPING_EXAMPLE = {
|
2024-11-29 23:58:31 +08:00
|
|
|
|
'gpt-3.5-turbo': 'gpt-3.5-turbo-0125'
|
2023-06-28 12:56:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-04-20 21:05:23 +08:00
|
|
|
|
const STATUS_CODE_MAPPING_EXAMPLE = {
|
2024-11-19 01:13:18 +08:00
|
|
|
|
400: '500'
|
2024-04-20 21:05:23 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-28 18:43:40 +08:00
|
|
|
|
const REGION_EXAMPLE = {
|
2024-11-19 01:13:18 +08:00
|
|
|
|
'default': 'us-central1',
|
|
|
|
|
|
'claude-3-5-sonnet-20240620': 'europe-west1'
|
|
|
|
|
|
};
|
2024-08-28 18:43:40 +08:00
|
|
|
|
|
2024-11-19 01:13:18 +08:00
|
|
|
|
const fetchButtonTips = '1. 新建渠道时,请求通过当前浏览器发出;2. 编辑已有渠道,请求通过后端服务器发出';
|
2024-05-23 19:49:28 +08:00
|
|
|
|
|
2023-09-03 15:50:49 +08:00
|
|
|
|
function type2secretPrompt(type) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
// inputs.type === 15 ? '按照如下格式输入:APIKey|SecretKey' : (inputs.type === 18 ? '按照如下格式输入:APPID|APISecret|APIKey' : '请输入渠道对应的鉴权密钥')
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case 15:
|
|
|
|
|
|
return '按照如下格式输入:APIKey|SecretKey';
|
|
|
|
|
|
case 18:
|
|
|
|
|
|
return '按照如下格式输入:APPID|APISecret|APIKey';
|
|
|
|
|
|
case 22:
|
|
|
|
|
|
return '按照如下格式输入:APIKey-AppId,例如:fastgpt-0sp2gtvfdgyi4k30jwlgwf1i-64f335d84283f05518e9e041';
|
|
|
|
|
|
case 23:
|
|
|
|
|
|
return '按照如下格式输入:AppId|SecretId|SecretKey';
|
2024-04-23 11:44:40 +08:00
|
|
|
|
case 33:
|
|
|
|
|
|
return '按照如下格式输入:Ak|Sk|Region';
|
2024-03-23 21:24:39 +08:00
|
|
|
|
default:
|
|
|
|
|
|
return '请输入渠道对应的鉴权密钥';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const EditChannel = (props) => {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
const { t } = useTranslation();
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
const channelId = props.editingChannel.id;
|
|
|
|
|
|
const isEdit = channelId !== undefined;
|
|
|
|
|
|
const [loading, setLoading] = useState(isEdit);
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
|
|
|
props.handleClose();
|
|
|
|
|
|
};
|
|
|
|
|
|
const originInputs = {
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
type: 1,
|
|
|
|
|
|
key: '',
|
|
|
|
|
|
openai_organization: '',
|
2024-04-23 11:44:40 +08:00
|
|
|
|
max_input_tokens: 0,
|
2024-03-23 21:24:39 +08:00
|
|
|
|
base_url: '',
|
|
|
|
|
|
other: '',
|
|
|
|
|
|
model_mapping: '',
|
2024-04-20 21:05:23 +08:00
|
|
|
|
status_code_mapping: '',
|
2024-03-23 21:24:39 +08:00
|
|
|
|
models: [],
|
|
|
|
|
|
auto_ban: 1,
|
2024-04-04 17:28:56 +08:00
|
|
|
|
test_model: '',
|
2024-03-23 21:24:39 +08:00
|
|
|
|
groups: ['default'],
|
2024-11-19 01:13:18 +08:00
|
|
|
|
priority: 0,
|
|
|
|
|
|
weight: 0,
|
|
|
|
|
|
tag: ''
|
2024-03-23 21:24:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
const [batch, setBatch] = useState(false);
|
|
|
|
|
|
const [autoBan, setAutoBan] = useState(true);
|
|
|
|
|
|
// const [autoBan, setAutoBan] = useState(true);
|
|
|
|
|
|
const [inputs, setInputs] = useState(originInputs);
|
|
|
|
|
|
const [originModelOptions, setOriginModelOptions] = useState([]);
|
|
|
|
|
|
const [modelOptions, setModelOptions] = useState([]);
|
|
|
|
|
|
const [groupOptions, setGroupOptions] = useState([]);
|
|
|
|
|
|
const [basicModels, setBasicModels] = useState([]);
|
|
|
|
|
|
const [fullModels, setFullModels] = useState([]);
|
|
|
|
|
|
const [customModel, setCustomModel] = useState('');
|
|
|
|
|
|
const handleInputChange = (name, value) => {
|
|
|
|
|
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
2024-05-12 19:07:33 +08:00
|
|
|
|
if (name === 'type') {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
let localModels = [];
|
|
|
|
|
|
switch (value) {
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
localModels = [
|
|
|
|
|
|
'mj_imagine',
|
|
|
|
|
|
'mj_variation',
|
|
|
|
|
|
'mj_reroll',
|
|
|
|
|
|
'mj_blend',
|
|
|
|
|
|
'mj_upscale',
|
|
|
|
|
|
'mj_describe',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
'mj_uploads'
|
2024-03-23 21:24:39 +08:00
|
|
|
|
];
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
localModels = [
|
|
|
|
|
|
'swap_face',
|
|
|
|
|
|
'mj_imagine',
|
|
|
|
|
|
'mj_variation',
|
|
|
|
|
|
'mj_reroll',
|
|
|
|
|
|
'mj_blend',
|
|
|
|
|
|
'mj_upscale',
|
|
|
|
|
|
'mj_describe',
|
|
|
|
|
|
'mj_zoom',
|
|
|
|
|
|
'mj_shorten',
|
|
|
|
|
|
'mj_modal',
|
|
|
|
|
|
'mj_inpaint',
|
|
|
|
|
|
'mj_custom_zoom',
|
|
|
|
|
|
'mj_high_variation',
|
|
|
|
|
|
'mj_low_variation',
|
|
|
|
|
|
'mj_pan',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
'mj_uploads'
|
2024-03-23 21:24:39 +08:00
|
|
|
|
];
|
|
|
|
|
|
break;
|
2024-06-12 20:37:42 +08:00
|
|
|
|
case 36:
|
|
|
|
|
|
localModels = [
|
|
|
|
|
|
'suno_music',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
'suno_lyrics'
|
2024-06-12 20:37:42 +08:00
|
|
|
|
];
|
|
|
|
|
|
break;
|
2024-05-12 19:07:33 +08:00
|
|
|
|
default:
|
|
|
|
|
|
localModels = getChannelModels(value);
|
|
|
|
|
|
break;
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}
|
2024-05-12 19:07:33 +08:00
|
|
|
|
if (inputs.models.length === 0) {
|
|
|
|
|
|
setInputs((inputs) => ({ ...inputs, models: localModels }));
|
|
|
|
|
|
}
|
|
|
|
|
|
setBasicModels(localModels);
|
2023-07-29 12:24:23 +08:00
|
|
|
|
}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
//setAutoBan
|
|
|
|
|
|
};
|
2023-04-23 12:43:10 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const loadChannel = async () => {
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
let res = await API.get(`/api/channel/${channelId}`);
|
2024-03-25 14:10:57 +08:00
|
|
|
|
if (res === undefined) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
if (data.models === '') {
|
|
|
|
|
|
data.models = [];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
data.models = data.models.split(',');
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data.group === '') {
|
|
|
|
|
|
data.groups = [];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
data.groups = data.group.split(',');
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data.model_mapping !== '') {
|
|
|
|
|
|
data.model_mapping = JSON.stringify(
|
|
|
|
|
|
JSON.parse(data.model_mapping),
|
|
|
|
|
|
null,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
2
|
2024-03-23 21:24:39 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
setInputs(data);
|
|
|
|
|
|
if (data.auto_ban === 0) {
|
|
|
|
|
|
setAutoBan(false);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setAutoBan(true);
|
|
|
|
|
|
}
|
2024-05-12 19:07:33 +08:00
|
|
|
|
setBasicModels(getChannelModels(data.type));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
// console.log(data);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
};
|
2023-06-11 11:08:16 +08:00
|
|
|
|
|
2024-05-23 19:49:28 +08:00
|
|
|
|
|
|
|
|
|
|
const fetchUpstreamModelList = async (name) => {
|
2024-12-24 18:02:08 +08:00
|
|
|
|
// if (inputs['type'] !== 1) {
|
|
|
|
|
|
// showError(t('仅支持 OpenAI 接口格式'));
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
2024-11-19 01:13:18 +08:00
|
|
|
|
setLoading(true);
|
|
|
|
|
|
const models = inputs['models'] || [];
|
2024-05-23 19:49:28 +08:00
|
|
|
|
let err = false;
|
2024-12-24 18:02:08 +08:00
|
|
|
|
|
2024-05-23 19:49:28 +08:00
|
|
|
|
if (isEdit) {
|
2024-12-24 18:02:08 +08:00
|
|
|
|
// 如果是编辑模式,使用已有的channel id获取模型列表
|
2024-11-19 01:13:18 +08:00
|
|
|
|
const res = await API.get('/api/channel/fetch_models/' + channelId);
|
2024-05-23 19:49:28 +08:00
|
|
|
|
if (res.data && res.data?.success) {
|
2024-11-19 01:13:18 +08:00
|
|
|
|
models.push(...res.data.data);
|
2024-05-23 19:49:28 +08:00
|
|
|
|
} else {
|
2024-11-19 01:13:18 +08:00
|
|
|
|
err = true;
|
2024-05-23 19:49:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2024-12-24 18:02:08 +08:00
|
|
|
|
// 如果是新建模式,通过后端代理获取模型列表
|
2024-11-19 01:13:18 +08:00
|
|
|
|
if (!inputs?.['key']) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showError(t('请填写密钥'));
|
2024-11-19 01:13:18 +08:00
|
|
|
|
err = true;
|
2024-05-23 19:49:28 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
try {
|
2024-12-24 18:02:08 +08:00
|
|
|
|
const res = await API.post('/api/channel/fetch_models', {
|
|
|
|
|
|
base_url: inputs['base_url'],
|
2025-01-07 12:40:36 +08:00
|
|
|
|
type: inputs['type'],
|
2024-12-24 18:02:08 +08:00
|
|
|
|
key: inputs['key']
|
2024-11-19 01:13:18 +08:00
|
|
|
|
});
|
2024-12-24 18:02:08 +08:00
|
|
|
|
|
|
|
|
|
|
if (res.data && res.data.success) {
|
|
|
|
|
|
models.push(...res.data.data);
|
2024-05-23 19:49:28 +08:00
|
|
|
|
} else {
|
2024-11-19 01:13:18 +08:00
|
|
|
|
err = true;
|
2024-05-23 19:49:28 +08:00
|
|
|
|
}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
} catch (error) {
|
2024-12-24 18:02:08 +08:00
|
|
|
|
console.error('Error fetching models:', error);
|
2024-11-19 01:13:18 +08:00
|
|
|
|
err = true;
|
2024-05-23 19:49:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-24 18:02:08 +08:00
|
|
|
|
|
2024-05-23 19:49:28 +08:00
|
|
|
|
if (!err) {
|
|
|
|
|
|
handleInputChange(name, Array.from(new Set(models)));
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showSuccess(t('获取模型列表成功'));
|
2024-05-23 19:49:28 +08:00
|
|
|
|
} else {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showError(t('获取模型列表失败'));
|
2024-05-23 19:49:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
setLoading(false);
|
2024-11-19 01:13:18 +08:00
|
|
|
|
};
|
2024-05-23 19:49:28 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const fetchModels = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let res = await API.get(`/api/channel/models`);
|
|
|
|
|
|
let localModelOptions = res.data.data.map((model) => ({
|
|
|
|
|
|
label: model.id,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
value: model.id
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}));
|
|
|
|
|
|
setOriginModelOptions(localModelOptions);
|
|
|
|
|
|
setFullModels(res.data.data.map((model) => model.id));
|
|
|
|
|
|
setBasicModels(
|
|
|
|
|
|
res.data.data
|
|
|
|
|
|
.filter((model) => {
|
2024-11-29 23:58:31 +08:00
|
|
|
|
return model.id.startsWith('gpt-') || model.id.startsWith('text-');
|
2024-03-23 21:24:39 +08:00
|
|
|
|
})
|
2024-11-19 01:13:18 +08:00
|
|
|
|
.map((model) => model.id)
|
2024-03-23 21:24:39 +08:00
|
|
|
|
);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
showError(error.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-12-05 18:15:40 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const fetchGroups = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let res = await API.get(`/api/group/`);
|
2024-03-25 14:10:57 +08:00
|
|
|
|
if (res === undefined) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
setGroupOptions(
|
|
|
|
|
|
res.data.data.map((group) => ({
|
|
|
|
|
|
label: group,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
value: group
|
|
|
|
|
|
}))
|
2024-03-23 21:24:39 +08:00
|
|
|
|
);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
showError(error.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-12-05 18:15:40 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
let localModelOptions = [...originModelOptions];
|
|
|
|
|
|
inputs.models.forEach((model) => {
|
2024-11-29 23:58:31 +08:00
|
|
|
|
if (!localModelOptions.find((option) => option.label === model)) {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
localModelOptions.push({
|
|
|
|
|
|
label: model,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
value: model
|
2023-07-22 18:56:36 +08:00
|
|
|
|
});
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
setModelOptions(localModelOptions);
|
|
|
|
|
|
}, [originModelOptions, inputs.models]);
|
2023-07-22 18:56:36 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
fetchModels().then();
|
|
|
|
|
|
fetchGroups().then();
|
|
|
|
|
|
if (isEdit) {
|
2024-11-29 23:58:31 +08:00
|
|
|
|
loadChannel().then(() => {});
|
2024-03-23 21:24:39 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
setInputs(originInputs);
|
2024-05-12 19:07:33 +08:00
|
|
|
|
let localModels = getChannelModels(inputs.type);
|
|
|
|
|
|
setBasicModels(localModels);
|
|
|
|
|
|
setInputs((inputs) => ({ ...inputs, models: localModels }));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}, [props.editingChannel.id]);
|
2023-04-23 12:43:10 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
const submit = async () => {
|
|
|
|
|
|
if (!isEdit && (inputs.name === '' || inputs.key === '')) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showInfo(t('请填写渠道名称和渠道密钥!'));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (inputs.models.length === 0) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showInfo(t('请至少选择一个模型!'));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (inputs.model_mapping !== '' && !verifyJSON(inputs.model_mapping)) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showInfo(t('模型映射必须是合法的 JSON 格式!'));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let localInputs = { ...inputs };
|
|
|
|
|
|
if (localInputs.base_url && localInputs.base_url.endsWith('/')) {
|
|
|
|
|
|
localInputs.base_url = localInputs.base_url.slice(
|
|
|
|
|
|
0,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
localInputs.base_url.length - 1
|
2024-03-23 21:24:39 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (localInputs.type === 3 && localInputs.other === '') {
|
|
|
|
|
|
localInputs.other = '2023-06-01-preview';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (localInputs.type === 18 && localInputs.other === '') {
|
|
|
|
|
|
localInputs.other = 'v2.1';
|
|
|
|
|
|
}
|
|
|
|
|
|
let res;
|
|
|
|
|
|
if (!Array.isArray(localInputs.models)) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showError(t('提交失败,请勿重复提交!'));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
handleCancel();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
localInputs.auto_ban = autoBan ? 1 : 0;
|
|
|
|
|
|
localInputs.models = localInputs.models.join(',');
|
|
|
|
|
|
localInputs.group = localInputs.groups.join(',');
|
|
|
|
|
|
if (isEdit) {
|
|
|
|
|
|
res = await API.put(`/api/channel/`, {
|
|
|
|
|
|
...localInputs,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
id: parseInt(channelId)
|
2024-03-23 21:24:39 +08:00
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
res = await API.post(`/api/channel/`, localInputs);
|
|
|
|
|
|
}
|
|
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
if (isEdit) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showSuccess(t('渠道更新成功!'));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
} else {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showSuccess(t('渠道创建成功!'));
|
2024-03-23 21:24:39 +08:00
|
|
|
|
setInputs(originInputs);
|
|
|
|
|
|
}
|
|
|
|
|
|
props.refresh();
|
|
|
|
|
|
props.handleClose();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showError(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-09-25 18:44:10 +08:00
|
|
|
|
|
2024-05-05 02:06:40 +08:00
|
|
|
|
const addCustomModels = () => {
|
2024-03-23 21:24:39 +08:00
|
|
|
|
if (customModel.trim() === '') return;
|
2024-05-18 16:06:12 +08:00
|
|
|
|
const modelArray = customModel.split(',').map((model) => model.trim());
|
2024-05-21 17:57:19 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
let localModels = [...inputs.models];
|
2024-05-05 02:06:40 +08:00
|
|
|
|
let localModelOptions = [...modelOptions];
|
|
|
|
|
|
let hasError = false;
|
|
|
|
|
|
|
2024-05-18 16:06:12 +08:00
|
|
|
|
modelArray.forEach((model) => {
|
2024-05-05 02:06:40 +08:00
|
|
|
|
if (model && !localModels.includes(model)) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
localModels.push(model);
|
2024-05-18 16:06:12 +08:00
|
|
|
|
localModelOptions.push({
|
2024-05-05 02:06:40 +08:00
|
|
|
|
key: model,
|
|
|
|
|
|
text: model,
|
2024-11-19 01:13:18 +08:00
|
|
|
|
value: model
|
2024-05-05 02:06:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
} else if (model) {
|
2024-12-13 19:03:14 +08:00
|
|
|
|
showError(t('某些模型已存在!'));
|
2024-05-05 02:06:40 +08:00
|
|
|
|
hasError = true;
|
|
|
|
|
|
}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
});
|
2024-05-05 02:06:40 +08:00
|
|
|
|
|
2024-12-13 19:03:14 +08:00
|
|
|
|
if (hasError) return;
|
2024-05-05 02:06:40 +08:00
|
|
|
|
|
|
|
|
|
|
setModelOptions(localModelOptions);
|
2024-03-23 21:24:39 +08:00
|
|
|
|
setCustomModel('');
|
|
|
|
|
|
handleInputChange('models', localModels);
|
|
|
|
|
|
};
|
2023-04-23 12:43:10 +08:00
|
|
|
|
|
2024-05-05 02:06:40 +08:00
|
|
|
|
|
2024-03-23 21:24:39 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<SideSheet
|
|
|
|
|
|
maskClosable={false}
|
|
|
|
|
|
placement={isEdit ? 'right' : 'left'}
|
|
|
|
|
|
title={
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Title level={3}>{isEdit ? t('更新渠道信息') : t('创建新的渠道')}</Title>
|
2023-12-05 18:15:40 +08:00
|
|
|
|
}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
headerStyle={{ borderBottom: '1px solid var(--semi-color-border)' }}
|
|
|
|
|
|
bodyStyle={{ borderBottom: '1px solid var(--semi-color-border)' }}
|
|
|
|
|
|
visible={props.visible}
|
|
|
|
|
|
footer={
|
|
|
|
|
|
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
|
|
|
|
<Space>
|
2024-11-19 01:13:18 +08:00
|
|
|
|
<Button theme="solid" size={'large'} onClick={submit}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('提交')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
2024-11-19 01:13:18 +08:00
|
|
|
|
theme="solid"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
size={'large'}
|
|
|
|
|
|
type={'tertiary'}
|
|
|
|
|
|
onClick={handleCancel}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('取消')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</div>
|
2023-12-05 18:15:40 +08:00
|
|
|
|
}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
closeIcon={null}
|
|
|
|
|
|
onCancel={() => handleCancel()}
|
|
|
|
|
|
width={isMobile() ? '100%' : 600}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Spin spinning={loading}>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('类型')}:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Select
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="type"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
required
|
|
|
|
|
|
optionList={CHANNEL_OPTIONS}
|
|
|
|
|
|
value={inputs.type}
|
|
|
|
|
|
onChange={(value) => handleInputChange('type', value)}
|
|
|
|
|
|
style={{ width: '50%' }}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{inputs.type === 3 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Banner
|
|
|
|
|
|
type={'warning'}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
description={t('注意,模型部署名称必须和模型名称保持一致,因为 One API 会把请求体中的 model 参数替换为你的部署名称(模型名称中的点会被剔除)')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
></Banner>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>
|
|
|
|
|
|
AZURE_OPENAI_ENDPOINT:
|
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-11-19 01:13:18 +08:00
|
|
|
|
label="AZURE_OPENAI_ENDPOINT"
|
|
|
|
|
|
name="azure_base_url"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入 AZURE_OPENAI_ENDPOINT,例如:https://docs-test-001.openai.azure.com')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('base_url', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.base_url}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('默认 API 版本')}:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('默认 API 版本')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="azure_other"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入默认 API 版本,例如:2023-06-01-preview,该配置可以被实际的请求查询参数所覆盖')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('other', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.other}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{inputs.type === 8 && (
|
|
|
|
|
|
<>
|
2024-05-24 16:25:11 +08:00
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Banner
|
|
|
|
|
|
type={'warning'}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
description={t('如果你对接的是上游One API或者New API等转发项目,请使用OpenAI类型,不要使用此类型,除非你知道你在做什么。')}
|
2024-05-24 16:25:11 +08:00
|
|
|
|
></Banner>
|
|
|
|
|
|
</div>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-05-18 16:06:12 +08:00
|
|
|
|
<Typography.Text strong>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('完整的 Base URL,支持变量{model}')}:
|
2024-05-18 16:06:12 +08:00
|
|
|
|
</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="base_url"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入完整的URL,例如:https://api.openai.com/v1/chat/completions')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('base_url', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.base_url}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{inputs.type !== 3 && inputs.type !== 8 && inputs.type !== 22 && inputs.type !== 36 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('代理')}:</Typography.Text>
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('代理')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="base_url"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('此项可选,用于通过代理站来进行 API 调用')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('base_url', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.base_url}
|
|
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{inputs.type === 22 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('私有部署地址')}:</Typography.Text>
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
name="base_url"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入私有部署地址,格式为:https://fastgpt.run/api/openapi')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('base_url', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.base_url}
|
|
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-06-12 20:37:42 +08:00
|
|
|
|
{inputs.type === 36 && (
|
2024-11-19 01:13:18 +08:00
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('注意非Chat API,请务必填写正确的API地址,否则可能导致无法使用')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
name="base_url"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入到 /suno 前的路径,通常就是域名,例如:https://api.example.com')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('base_url', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.base_url}
|
|
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</>
|
2024-06-12 20:37:42 +08:00
|
|
|
|
)}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('名称')}:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-11-19 01:13:18 +08:00
|
|
|
|
required
|
|
|
|
|
|
name="name"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请为渠道命名')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('name', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.name}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('分组')}:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Select
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请选择可以使用该渠道的分组')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="groups"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
required
|
|
|
|
|
|
multiple
|
|
|
|
|
|
selection
|
|
|
|
|
|
allowAdditions
|
2024-12-13 19:03:14 +08:00
|
|
|
|
additionLabel={t('请在系统设置页面编辑分组倍率以添加新的分组:')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('groups', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.groups}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
optionList={groupOptions}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{inputs.type === 18 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>模型版本:</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="other"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
placeholder={
|
|
|
|
|
|
'请输入星火大模型版本,注意是接口地址中的版本号,例如:v2.1'
|
|
|
|
|
|
}
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('other', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.other}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-08-27 20:19:51 +08:00
|
|
|
|
{inputs.type === 41 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('部署地区')}:</Typography.Text>
|
2024-08-27 20:19:51 +08:00
|
|
|
|
</div>
|
2024-08-28 18:43:40 +08:00
|
|
|
|
<TextArea
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="other"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入部署地区,例如:us-central1\n支持使用模型映射格式\n' +
|
2024-08-28 18:43:40 +08:00
|
|
|
|
'{\n' +
|
|
|
|
|
|
' "default": "us-central1",\n' +
|
|
|
|
|
|
' "claude-3-5-sonnet-20240620": "europe-west1"\n' +
|
2024-12-13 19:03:14 +08:00
|
|
|
|
'}')}
|
2024-08-28 18:43:40 +08:00
|
|
|
|
autosize={{ minRows: 2 }}
|
2024-08-27 20:19:51 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('other', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.other}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-08-27 20:19:51 +08:00
|
|
|
|
/>
|
2024-08-28 18:43:40 +08:00
|
|
|
|
<Typography.Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
color: 'rgba(var(--semi-blue-5), 1)',
|
|
|
|
|
|
userSelect: 'none',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
cursor: 'pointer'
|
2024-08-28 18:43:40 +08:00
|
|
|
|
}}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handleInputChange(
|
|
|
|
|
|
'other',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
JSON.stringify(REGION_EXAMPLE, null, 2)
|
2024-08-28 18:43:40 +08:00
|
|
|
|
);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('填入模板')}
|
2024-08-28 18:43:40 +08:00
|
|
|
|
</Typography.Text>
|
2024-08-27 20:19:51 +08:00
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
{inputs.type === 21 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-24 18:02:08 +08:00
|
|
|
|
<Typography.Text strong><EFBFBD><EFBFBD>识库 ID:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-11-19 01:13:18 +08:00
|
|
|
|
label="知识库 ID"
|
|
|
|
|
|
name="other"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
placeholder={'请输入知识库 ID,例如:123456'}
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('other', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.other}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-07-13 19:55:22 +08:00
|
|
|
|
{inputs.type === 39 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>Account ID:</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="other"
|
2024-07-13 19:55:22 +08:00
|
|
|
|
placeholder={
|
|
|
|
|
|
'请输入Account ID,例如:d6b5da8hk1awo8nap34ube6gh'
|
|
|
|
|
|
}
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('other', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.other}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-07-13 19:55:22 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('模型')}:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Select
|
|
|
|
|
|
placeholder={'请选择该渠道所支持的模型'}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="models"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
required
|
|
|
|
|
|
multiple
|
|
|
|
|
|
selection
|
2024-12-11 21:33:30 +08:00
|
|
|
|
filter
|
|
|
|
|
|
searchPosition='dropdown'
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('models', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.models}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
optionList={modelOptions}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div style={{ lineHeight: '40px', marginBottom: '12px' }}>
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<Button
|
2024-11-19 01:13:18 +08:00
|
|
|
|
type="primary"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handleInputChange('models', basicModels);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('填入相关模型')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
2024-11-19 01:13:18 +08:00
|
|
|
|
type="secondary"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handleInputChange('models', fullModels);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('填入所有模型')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Tooltip content={t('新建渠道时,请求通过当前浏览器发出;编辑已有渠道,请求通过后端服务器发出')}>
|
2024-05-21 22:16:20 +08:00
|
|
|
|
<Button
|
2024-11-19 01:13:18 +08:00
|
|
|
|
type="tertiary"
|
2024-05-21 22:16:20 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
fetchUpstreamModelList('models');
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('获取模型列表')}
|
2024-05-21 22:16:20 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
</Tooltip>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<Button
|
2024-11-19 01:13:18 +08:00
|
|
|
|
type="warning"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handleInputChange('models', []);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('清除所有模型')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
addonAfter={
|
2024-11-19 01:13:18 +08:00
|
|
|
|
<Button type="primary" onClick={addCustomModels}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('填入')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('输入自定义模型名称')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
value={customModel}
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
setCustomModel(value.trim());
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('模型重定向')}:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<TextArea
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称,例如:') + `\n${JSON.stringify(MODEL_MAPPING_EXAMPLE, null, 2)}`}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="model_mapping"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('model_mapping', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
autosize
|
|
|
|
|
|
value={inputs.model_mapping}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<Typography.Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
color: 'rgba(var(--semi-blue-5), 1)',
|
|
|
|
|
|
userSelect: 'none',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
cursor: 'pointer'
|
2024-03-23 21:24:39 +08:00
|
|
|
|
}}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handleInputChange(
|
|
|
|
|
|
'model_mapping',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
JSON.stringify(MODEL_MAPPING_EXAMPLE, null, 2)
|
2024-03-23 21:24:39 +08:00
|
|
|
|
);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('填入模板')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('密钥')}:</Typography.Text>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
{batch ? (
|
|
|
|
|
|
<TextArea
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('密钥')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="key"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
required
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入密钥,一行一个')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('key', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.key}
|
|
|
|
|
|
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
2024-08-27 20:19:51 +08:00
|
|
|
|
<>
|
|
|
|
|
|
{inputs.type === 41 ? (
|
|
|
|
|
|
<TextArea
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('鉴权json')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="key"
|
2024-08-27 20:19:51 +08:00
|
|
|
|
required
|
|
|
|
|
|
placeholder={'{\n' +
|
|
|
|
|
|
' "type": "service_account",\n' +
|
|
|
|
|
|
' "project_id": "abc-bcd-123-456",\n' +
|
|
|
|
|
|
' "private_key_id": "123xxxxx456",\n' +
|
|
|
|
|
|
' "private_key": "-----BEGIN PRIVATE KEY-----xxxx\n' +
|
|
|
|
|
|
' "client_email": "xxx@developer.gserviceaccount.com",\n' +
|
|
|
|
|
|
' "client_id": "111222333",\n' +
|
|
|
|
|
|
' "auth_uri": "https://accounts.google.com/o/oauth2/auth",\n' +
|
|
|
|
|
|
' "token_uri": "https://oauth2.googleapis.com/token",\n' +
|
|
|
|
|
|
' "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\n' +
|
|
|
|
|
|
' "client_x509_cert_url": "https://xxxxx.gserviceaccount.com",\n' +
|
|
|
|
|
|
' "universe_domain": "googleapis.com"\n' +
|
|
|
|
|
|
'}'}
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('key', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
autosize={{ minRows: 10 }}
|
|
|
|
|
|
value={inputs.key}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-08-27 20:19:51 +08:00
|
|
|
|
/>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Input
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('密钥')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="key"
|
2024-08-27 20:19:51 +08:00
|
|
|
|
required
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t(type2secretPrompt(inputs.type))}
|
2024-08-27 20:19:51 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('key', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.key}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-08-27 20:19:51 +08:00
|
|
|
|
/>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
)}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{!isEdit && (
|
|
|
|
|
|
<div style={{ marginTop: 10, display: 'flex' }}>
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<Checkbox
|
|
|
|
|
|
checked={batch}
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('批量创建')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="batch"
|
|
|
|
|
|
onChange={() => setBatch(!batch)}
|
|
|
|
|
|
/>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('批量创建')}</Typography.Text>
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</Space>
|
|
|
|
|
|
</div>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
)}
|
2024-04-23 11:44:40 +08:00
|
|
|
|
{inputs.type === 1 && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('组织')}:</Typography.Text>
|
2024-04-23 11:44:40 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('组织,可选,不填则为默认组织')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="openai_organization"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('请输入组织org-xxx')}
|
2024-04-23 11:44:40 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('openai_organization', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.openai_organization}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2024-04-04 17:28:56 +08:00
|
|
|
|
<div style={{ marginTop: 10 }}>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
<Typography.Text strong>{t('默认测试模型')}:</Typography.Text>
|
2024-04-04 17:28:56 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="test_model"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('不填则为模型列表第一个')}
|
2024-04-04 17:28:56 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('test_model', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.test_model}
|
|
|
|
|
|
/>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
<div style={{ marginTop: 10, display: 'flex' }}>
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<Checkbox
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="auto_ban"
|
2024-03-23 21:24:39 +08:00
|
|
|
|
checked={autoBan}
|
|
|
|
|
|
onChange={() => {
|
|
|
|
|
|
setAutoBan(!autoBan);
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Typography.Text strong>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('是否自动禁用(仅当自动禁用开启时有效),关闭后不会自动禁用该渠道:')}
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
</div>
|
2024-04-23 11:44:40 +08:00
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('状态码复写(仅影响本地判断,不修改返回到上游的状态码)')}:
|
2024-04-23 11:44:40 +08:00
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<TextArea
|
2025-01-07 12:40:36 +08:00
|
|
|
|
placeholder={t('此项可选,用于复写返回的状态码,比如将claude渠道的400错误复写为500(用于重试),请勿滥用该功能,例如:') +
|
2024-12-13 19:03:14 +08:00
|
|
|
|
'\n' + JSON.stringify(STATUS_CODE_MAPPING_EXAMPLE, null, 2)}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="status_code_mapping"
|
2024-04-23 11:44:40 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('status_code_mapping', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
autosize
|
|
|
|
|
|
value={inputs.status_code_mapping}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
autoComplete="new-password"
|
2024-04-23 11:44:40 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<Typography.Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
color: 'rgba(var(--semi-blue-5), 1)',
|
|
|
|
|
|
userSelect: 'none',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
cursor: 'pointer'
|
2024-04-23 11:44:40 +08:00
|
|
|
|
}}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handleInputChange(
|
|
|
|
|
|
'status_code_mapping',
|
2024-11-19 01:13:18 +08:00
|
|
|
|
JSON.stringify(STATUS_CODE_MAPPING_EXAMPLE, null, 2)
|
2024-04-23 11:44:40 +08:00
|
|
|
|
);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('填入模板')}
|
2024-04-23 11:44:40 +08:00
|
|
|
|
</Typography.Text>
|
2024-11-19 01:13:18 +08:00
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('渠道标签')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('渠道标签')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="tag"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('渠道标签')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('tag', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.tag}
|
|
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('渠道优先级')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('渠道优先级')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="priority"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('渠道优先级')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
onChange={(value) => {
|
2024-12-09 21:26:17 +08:00
|
|
|
|
const number = parseInt(value);
|
|
|
|
|
|
if (isNaN(number)) {
|
|
|
|
|
|
handleInputChange('priority', value);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
handleInputChange('priority', number);
|
|
|
|
|
|
}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.priority}
|
|
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>
|
2024-12-13 19:03:14 +08:00
|
|
|
|
{t('渠道权重')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Input
|
2024-12-13 19:03:14 +08:00
|
|
|
|
label={t('渠道权重')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
name="weight"
|
2024-12-13 19:03:14 +08:00
|
|
|
|
placeholder={t('渠道权重')}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
onChange={(value) => {
|
2024-12-09 21:26:17 +08:00
|
|
|
|
const number = parseInt(value);
|
|
|
|
|
|
if (isNaN(number)) {
|
|
|
|
|
|
handleInputChange('weight', value);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
handleInputChange('weight', number);
|
|
|
|
|
|
}
|
2024-11-19 01:13:18 +08:00
|
|
|
|
}}
|
|
|
|
|
|
value={inputs.weight}
|
|
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
|
/>
|
2024-12-15 15:52:41 +08:00
|
|
|
|
<>
|
|
|
|
|
|
<div style={{ marginTop: 10 }}>
|
|
|
|
|
|
<Typography.Text strong>
|
|
|
|
|
|
{t('渠道额外设置')}:
|
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<TextArea
|
|
|
|
|
|
placeholder={t('此项可选,用于配置渠道特定设置,为一个 JSON 字符串,例如:') + '\n{\n "force_format": true\n}'}
|
|
|
|
|
|
name="setting"
|
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
|
handleInputChange('setting', value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
autosize
|
|
|
|
|
|
value={inputs.setting}
|
|
|
|
|
|
autoComplete="new-password"
|
|
|
|
|
|
/>
|
2025-02-02 22:18:37 +08:00
|
|
|
|
<Space>
|
|
|
|
|
|
<Typography.Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
color: 'rgba(var(--semi-blue-5), 1)',
|
|
|
|
|
|
userSelect: 'none',
|
|
|
|
|
|
cursor: 'pointer'
|
|
|
|
|
|
}}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
handleInputChange(
|
|
|
|
|
|
'setting',
|
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
|
force_format: true
|
|
|
|
|
|
}, null, 2)
|
|
|
|
|
|
);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('填入模板')}
|
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
<Typography.Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
color: 'rgba(var(--semi-blue-5), 1)',
|
|
|
|
|
|
userSelect: 'none',
|
|
|
|
|
|
cursor: 'pointer'
|
|
|
|
|
|
}}
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
window.open('https://github.com/Calcium-Ion/new-api/blob/main/docs/channel/other_setting.md');
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t('设置说明')}
|
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
</Space>
|
2025-02-02 22:15:06 +08:00
|
|
|
|
</>
|
2024-03-23 21:24:39 +08:00
|
|
|
|
</Spin>
|
|
|
|
|
|
</SideSheet>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
2023-04-23 12:43:10 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default EditChannel;
|