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
efb7c6a1
authored
Jul 29, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: auto ban
parent
a1caf37f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
7 deletions
+6
-7
controller/channel-test.go
+5
-5
service/error.go
+1
-2
No files found.
controller/channel-test.go
View file @
efb7c6a1
...
@@ -209,7 +209,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
...
@@ -209,7 +209,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
return
testResult
{
return
testResult
{
context
:
c
,
context
:
c
,
localErr
:
err
,
localErr
:
err
,
newAPIError
:
types
.
New
Error
(
err
,
types
.
ErrorCodeDoRequestFailed
),
newAPIError
:
types
.
New
OpenAIError
(
err
,
types
.
ErrorCodeDoRequestFailed
,
http
.
StatusInternalServerError
),
}
}
}
}
var
httpResp
*
http
.
Response
var
httpResp
*
http
.
Response
...
@@ -220,7 +220,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
...
@@ -220,7 +220,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
return
testResult
{
return
testResult
{
context
:
c
,
context
:
c
,
localErr
:
err
,
localErr
:
err
,
newAPIError
:
types
.
New
Error
(
err
,
types
.
ErrorCodeBadResponse
),
newAPIError
:
types
.
New
OpenAIError
(
err
,
types
.
ErrorCodeBadResponse
,
http
.
StatusInternalServerError
),
}
}
}
}
}
}
...
@@ -236,7 +236,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
...
@@ -236,7 +236,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
return
testResult
{
return
testResult
{
context
:
c
,
context
:
c
,
localErr
:
errors
.
New
(
"usage is nil"
),
localErr
:
errors
.
New
(
"usage is nil"
),
newAPIError
:
types
.
New
Error
(
errors
.
New
(
"usage is nil"
),
types
.
ErrorCodeBadResponseBody
),
newAPIError
:
types
.
New
OpenAIError
(
errors
.
New
(
"usage is nil"
),
types
.
ErrorCodeBadResponseBody
,
http
.
StatusInternalServerError
),
}
}
}
}
usage
:=
usageA
.
(
*
dto
.
Usage
)
usage
:=
usageA
.
(
*
dto
.
Usage
)
...
@@ -246,7 +246,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
...
@@ -246,7 +246,7 @@ func testChannel(channel *model.Channel, testModel string) testResult {
return
testResult
{
return
testResult
{
context
:
c
,
context
:
c
,
localErr
:
err
,
localErr
:
err
,
newAPIError
:
types
.
New
Error
(
err
,
types
.
ErrorCodeReadResponseBodyFailed
),
newAPIError
:
types
.
New
OpenAIError
(
err
,
types
.
ErrorCodeReadResponseBodyFailed
,
http
.
StatusInternalServerError
),
}
}
}
}
info
.
PromptTokens
=
usage
.
PromptTokens
info
.
PromptTokens
=
usage
.
PromptTokens
...
@@ -417,7 +417,7 @@ func testAllChannels(notify bool) error {
...
@@ -417,7 +417,7 @@ func testAllChannels(notify bool) error {
if
common
.
AutomaticDisableChannelEnabled
&&
!
shouldBanChannel
{
if
common
.
AutomaticDisableChannelEnabled
&&
!
shouldBanChannel
{
if
milliseconds
>
disableThreshold
{
if
milliseconds
>
disableThreshold
{
err
:=
errors
.
New
(
fmt
.
Sprintf
(
"响应时间 %.2fs 超过阈值 %.2fs"
,
float64
(
milliseconds
)
/
1000.0
,
float64
(
disableThreshold
)
/
1000.0
))
err
:=
errors
.
New
(
fmt
.
Sprintf
(
"响应时间 %.2fs 超过阈值 %.2fs"
,
float64
(
milliseconds
)
/
1000.0
,
float64
(
disableThreshold
)
/
1000.0
))
newAPIError
=
types
.
New
Error
(
err
,
types
.
ErrorCodeChannelResponseTimeExceeded
)
newAPIError
=
types
.
New
OpenAIError
(
err
,
types
.
ErrorCodeChannelResponseTimeExceeded
,
http
.
StatusRequestTimeout
)
shouldBanChannel
=
true
shouldBanChannel
=
true
}
}
}
}
...
...
service/error.go
View file @
efb7c6a1
package
service
package
service
import
(
import
(
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
...
@@ -112,7 +111,7 @@ func ResetStatusCode(newApiErr *types.NewAPIError, statusCodeMappingStr string)
...
@@ -112,7 +111,7 @@ func ResetStatusCode(newApiErr *types.NewAPIError, statusCodeMappingStr string)
return
return
}
}
statusCodeMapping
:=
make
(
map
[
string
]
string
)
statusCodeMapping
:=
make
(
map
[
string
]
string
)
err
:=
js
on
.
Unmarshal
([]
byte
(
statusCodeMappingStr
),
&
statusCodeMapping
)
err
:=
comm
on
.
Unmarshal
([]
byte
(
statusCodeMappingStr
),
&
statusCodeMapping
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
...
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