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
2193d46b
authored
Aug 26, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: disable channel when 401 received (close #467)
parent
04bd77e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
3 deletions
+7
-3
controller/channel-test.go
+1
-1
controller/relay-utils.go
+5
-1
controller/relay.go
+1
-1
No files found.
controller/channel-test.go
View file @
2193d46b
...
...
@@ -174,7 +174,7 @@ func testAllChannels(notify bool) error {
err
=
errors
.
New
(
fmt
.
Sprintf
(
"响应时间 %.2fs 超过阈值 %.2fs"
,
float64
(
milliseconds
)
/
1000.0
,
float64
(
disableThreshold
)
/
1000.0
))
disableChannel
(
channel
.
Id
,
channel
.
Name
,
err
.
Error
())
}
if
shouldDisableChannel
(
openaiErr
)
{
if
shouldDisableChannel
(
openaiErr
,
-
1
)
{
disableChannel
(
channel
.
Id
,
channel
.
Name
,
err
.
Error
())
}
channel
.
UpdateResponseTime
(
milliseconds
)
...
...
controller/relay-utils.go
View file @
2193d46b
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/pkoukk/tiktoken-go"
"net/http"
"one-api/common"
)
...
...
@@ -95,13 +96,16 @@ func errorWrapper(err error, code string, statusCode int) *OpenAIErrorWithStatus
}
}
func
shouldDisableChannel
(
err
*
OpenAIError
)
bool
{
func
shouldDisableChannel
(
err
*
OpenAIError
,
statusCode
int
)
bool
{
if
!
common
.
AutomaticDisableChannelEnabled
{
return
false
}
if
err
==
nil
{
return
false
}
if
statusCode
==
http
.
StatusUnauthorized
{
return
true
}
if
err
.
Type
==
"insufficient_quota"
||
err
.
Code
==
"invalid_api_key"
||
err
.
Code
==
"account_deactivated"
{
return
true
}
...
...
controller/relay.go
View file @
2193d46b
...
...
@@ -185,7 +185,7 @@ func Relay(c *gin.Context) {
channelId
:=
c
.
GetInt
(
"channel_id"
)
common
.
SysError
(
fmt
.
Sprintf
(
"relay error (channel #%d): %s"
,
channelId
,
err
.
Message
))
// https://platform.openai.com/docs/guides/error-codes/api-errors
if
shouldDisableChannel
(
&
err
.
OpenAIError
)
{
if
shouldDisableChannel
(
&
err
.
OpenAIError
,
err
.
StatusCode
)
{
channelId
:=
c
.
GetInt
(
"channel_id"
)
channelName
:=
c
.
GetString
(
"channel_name"
)
disableChannel
(
channelId
,
channelName
,
err
.
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