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
1b03512e
authored
Jul 14, 2024
by
Calcium-Ion
Committed by
GitHub
Jul 14, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #363 from dalefengs/main
fix: http code is not properly disabled channel
parents
6e72e4a5
8baaa7e9
Show 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 @
1b03512e
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
"github.com/gin-gonic/gin"
"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
()
tik
:=
time
.
Now
()
if
channel
.
Type
==
common
.
ChannelTypeMidjourney
{
if
channel
.
Type
==
common
.
ChannelTypeMidjourney
{
return
errors
.
New
(
"midjourney channel test is not supported"
),
nil
return
errors
.
New
(
"midjourney channel test is not supported"
),
nil
...
@@ -58,8 +58,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
...
@@ -58,8 +58,7 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
modelMap
:=
make
(
map
[
string
]
string
)
modelMap
:=
make
(
map
[
string
]
string
)
err
:=
json
.
Unmarshal
([]
byte
(
modelMapping
),
&
modelMap
)
err
:=
json
.
Unmarshal
([]
byte
(
modelMapping
),
&
modelMap
)
if
err
!=
nil
{
if
err
!=
nil
{
openaiErr
:=
service
.
OpenAIErrorWrapperLocal
(
err
,
"unmarshal_model_mapping_failed"
,
http
.
StatusInternalServerError
)
.
Error
return
err
,
service
.
OpenAIErrorWrapperLocal
(
err
,
"unmarshal_model_mapping_failed"
,
http
.
StatusInternalServerError
)
return
err
,
&
openaiErr
}
}
if
modelMap
[
testModel
]
!=
""
{
if
modelMap
[
testModel
]
!=
""
{
testModel
=
modelMap
[
testModel
]
testModel
=
modelMap
[
testModel
]
...
@@ -104,11 +103,11 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
...
@@ -104,11 +103,11 @@ func testChannel(channel *model.Channel, testModel string) (err error, openaiErr
}
}
if
resp
!=
nil
&&
resp
.
StatusCode
!=
http
.
StatusOK
{
if
resp
!=
nil
&&
resp
.
StatusCode
!=
http
.
StatusOK
{
err
:=
relaycommon
.
RelayErrorHandler
(
resp
)
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
)
usage
,
respErr
:=
adaptor
.
DoResponse
(
c
,
resp
,
meta
)
if
respErr
!=
nil
{
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
{
if
usage
==
nil
{
return
errors
.
New
(
"usage is nil"
),
nil
return
errors
.
New
(
"usage is nil"
),
nil
...
@@ -222,7 +221,7 @@ func testAllChannels(notify bool) error {
...
@@ -222,7 +221,7 @@ func testAllChannels(notify bool) error {
for
_
,
channel
:=
range
channels
{
for
_
,
channel
:=
range
channels
{
isChannelEnabled
:=
channel
.
Status
==
common
.
ChannelStatusEnabled
isChannelEnabled
:=
channel
.
Status
==
common
.
ChannelStatusEnabled
tik
:=
time
.
Now
()
tik
:=
time
.
Now
()
err
,
openaiErr
:=
testChannel
(
channel
,
""
)
err
,
openai
WithStatus
Err
:=
testChannel
(
channel
,
""
)
tok
:=
time
.
Now
()
tok
:=
time
.
Now
()
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
milliseconds
:=
tok
.
Sub
(
tik
)
.
Milliseconds
()
...
@@ -233,14 +232,10 @@ func testAllChannels(notify bool) error {
...
@@ -233,14 +232,10 @@ func testAllChannels(notify bool) error {
}
}
// request error disables the channel
// request error disables the channel
if
openaiErr
!=
nil
{
if
openaiWithStatusErr
!=
nil
{
err
=
errors
.
New
(
fmt
.
Sprintf
(
"type %s, code %v, message %s"
,
openaiErr
.
Type
,
openaiErr
.
Code
,
openaiErr
.
Message
))
oaiErr
:=
openaiWithStatusErr
.
Error
openAiErrWithStatus
:=
dto
.
OpenAIErrorWithStatusCode
{
err
=
errors
.
New
(
fmt
.
Sprintf
(
"type %s, httpCode %d, code %v, message %s"
,
oaiErr
.
Type
,
openaiWithStatusErr
.
StatusCode
,
oaiErr
.
Code
,
oaiErr
.
Message
))
StatusCode
:
-
1
,
ban
=
service
.
ShouldDisableChannel
(
channel
.
Type
,
openaiWithStatusErr
)
Error
:
*
openaiErr
,
LocalError
:
false
,
}
ban
=
service
.
ShouldDisableChannel
(
channel
.
Type
,
&
openAiErrWithStatus
)
}
}
// parse *int to bool
// parse *int to bool
...
@@ -254,7 +249,7 @@ func testAllChannels(notify bool) error {
...
@@ -254,7 +249,7 @@ func testAllChannels(notify bool) error {
}
}
// enable channel
// 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
.
EnableChannel
(
channel
.
Id
,
channel
.
Name
)
}
}
...
...
service/channel.go
View file @
1b03512e
...
@@ -74,14 +74,14 @@ func ShouldDisableChannel(channelType int, err *relaymodel.OpenAIErrorWithStatus
...
@@ -74,14 +74,14 @@ func ShouldDisableChannel(channelType int, err *relaymodel.OpenAIErrorWithStatus
return
false
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
{
if
!
common
.
AutomaticEnableChannelEnabled
{
return
false
return
false
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
}
}
if
open
AI
Err
!=
nil
{
if
open
aiWithStatus
Err
!=
nil
{
return
false
return
false
}
}
if
status
!=
common
.
ChannelStatusAutoDisabled
{
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