|
@@ -1,7 +1,7 @@
|
|
|
import React, { useEffect, useState } from 'react';
|
|
import React, { useEffect, useState } from 'react';
|
|
|
import { Button, Form, Header, Message, Segment } from 'semantic-ui-react';
|
|
import { Button, Form, Header, Message, Segment } from 'semantic-ui-react';
|
|
|
import { useParams } from 'react-router-dom';
|
|
import { useParams } from 'react-router-dom';
|
|
|
-import { API, showError, showInfo, showSuccess } from '../../helpers';
|
|
|
|
|
|
|
+import { API, showError, showInfo, showSuccess, verifyJSON } from '../../helpers';
|
|
|
import { CHANNEL_OPTIONS } from '../../constants';
|
|
import { CHANNEL_OPTIONS } from '../../constants';
|
|
|
|
|
|
|
|
const EditChannel = () => {
|
|
const EditChannel = () => {
|
|
@@ -15,6 +15,7 @@ const EditChannel = () => {
|
|
|
key: '',
|
|
key: '',
|
|
|
base_url: '',
|
|
base_url: '',
|
|
|
other: '',
|
|
other: '',
|
|
|
|
|
+ model_mapping:'',
|
|
|
models: [],
|
|
models: [],
|
|
|
groups: ['default']
|
|
groups: ['default']
|
|
|
};
|
|
};
|
|
@@ -42,6 +43,9 @@ const EditChannel = () => {
|
|
|
} else {
|
|
} else {
|
|
|
data.groups = data.group.split(',');
|
|
data.groups = data.group.split(',');
|
|
|
}
|
|
}
|
|
|
|
|
+ if (data.model_mapping !== '') {
|
|
|
|
|
+ data.model_mapping = JSON.stringify(JSON.parse(data.model_mapping), null, 2);
|
|
|
|
|
+ }
|
|
|
setInputs(data);
|
|
setInputs(data);
|
|
|
} else {
|
|
} else {
|
|
|
showError(message);
|
|
showError(message);
|
|
@@ -94,6 +98,10 @@ const EditChannel = () => {
|
|
|
showInfo('请至少选择一个模型!');
|
|
showInfo('请至少选择一个模型!');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (inputs.model_mapping !== "" && !verifyJSON(inputs.model_mapping)) {
|
|
|
|
|
+ showInfo('模型映射必须是合法的 JSON 格式!');
|
|
|
|
|
+ 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);
|
|
@@ -246,6 +254,17 @@ const EditChannel = () => {
|
|
|
handleInputChange(null, { name: 'models', value: [] });
|
|
handleInputChange(null, { name: 'models', value: [] });
|
|
|
}}>清除所有模型</Button>
|
|
}}>清除所有模型</Button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ <Form.Field>
|
|
|
|
|
+ <Form.TextArea
|
|
|
|
|
+ label='模型映射'
|
|
|
|
|
+ placeholder={'为一个 JSON 文本,键为用户请求的模型名称,值为要替换的模型名称'}
|
|
|
|
|
+ name='model_mapping'
|
|
|
|
|
+ onChange={handleInputChange}
|
|
|
|
|
+ value={inputs.model_mapping}
|
|
|
|
|
+ style={{ minHeight: 100, fontFamily: 'JetBrains Mono, Consolas' }}
|
|
|
|
|
+ autoComplete='new-password'
|
|
|
|
|
+ />
|
|
|
|
|
+ </Form.Field>
|
|
|
{
|
|
{
|
|
|
batch ? <Form.Field>
|
|
batch ? <Form.Field>
|
|
|
<Form.TextArea
|
|
<Form.TextArea
|