Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ff0e690b
authored
May 21, 2024
by
bubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加同步上游模型列表按钮
parent
f5befd5a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
3 deletions
+40
-3
web/src/pages/Channel/EditChannel.js
+40
-3
No files found.
web/src/pages/Channel/EditChannel.js
View file @
ff0e690b
...
@@ -24,6 +24,7 @@ import {
...
@@ -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) => {
...
@@ -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) => {
...
@@ -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
);
...
@@ -302,7 +331,7 @@ const EditChannel = (props) => {
...
@@ -302,7 +331,7 @@ const EditChannel = (props) => {
if
(
customModel
.
trim
()
===
''
)
return
;
if
(
customModel
.
trim
()
===
''
)
return
;
// 使用逗号分隔字符串,然后去除每个模型名称前后的空格
// 使用逗号分隔字符串,然后去除每个模型名称前后的空格
const
modelArray
=
customModel
.
split
(
','
).
map
(
model
=>
model
.
trim
());
const
modelArray
=
customModel
.
split
(
','
).
map
(
model
=>
model
.
trim
());
let
localModels
=
[...
inputs
.
models
];
let
localModels
=
[...
inputs
.
models
];
let
localModelOptions
=
[...
modelOptions
];
let
localModelOptions
=
[...
modelOptions
];
let
hasError
=
false
;
let
hasError
=
false
;
...
@@ -547,6 +576,14 @@ const EditChannel = (props) => {
...
@@ -547,6 +576,14 @@ const EditChannel = (props) => {
填入所有模型
填入所有模型
<
/Button
>
<
/Button
>
<
Button
<
Button
type
=
'tertiary'
onClick
=
{()
=>
{
fetchUpstreamModelList
(
'models'
);
}}
>
获取模型列表
<
/Button
>
<
Button
type
=
'warning'
type
=
'warning'
onClick
=
{()
=>
{
onClick
=
{()
=>
{
handleInputChange
(
'models'
,
[]);
handleInputChange
(
'models'
,
[]);
...
@@ -660,7 +697,7 @@ const EditChannel = (props) => {
...
@@ -660,7 +697,7 @@ const EditChannel = (props) => {
onChange
=
{()
=>
{
onChange
=
{()
=>
{
setAutoBan
(
!
autoBan
);
setAutoBan
(
!
autoBan
);
}}
}}
// onChange={handleInputChange}
// onChange={handleInputChange}
/
>
/
>
<
Typography
.
Text
strong
>
<
Typography
.
Text
strong
>
是否自动禁用(仅当自动禁用开启时有效),关闭后不会自动禁用该渠道:
是否自动禁用(仅当自动禁用开启时有效),关闭后不会自动禁用该渠道:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment