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
8baaa7e9
authored
Jul 14, 2024
by
FENG
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: http code is not properly disabled
parent
6e72e4a5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
17 deletions
+12
-17
controller/channel-test.go
+10
-15
service/channel.go
+2
-2
No files found.
controller/channel-test.go
View file @
8baaa7e9
...
...
@@ -25,7 +25,7 @@ import (
"github.com/gin-gonic/gin"
)
func
testChannel
(
channel
*
model
.
Channel
,
testModel
string
)
(
err
error
,
open
aiErr
*
dto
.
OpenAIError
)
{
func
testChannel
(
channel
*
model
.
Channel
,
testModel
string
)
(
err
error
,
open
AIErrorWithStatusCode
*
dto
.
OpenAIErrorWithStatusCode
)
{
tik
:=
time
.
Now
()
if
channel
.
Type
==
common
.
ChannelTypeMidjourney
{
return
errors
.
New
(
"midjourney channel test is not supported"
),
nil
...
...
@@ -58,8 +58,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
modelMap
:=
make
(
map
[
string
]
string
)
err
:=
json
.
Unmarshal
([]
byte
(
modelMapping
),
&
modelMap
)
if
err
!=
nil
{
openaiErr
:=
service
.
OpenAIErrorWrapperLocal
(
err
,
"unmarshal_model_mapping_failed"
,
http
.
StatusInternalServerError
)
.
Error
return
err
,
&
openaiErr
return
err
,
service
.
OpenAIErrorWrapperLocal
(
err
,
"unmarshal_model_mapping_failed"
,
http
.
StatusInternalServerError
)
}
if
modelMap
[
testModel
]
!=
""
{
testModel
=
modelMap
[
testModel
]
...
...
@@ -104,11 +103,11 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
}
if
resp
!=
nil
&&
resp
.
StatusCode
!=
http
.
StatusOK
{
err
:=
relaycommon
.
RelayErrorHandler
(
resp
)
return
fmt
.
Errorf
(
"status code %d: %s"
,
resp
.
StatusCode
,
err
.
Error
.
Message
),
&
err
.
Erro
r
return
fmt
.
Errorf
(
"status code %d: %s"
,
resp
.
StatusCode
,
err
.
Error
.
Message
),
er
r
}
usage
,
respErr
:=
adaptor
.
DoResponse
(
c
,
resp
,
meta
)
if
respErr
!=
nil
{
return
fmt
.
Errorf
(
"%s"
,
respErr
.
Error
.
Message
),
&
respErr
.
Erro
r
return
fmt
.
Errorf
(
"%s"
,
respErr
.
Error
.
Message
),
respEr
r
}
if
usage
==
nil
{
return
errors
.
New
(
"usage is nil"
),
nil
...
...
@@ -222,7 +221,7 @@ func testAllChannels(notify bool) error {
for
_
,
channel
:=
range
channels
{
isChannelEnabled
:=
channel
.
Status
==
common
.
ChannelStatusEnabled
tik
:=
time
.
Now
()
err
,
openaiErr
:=
testChannel
(
channel
,
""
)
err
,
openai
WithStatus
Err
:=
testChannel
(
channel
,
""
)
tok
:=
time
.
Now
()
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
...
...
@@ -233,14 +232,10 @@ func testAllChannels(notify bool) error {
}
// request error disables the channel
if
openaiErr
!=
nil
{
err
=
errors
.
New
(
fmt
.
Sprintf
(
"type %s, code %v, message %s"
,
openaiErr
.
Type
,
openaiErr
.
Code
,
openaiErr
.
Message
))
openAiErrWithStatus
:=
dto
.
OpenAIErrorWithStatusCode
{
StatusCode
:
-
1
,
Error
:
*
openaiErr
,
LocalError
:
false
,
}
ban
=
service
.
ShouldDisableChannel
(
channel
.
Type
,
&
openAiErrWithStatus
)
if
openaiWithStatusErr
!=
nil
{
oaiErr
:=
openaiWithStatusErr
.
Error
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
)
}
// parse *int to bool
...
...
@@ -254,7 +249,7 @@ func testAllChannels(notify bool) error {
}
// enable channel
if
!
isChannelEnabled
&&
service
.
ShouldEnableChannel
(
err
,
openaiErr
,
channel
.
Status
)
{
if
!
isChannelEnabled
&&
service
.
ShouldEnableChannel
(
err
,
openai
WithStatus
Err
,
channel
.
Status
)
{
service
.
EnableChannel
(
channel
.
Id
,
channel
.
Name
)
}
...
...
service/channel.go
View file @
8baaa7e9
...
...
@@ -74,14 +74,14 @@ func ShouldDisableChannel(channelType int, err *relaymodel.OpenAIErrorWithStatus
return
false
}
func
ShouldEnableChannel
(
err
error
,
open
AIErr
*
relaymodel
.
OpenAIError
,
status
int
)
bool
{
func
ShouldEnableChannel
(
err
error
,
open
aiWithStatusErr
*
relaymodel
.
OpenAIErrorWithStatusCode
,
status
int
)
bool
{
if
!
common
.
AutomaticEnableChannelEnabled
{
return
false
}
if
err
!=
nil
{
return
false
}
if
open
AI
Err
!=
nil
{
if
open
aiWithStatus
Err
!=
nil
{
return
false
}
if
status
!=
common
.
ChannelStatusAutoDisabled
{
...
...
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