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
b9099b85
authored
Jul 31, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: error channel name on notify. #338
parent
f46fc4e3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
7 deletions
+7
-7
controller/relay.go
+5
-5
model/channel.go
+2
-2
No files found.
controller/relay.go
View file @
b9099b85
...
...
@@ -43,12 +43,13 @@ func Relay(c *gin.Context) {
requestId
:=
c
.
GetString
(
common
.
RequestIdKey
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
channelType
:=
c
.
GetInt
(
"channel_type"
)
channelName
:=
c
.
GetString
(
"channel_name"
)
group
:=
c
.
GetString
(
"group"
)
originalModel
:=
c
.
GetString
(
"original_model"
)
openaiErr
:=
relayHandler
(
c
,
relayMode
)
c
.
Set
(
"use_channel"
,
[]
string
{
fmt
.
Sprintf
(
"%d"
,
channelId
)})
if
openaiErr
!=
nil
{
go
processChannelError
(
c
,
channelId
,
channelType
,
openaiErr
)
go
processChannelError
(
c
,
channelId
,
channelType
,
channelName
,
openaiErr
)
}
else
{
retryTimes
=
0
}
...
...
@@ -60,7 +61,7 @@ func Relay(c *gin.Context) {
}
channelId
=
channel
.
Id
useChannel
:=
c
.
GetStringSlice
(
"use_channel"
)
useChannel
=
append
(
useChannel
,
fmt
.
Sprintf
(
"%d"
,
channelId
))
useChannel
=
append
(
useChannel
,
fmt
.
Sprintf
(
"%d"
,
channel
.
Id
))
c
.
Set
(
"use_channel"
,
useChannel
)
common
.
LogInfo
(
c
.
Request
.
Context
(),
fmt
.
Sprintf
(
"using channel #%d to retry (remain times %d)"
,
channel
.
Id
,
i
))
middleware
.
SetupContextForSelectedChannel
(
c
,
channel
,
originalModel
)
...
...
@@ -69,7 +70,7 @@ func Relay(c *gin.Context) {
c
.
Request
.
Body
=
io
.
NopCloser
(
bytes
.
NewBuffer
(
requestBody
))
openaiErr
=
relayHandler
(
c
,
relayMode
)
if
openaiErr
!=
nil
{
go
processChannelError
(
c
,
channel
Id
,
channel
.
Typ
e
,
openaiErr
)
go
processChannelError
(
c
,
channel
.
Id
,
channel
.
Type
,
channel
.
Nam
e
,
openaiErr
)
}
}
useChannel
:=
c
.
GetStringSlice
(
"use_channel"
)
...
...
@@ -128,11 +129,10 @@ func shouldRetry(c *gin.Context, channelId int, openaiErr *dto.OpenAIErrorWithSt
return
true
}
func
processChannelError
(
c
*
gin
.
Context
,
channelId
int
,
channelType
int
,
err
*
dto
.
OpenAIErrorWithStatusCode
)
{
func
processChannelError
(
c
*
gin
.
Context
,
channelId
int
,
channelType
int
,
channelName
string
,
err
*
dto
.
OpenAIErrorWithStatusCode
)
{
autoBan
:=
c
.
GetBool
(
"auto_ban"
)
common
.
LogError
(
c
.
Request
.
Context
(),
fmt
.
Sprintf
(
"relay error (channel #%d, status code: %d): %s"
,
channelId
,
err
.
StatusCode
,
err
.
Error
.
Message
))
if
service
.
ShouldDisableChannel
(
channelType
,
err
)
&&
autoBan
{
channelName
:=
c
.
GetString
(
"channel_name"
)
service
.
DisableChannel
(
channelId
,
channelName
,
err
.
Error
.
Message
)
}
}
...
...
model/channel.go
View file @
b9099b85
...
...
@@ -100,8 +100,8 @@ func SearchChannels(keyword string, group string, model string) ([]*Channel, err
var
whereClause
string
var
args
[]
interface
{}
if
group
!=
""
{
whereClause
=
"(id = ? OR name LIKE ? OR "
+
keyCol
+
" = ?) AND "
+
groupCol
+
"
LIKE
? AND "
+
modelsCol
+
" LIKE ?"
args
=
append
(
args
,
common
.
String2Int
(
keyword
),
"%"
+
keyword
+
"%"
,
keyword
,
"%"
+
group
+
"%"
,
"%"
+
model
+
"%"
)
whereClause
=
"(id = ? OR name LIKE ? OR "
+
keyCol
+
" = ?) AND "
+
groupCol
+
"
=
? AND "
+
modelsCol
+
" LIKE ?"
args
=
append
(
args
,
common
.
String2Int
(
keyword
),
"%"
+
keyword
+
"%"
,
keyword
,
group
,
"%"
+
model
+
"%"
)
}
else
{
whereClause
=
"(id = ? OR name LIKE ? OR "
+
keyCol
+
" = ?) AND "
+
modelsCol
+
" LIKE ?"
args
=
append
(
args
,
common
.
String2Int
(
keyword
),
"%"
+
keyword
+
"%"
,
keyword
,
"%"
+
model
+
"%"
)
...
...
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