mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-16 13:13:41 +08:00
feat: support custom http header
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user