feat: support custom http header

This commit is contained in:
ckt1031
2023-07-19 21:25:34 +08:00
parent cf564f36fa
commit 66e02a4bcf
6 changed files with 79 additions and 1 deletions

View File

@@ -23,6 +23,10 @@ const MODEL_MAPPING_EXAMPLE = {
'gpt-4-32k-0314': 'gpt-4-32k',
};
const CUSTOM_HTTP_HEADERS_EXAMPLE = {
'X-OpenAI-Organization': 'OpenAI',
};
const EditChannel = () => {
const params = useParams();
const channelId = params.id;
@@ -35,6 +39,7 @@ const EditChannel = () => {
base_url: '',
other: '',
model_mapping: '',
custom_http_headers: '',
models: [],
groups: ['default'],
enable_ip_randomization: false,
@@ -85,6 +90,13 @@ const EditChannel = () => {
2,
);
}
if (data.custom_http_headers !== '') {
data.custom_http_headers = JSON.stringify(
JSON.parse(data.custom_http_headers),
null,
2,
);
}
setInputs(data);
} else {
showError(message);
@@ -153,6 +165,13 @@ const EditChannel = () => {
showInfo('模型映射必须是合法的 JSON 格式!');
return;
}
if (
inputs.custom_http_headers !== '' &&
!verifyJSON(inputs.custom_http_headers)
) {
showInfo('自定义 HTTP 头必须是合法的 JSON 格式!');
return;
}
let localInputs = inputs;
if (localInputs.base_url.endsWith('/')) {
localInputs.base_url = localInputs.base_url.slice(
@@ -394,6 +413,21 @@ const EditChannel = () => {
autoComplete='new-password'
/>
</Form.Field>
<Form.Field>
<Form.TextArea
label='自定义 HTTP 头'
placeholder={`此项可选,为一个 JSON 文本,键为 HTTP 头名称,值为 HTTP 头内容,例如:\n${JSON.stringify(
CUSTOM_HTTP_HEADERS_EXAMPLE,
null,
2,
)}`}
name='custom_http_headers'
onChange={handleInputChange}
value={inputs.custom_http_headers}
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
autoComplete='new-password'
/>
</Form.Field>
{batch ? (
<Form.Field>
<Form.TextArea