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
70eaca51
authored
Sep 13, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support o1 channel test
parent
e8452869
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
controller/channel-test.go
+15
-14
No files found.
controller/channel-test.go
View file @
70eaca51
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"one-api/relay/constant"
"one-api/relay/constant"
"one-api/service"
"one-api/service"
"strconv"
"strconv"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -81,8 +82,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
...
@@ -81,8 +82,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
return
fmt
.
Errorf
(
"invalid api type: %d, adaptor is nil"
,
apiType
),
nil
return
fmt
.
Errorf
(
"invalid api type: %d, adaptor is nil"
,
apiType
),
nil
}
}
request
:=
buildTestRequest
()
request
:=
buildTestRequest
(
testModel
)
request
.
Model
=
testModel
meta
.
UpstreamModelName
=
testModel
meta
.
UpstreamModelName
=
testModel
common
.
SysLog
(
fmt
.
Sprintf
(
"testing channel %d with model %s"
,
channel
.
Id
,
testModel
))
common
.
SysLog
(
fmt
.
Sprintf
(
"testing channel %d with model %s"
,
channel
.
Id
,
testModel
))
...
@@ -141,17 +141,22 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
...
@@ -141,17 +141,22 @@ func testChannel(channel *model.Channel, testModel string) (err error, openAIErr
return
nil
,
nil
return
nil
,
nil
}
}
func
buildTestRequest
()
*
dto
.
GeneralOpenAIRequest
{
func
buildTestRequest
(
model
string
)
*
dto
.
GeneralOpenAIRequest
{
testRequest
:=
&
dto
.
GeneralOpenAIRequest
{
testRequest
:=
&
dto
.
GeneralOpenAIRequest
{
Model
:
""
,
// this will be set later
Model
:
""
,
// this will be set later
MaxTokens
:
1
,
Stream
:
false
,
Stream
:
false
,
}
}
if
strings
.
HasPrefix
(
model
,
"o1-"
)
{
testRequest
.
MaxCompletionTokens
=
1
}
else
{
testRequest
.
MaxTokens
=
1
}
content
,
_
:=
json
.
Marshal
(
"hi"
)
content
,
_
:=
json
.
Marshal
(
"hi"
)
testMessage
:=
dto
.
Message
{
testMessage
:=
dto
.
Message
{
Role
:
"user"
,
Role
:
"user"
,
Content
:
content
,
Content
:
content
,
}
}
testRequest
.
Model
=
model
testRequest
.
Messages
=
append
(
testRequest
.
Messages
,
testMessage
)
testRequest
.
Messages
=
append
(
testRequest
.
Messages
,
testMessage
)
return
testRequest
return
testRequest
}
}
...
@@ -226,26 +231,22 @@ func testAllChannels(notify bool) error {
...
@@ -226,26 +231,22 @@ func testAllChannels(notify bool) error {
tok
:=
time
.
Now
()
tok
:=
time
.
Now
()
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
ban
:=
false
shouldBanChannel
:=
false
if
milliseconds
>
disableThreshold
{
err
=
errors
.
New
(
fmt
.
Sprintf
(
"响应时间 %.2fs 超过阈值 %.2fs"
,
float64
(
milliseconds
)
/
1000.0
,
float64
(
disableThreshold
)
/
1000.0
))
ban
=
true
}
// request error disables the channel
// request error disables the channel
if
openaiWithStatusErr
!=
nil
{
if
openaiWithStatusErr
!=
nil
{
oaiErr
:=
openaiWithStatusErr
.
Error
oaiErr
:=
openaiWithStatusErr
.
Error
err
=
errors
.
New
(
fmt
.
Sprintf
(
"type %s, httpCode %d, code %v, message %s"
,
oaiErr
.
Type
,
openaiWithStatusErr
.
StatusCode
,
oaiErr
.
Code
,
oaiErr
.
Message
))
err
=
errors
.
New
(
fmt
.
Sprintf
(
"type %s, httpCode %d, code %v, message %s"
,
oaiErr
.
Type
,
openaiWithStatusErr
.
StatusCode
,
oaiErr
.
Code
,
oaiErr
.
Message
))
ban
=
service
.
ShouldDisableChannel
(
channel
.
Type
,
openaiWithStatusErr
)
shouldBanChannel
=
service
.
ShouldDisableChannel
(
channel
.
Type
,
openaiWithStatusErr
)
}
}
// parse *int to bool
if
milliseconds
>
disableThreshold
{
if
!
channel
.
GetAutoBan
()
{
err
=
errors
.
New
(
fmt
.
Sprintf
(
"响应时间 %.2fs 超过阈值 %.2fs"
,
float64
(
milliseconds
)
/
1000.0
,
float64
(
disableThreshold
)
/
1000.0
))
ban
=
fals
e
shouldBanChannel
=
tru
e
}
}
// disable channel
// disable channel
if
ban
&&
isChannelEnabled
{
if
isChannelEnabled
&&
shouldBanChannel
&&
channel
.
GetAutoBan
()
{
service
.
DisableChannel
(
channel
.
Id
,
channel
.
Name
,
err
.
Error
())
service
.
DisableChannel
(
channel
.
Id
,
channel
.
Name
,
err
.
Error
())
}
}
...
...
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