mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-19 08:56:37 +08:00
添加同步上游模型列表按钮
This commit is contained in:
parent
d6c1e3f37c
commit
6fe643b1c1
@ -24,6 +24,7 @@ import {
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { Divider } from 'semantic-ui-react';
|
||||
import { getChannelModels, loadChannelModels } from '../../components/utils.js';
|
||||
import axios from 'axios';
|
||||
|
||||
const MODEL_MAPPING_EXAMPLE = {
|
||||
'gpt-3.5-turbo-0301': 'gpt-3.5-turbo',
|
||||
@ -86,6 +87,34 @@ const EditChannel = (props) => {
|
||||
const [basicModels, setBasicModels] = useState([]);
|
||||
const [fullModels, setFullModels] = 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) => {
|
||||
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
||||
if (name === 'type') {
|
||||
@ -546,6 +575,14 @@ const EditChannel = (props) => {
|
||||
>
|
||||
填入所有模型
|
||||
</Button>
|
||||
<Button
|
||||
type='tertiary'
|
||||
onClick={() => {
|
||||
fetchUpstreamModelList('models');
|
||||
}}
|
||||
>
|
||||
获取模型列表
|
||||
</Button>
|
||||
<Button
|
||||
type='warning'
|
||||
onClick={() => {
|
||||
|
Loading…
Reference in New Issue
Block a user