chore: able to clear all models now

This commit is contained in:
JustSong 2023-06-22 20:53:21 +08:00
parent fe135fd508
commit d0c454c78e

View File

@ -32,15 +32,15 @@ const EditChannel = () => {
let res = await API.get(`/api/channel/${channelId}`); let res = await API.get(`/api/channel/${channelId}`);
const { success, message, data } = res.data; const { success, message, data } = res.data;
if (success) { if (success) {
if (data.models === "") { if (data.models === '') {
data.models = [] data.models = [];
} else { } else {
data.models = data.models.split(",") data.models = data.models.split(',');
} }
if (data.group === "") { if (data.group === '') {
data.groups = [] data.groups = [];
} else { } else {
data.groups = data.group.split(",") data.groups = data.group.split(',');
} }
setInputs(data); setInputs(data);
} else { } else {
@ -55,10 +55,10 @@ const EditChannel = () => {
setModelOptions(res.data.data.map((model) => ({ setModelOptions(res.data.data.map((model) => ({
key: model.id, key: model.id,
text: model.id, text: model.id,
value: model.id, value: model.id
}))); })));
setFullModels(res.data.data.map((model) => model.id)); setFullModels(res.data.data.map((model) => model.id));
setBasicModels(res.data.data.filter((model) => !model.id.startsWith("gpt-4")).map((model) => model.id)); setBasicModels(res.data.data.filter((model) => !model.id.startsWith('gpt-4')).map((model) => model.id));
} catch (error) { } catch (error) {
showError(error.message); showError(error.message);
} }
@ -70,7 +70,7 @@ const EditChannel = () => {
setGroupOptions(res.data.data.map((group) => ({ setGroupOptions(res.data.data.map((group) => ({
key: group, key: group,
text: group, text: group,
value: group, value: group
}))); })));
} catch (error) { } catch (error) {
showError(error.message); showError(error.message);
@ -90,6 +90,10 @@ const EditChannel = () => {
showInfo('请填写渠道名称和渠道密钥!'); showInfo('请填写渠道名称和渠道密钥!');
return; return;
} }
if (inputs.models.length === 0) {
showInfo('请至少选择一个模型!');
return;
}
let localInputs = inputs; let localInputs = inputs;
if (localInputs.base_url.endsWith('/')) { if (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);
@ -98,8 +102,8 @@ const EditChannel = () => {
localInputs.other = '2023-03-15-preview'; localInputs.other = '2023-03-15-preview';
} }
let res; let res;
localInputs.models = localInputs.models.join(",") localInputs.models = localInputs.models.join(',');
localInputs.group = localInputs.groups.join(",") localInputs.group = localInputs.groups.join(',');
if (isEdit) { if (isEdit) {
res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) }); res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) });
} else { } else {
@ -238,6 +242,9 @@ const EditChannel = () => {
<Button type={'button'} onClick={() => { <Button type={'button'} onClick={() => {
handleInputChange(null, { name: 'models', value: fullModels }); handleInputChange(null, { name: 'models', value: fullModels });
}}>填入所有模型</Button> }}>填入所有模型</Button>
<Button type={'button'} onClick={() => {
handleInputChange(null, { name: 'models', value: [] });
}}>清除所有模型</Button>
</div> </div>
{ {
batch ? <Form.Field> batch ? <Form.Field>