mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-19 17:06:38 +08:00
添加同步上游模型列表按钮
This commit is contained in:
parent
d6c1e3f37c
commit
6fe643b1c1
@ -24,6 +24,7 @@ import {
|
|||||||
} from '@douyinfe/semi-ui';
|
} from '@douyinfe/semi-ui';
|
||||||
import { Divider } from 'semantic-ui-react';
|
import { Divider } from 'semantic-ui-react';
|
||||||
import { getChannelModels, loadChannelModels } from '../../components/utils.js';
|
import { getChannelModels, loadChannelModels } from '../../components/utils.js';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
const MODEL_MAPPING_EXAMPLE = {
|
const MODEL_MAPPING_EXAMPLE = {
|
||||||
'gpt-3.5-turbo-0301': 'gpt-3.5-turbo',
|
'gpt-3.5-turbo-0301': 'gpt-3.5-turbo',
|
||||||
@ -86,6 +87,34 @@ const EditChannel = (props) => {
|
|||||||
const [basicModels, setBasicModels] = useState([]);
|
const [basicModels, setBasicModels] = useState([]);
|
||||||
const [fullModels, setFullModels] = useState([]);
|
const [fullModels, setFullModels] = useState([]);
|
||||||
const [customModel, setCustomModel] = useState('');
|
const [customModel, setCustomModel] = useState('');
|
||||||
|
|
||||||
|
const fetchUpstreamModelList = (name) => {
|
||||||
|
const url = inputs['base_url'] + '/v1/models';
|
||||||
|
const key = inputs['key']
|
||||||
|
axios.get(url, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${key}`
|
||||||
|
}
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.data && res.data?.success) {
|
||||||
|
const models = res.data.data.map((model) => model.id);
|
||||||
|
handleInputChange(name, models);
|
||||||
|
showSuccess("获取模型列表成功");
|
||||||
|
} else {
|
||||||
|
showError('获取模型列表失败');
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
const errCode = error.response.status;
|
||||||
|
if (errCode === 401) {
|
||||||
|
showError(`获取模型列表失败,错误代码 ${errCode},请检查密钥是否填写`);
|
||||||
|
} else {
|
||||||
|
showError(`获取模型列表失败,错误代码 ${errCode}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleInputChange = (name, value) => {
|
const handleInputChange = (name, value) => {
|
||||||
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
||||||
if (name === 'type') {
|
if (name === 'type') {
|
||||||
@ -231,7 +260,7 @@ const EditChannel = (props) => {
|
|||||||
fetchModels().then();
|
fetchModels().then();
|
||||||
fetchGroups().then();
|
fetchGroups().then();
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
loadChannel().then(() => {});
|
loadChannel().then(() => { });
|
||||||
} else {
|
} else {
|
||||||
setInputs(originInputs);
|
setInputs(originInputs);
|
||||||
let localModels = getChannelModels(inputs.type);
|
let localModels = getChannelModels(inputs.type);
|
||||||
@ -546,6 +575,14 @@ const EditChannel = (props) => {
|
|||||||
>
|
>
|
||||||
填入所有模型
|
填入所有模型
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
type='tertiary'
|
||||||
|
onClick={() => {
|
||||||
|
fetchUpstreamModelList('models');
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
获取模型列表
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type='warning'
|
type='warning'
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@ -660,7 +697,7 @@ const EditChannel = (props) => {
|
|||||||
onChange={() => {
|
onChange={() => {
|
||||||
setAutoBan(!autoBan);
|
setAutoBan(!autoBan);
|
||||||
}}
|
}}
|
||||||
// onChange={handleInputChange}
|
// onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
<Typography.Text strong>
|
<Typography.Text strong>
|
||||||
是否自动禁用(仅当自动禁用开启时有效),关闭后不会自动禁用该渠道:
|
是否自动禁用(仅当自动禁用开启时有效),关闭后不会自动禁用该渠道:
|
||||||
|
Loading…
Reference in New Issue
Block a user