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
b0dcea7e
authored
Apr 04, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: able to set default test model (#138)
parent
6b8d8d77
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
3 deletions
+19
-3
controller/channel-test.go
+5
-2
middleware/distributor.go
+1
-1
model/channel.go
+1
-0
web/src/pages/Channel/EditChannel.js
+12
-0
No files found.
controller/channel-test.go
View file @
b0dcea7e
...
...
@@ -27,7 +27,6 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
if
channel
.
Type
==
common
.
ChannelTypeMidjourney
{
return
errors
.
New
(
"midjourney channel test is not supported"
),
nil
}
common
.
SysLog
(
fmt
.
Sprintf
(
"testing channel %d with model %s"
,
channel
.
Id
,
testModel
))
w
:=
httptest
.
NewRecorder
()
c
,
_
:=
gin
.
CreateTestContext
(
w
)
c
.
Request
=
&
http
.
Request
{
...
...
@@ -60,12 +59,16 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
return
fmt
.
Errorf
(
"invalid api type: %d, adaptor is nil"
,
apiType
),
nil
}
if
testModel
==
""
{
if
channel
.
TestModel
!=
nil
&&
*
channel
.
TestModel
!=
""
{
testModel
=
*
channel
.
TestModel
}
else
{
testModel
=
adaptor
.
GetModelList
()[
0
]
meta
.
UpstreamModelName
=
testModel
}
}
request
:=
buildTestRequest
()
request
.
Model
=
testModel
meta
.
UpstreamModelName
=
testModel
common
.
SysLog
(
fmt
.
Sprintf
(
"testing channel %d with model %s"
,
channel
.
Id
,
testModel
))
adaptor
.
Init
(
meta
,
*
request
)
...
...
middleware/distributor.go
View file @
b0dcea7e
...
...
@@ -163,7 +163,7 @@ func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, mode
if
channel
.
AutoBan
!=
nil
&&
*
channel
.
AutoBan
==
0
{
ban
=
false
}
if
nil
!=
channel
.
OpenAIOrganization
{
if
nil
!=
channel
.
OpenAIOrganization
&&
""
!=
*
channel
.
OpenAIOrganization
{
c
.
Set
(
"channel_organization"
,
*
channel
.
OpenAIOrganization
)
}
c
.
Set
(
"auto_ban"
,
ban
)
...
...
model/channel.go
View file @
b0dcea7e
...
...
@@ -10,6 +10,7 @@ type Channel struct {
Type
int
`json:"type" gorm:"default:0"`
Key
string
`json:"key" gorm:"not null"`
OpenAIOrganization
*
string
`json:"openai_organization"`
TestModel
*
string
`json:"test_model"`
Status
int
`json:"status" gorm:"default:1"`
Name
string
`json:"name" gorm:"index"`
Weight
*
uint
`json:"weight" gorm:"default:0"`
...
...
web/src/pages/Channel/EditChannel.js
View file @
b0dcea7e
...
...
@@ -63,6 +63,7 @@ const EditChannel = (props) => {
model_mapping
:
''
,
models
:
[],
auto_ban
:
1
,
test_model
:
''
,
groups
:
[
'default'
],
};
const
[
batch
,
setBatch
]
=
useState
(
false
);
...
...
@@ -669,6 +670,17 @@ const EditChannel = (props) => {
}}
value
=
{
inputs
.
openai_organization
}
/
>
<
div
style
=
{{
marginTop
:
10
}}
>
<
Typography
.
Text
strong
>
默认测试模型:
<
/Typography.Text
>
<
/div
>
<
Input
name
=
'test_model'
placeholder
=
'不填则为模型列表第一个'
onChange
=
{(
value
)
=>
{
handleInputChange
(
'test_model'
,
value
);
}}
value
=
{
inputs
.
test_model
}
/
>
<
div
style
=
{{
marginTop
:
10
,
display
:
'flex'
}}
>
<
Space
>
<
Checkbox
...
...
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