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
8aab40ad
authored
Feb 01, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 支持测试渠道时自选模型
parent
101f9f6a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
controller/channel-test.go
+10
-2
web/src/components/ChannelsTable.js
+25
-5
No files found.
controller/channel-test.go
View file @
8aab40ad
...
@@ -34,14 +34,18 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
...
@@ -34,14 +34,18 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
case
common
.
ChannelTypeXunfei
:
case
common
.
ChannelTypeXunfei
:
return
errors
.
New
(
"该渠道类型当前版本不支持测试,请手动测试"
),
nil
return
errors
.
New
(
"该渠道类型当前版本不支持测试,请手动测试"
),
nil
case
common
.
ChannelTypeAzure
:
case
common
.
ChannelTypeAzure
:
request
.
Model
=
"gpt-35-turbo"
if
request
.
Model
==
""
{
request
.
Model
=
"gpt-35-turbo"
}
defer
func
()
{
defer
func
()
{
if
err
!=
nil
{
if
err
!=
nil
{
err
=
errors
.
New
(
"请确保已在 Azure 上创建了 gpt-35-turbo 模型,并且 apiVersion 已正确填写!"
)
err
=
errors
.
New
(
"请确保已在 Azure 上创建了 gpt-35-turbo 模型,并且 apiVersion 已正确填写!"
)
}
}
}()
}()
default
:
default
:
request
.
Model
=
"gpt-3.5-turbo"
if
request
.
Model
==
""
{
request
.
Model
=
"gpt-3.5-turbo"
}
}
}
requestURL
:=
getFullRequestURL
(
channel
.
GetBaseURL
(),
"/v1/chat/completions"
,
channel
.
Type
)
requestURL
:=
getFullRequestURL
(
channel
.
GetBaseURL
(),
"/v1/chat/completions"
,
channel
.
Type
)
...
@@ -102,6 +106,7 @@ func TestChannel(c *gin.Context) {
...
@@ -102,6 +106,7 @@ func TestChannel(c *gin.Context) {
})
})
return
return
}
}
testModel
:=
c
.
Param
(
"model"
)
channel
,
err
:=
model
.
GetChannelById
(
id
,
true
)
channel
,
err
:=
model
.
GetChannelById
(
id
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -111,6 +116,9 @@ func TestChannel(c *gin.Context) {
...
@@ -111,6 +116,9 @@ func TestChannel(c *gin.Context) {
return
return
}
}
testRequest
:=
buildTestRequest
()
testRequest
:=
buildTestRequest
()
if
testModel
!=
""
{
testRequest
.
Model
=
testModel
}
tik
:=
time
.
Now
()
tik
:=
time
.
Now
()
err
,
_
=
testChannel
(
channel
,
*
testRequest
)
err
,
_
=
testChannel
(
channel
,
*
testRequest
)
tok
:=
time
.
Now
()
tok
:=
time
.
Now
()
...
...
web/src/components/ChannelsTable.js
View file @
8aab40ad
...
@@ -23,9 +23,10 @@ import {
...
@@ -23,9 +23,10 @@ import {
Space
,
Space
,
Tooltip
,
Tooltip
,
Switch
,
Switch
,
Typography
,
InputNumber
Typography
,
InputNumber
,
Dropdown
,
SplitButtonGroup
}
from
"@douyinfe/semi-ui"
;
}
from
"@douyinfe/semi-ui"
;
import
EditChannel
from
"../pages/Channel/EditChannel"
;
import
EditChannel
from
"../pages/Channel/EditChannel"
;
import
{
IconTreeTriangleDown
}
from
"@douyinfe/semi-icons"
;
function
renderTimestamp
(
timestamp
)
{
function
renderTimestamp
(
timestamp
)
{
return
(
return
(
...
@@ -195,7 +196,14 @@ const ChannelsTable = () => {
...
@@ -195,7 +196,14 @@ const ChannelsTable = () => {
dataIndex
:
'operate'
,
dataIndex
:
'operate'
,
render
:
(
text
,
record
,
index
)
=>
(
render
:
(
text
,
record
,
index
)
=>
(
<
div
>
<
div
>
<
Button
theme
=
'light'
type
=
'primary'
style
=
{{
marginRight
:
1
}}
onClick
=
{()
=>
testChannel
(
record
)}
>
测试
<
/Button
>
<
SplitButtonGroup
style
=
{{
marginRight
:
1
}}
aria
-
label
=
"测试操作项目组"
>
<
Button
theme
=
"light"
onClick
=
{()
=>
{
testChannel
(
record
,
''
)}}
>
测试
<
/Button
>
<
Dropdown
trigger
=
"click"
position
=
"bottomRight"
menu
=
{
record
.
test_models
}
>
<
Button
style
=
{
{
padding
:
'8px 4px'
}}
type
=
"primary"
icon
=
{
<
IconTreeTriangleDown
/>
}
><
/Button
>
<
/Dropdown
>
<
/SplitButtonGroup
>
{
/*<Button theme='light' type='primary' style={{marginRight: 1}} onClick={()=>testChannel(record)}>测试</Button>*/
}
<
Popconfirm
<
Popconfirm
title
=
"确定是否要删除此渠道?"
title
=
"确定是否要删除此渠道?"
content
=
"此修改将不可逆"
content
=
"此修改将不可逆"
...
@@ -277,6 +285,17 @@ const ChannelsTable = () => {
...
@@ -277,6 +285,17 @@ const ChannelsTable = () => {
const
setChannelFormat
=
(
channels
)
=>
{
const
setChannelFormat
=
(
channels
)
=>
{
for
(
let
i
=
0
;
i
<
channels
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
channels
.
length
;
i
++
)
{
channels
[
i
].
key
=
''
+
channels
[
i
].
id
;
channels
[
i
].
key
=
''
+
channels
[
i
].
id
;
let
test_models
=
[]
channels
[
i
].
models
.
split
(
','
).
forEach
((
item
,
index
)
=>
{
test_models
.
push
({
node
:
'item'
,
name
:
item
,
onClick
:
()
=>
{
testChannel
(
channels
[
i
],
item
)
}
})
})
channels
[
i
].
test_models
=
test_models
}
}
// data.key = '' + data.id
// data.key = '' + data.id
setChannels
(
channels
);
setChannels
(
channels
);
...
@@ -440,14 +459,15 @@ const ChannelsTable = () => {
...
@@ -440,14 +459,15 @@ const ChannelsTable = () => {
setSearching
(
false
);
setSearching
(
false
);
};
};
const
testChannel
=
async
(
record
)
=>
{
const
testChannel
=
async
(
record
,
model
)
=>
{
const
res
=
await
API
.
get
(
`/api/channel/test/
${
record
.
id
}
/
`
);
const
res
=
await
API
.
get
(
`/api/channel/test/
${
record
.
id
}
?model=
${
model
}
`
);
const
{
success
,
message
,
time
}
=
res
.
data
;
const
{
success
,
message
,
time
}
=
res
.
data
;
if
(
success
)
{
if
(
success
)
{
let
newChannels
=
[...
channels
];
let
newChannels
=
[...
channels
];
record
.
response_time
=
time
*
1000
;
record
.
response_time
=
time
*
1000
;
record
.
test_time
=
Date
.
now
()
/
1000
;
record
.
test_time
=
Date
.
now
()
/
1000
;
setChannels
(
newChannels
);
setChannelFormat
(
newChannels
)
showInfo
(
`通道
${
record
.
name
}
测试成功,耗时
${
time
.
toFixed
(
2
)}
秒。`
);
showInfo
(
`通道
${
record
.
name
}
测试成功,耗时
${
time
.
toFixed
(
2
)}
秒。`
);
}
else
{
}
else
{
showError
(
message
);
showError
(
message
);
...
...
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