From 6fe643b1c1944d48f79aca9d838aab3ee2108528 Mon Sep 17 00:00:00 2001 From: bubu Date: Tue, 21 May 2024 17:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=AD=A5=E4=B8=8A?= =?UTF-8?q?=E6=B8=B8=E6=A8=A1=E5=9E=8B=E5=88=97=E8=A1=A8=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Channel/EditChannel.js | 43 ++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 03b8e3b..2412002 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -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') { @@ -231,7 +260,7 @@ const EditChannel = (props) => { fetchModels().then(); fetchGroups().then(); if (isEdit) { - loadChannel().then(() => {}); + loadChannel().then(() => { }); } else { setInputs(originInputs); let localModels = getChannelModels(inputs.type); @@ -302,7 +331,7 @@ const EditChannel = (props) => { if (customModel.trim() === '') return; // 使用逗号分隔字符串,然后去除每个模型名称前后的空格 const modelArray = customModel.split(',').map(model => model.trim()); - + let localModels = [...inputs.models]; let localModelOptions = [...modelOptions]; let hasError = false; @@ -546,6 +575,14 @@ const EditChannel = (props) => { > 填入所有模型 +