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
a127461b
authored
May 16, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 日志显示重试信息
parent
9df64bca
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
2 deletions
+50
-2
common/utils.go
+9
-0
controller/relay.go
+5
-2
model/log.go
+9
-0
relay/relay-text.go
+3
-0
web/src/components/LogsTable.js
+24
-0
No files found.
common/utils.go
View file @
a127461b
...
@@ -258,3 +258,12 @@ func MapToJsonStrFloat(m map[string]float64) string {
...
@@ -258,3 +258,12 @@ func MapToJsonStrFloat(m map[string]float64) string {
}
}
return
string
(
bytes
)
return
string
(
bytes
)
}
}
func
StrToMap
(
str
string
)
map
[
string
]
interface
{}
{
m
:=
make
(
map
[
string
]
interface
{})
err
:=
json
.
Unmarshal
([]
byte
(
str
),
&
m
)
if
err
!=
nil
{
return
nil
}
return
m
}
controller/relay.go
View file @
a127461b
...
@@ -43,7 +43,7 @@ func Relay(c *gin.Context) {
...
@@ -43,7 +43,7 @@ func Relay(c *gin.Context) {
group
:=
c
.
GetString
(
"group"
)
group
:=
c
.
GetString
(
"group"
)
originalModel
:=
c
.
GetString
(
"original_model"
)
originalModel
:=
c
.
GetString
(
"original_model"
)
openaiErr
:=
relayHandler
(
c
,
relayMode
)
openaiErr
:=
relayHandler
(
c
,
relayMode
)
useChannel
:=
[]
int
{
channelId
}
c
.
Set
(
"use_channel"
,
[]
string
{
fmt
.
Sprintf
(
"%d"
,
channelId
)})
if
openaiErr
!=
nil
{
if
openaiErr
!=
nil
{
go
processChannelError
(
c
,
channelId
,
openaiErr
)
go
processChannelError
(
c
,
channelId
,
openaiErr
)
}
else
{
}
else
{
...
@@ -56,7 +56,9 @@ func Relay(c *gin.Context) {
...
@@ -56,7 +56,9 @@ func Relay(c *gin.Context) {
break
break
}
}
channelId
=
channel
.
Id
channelId
=
channel
.
Id
useChannel
=
append
(
useChannel
,
channelId
)
useChannel
:=
c
.
GetStringSlice
(
"use_channel"
)
useChannel
=
append
(
useChannel
,
fmt
.
Sprintf
(
"%d"
,
channelId
))
c
.
Set
(
"use_channel"
,
useChannel
)
common
.
LogInfo
(
c
.
Request
.
Context
(),
fmt
.
Sprintf
(
"using channel #%d to retry (remain times %d)"
,
channel
.
Id
,
i
))
common
.
LogInfo
(
c
.
Request
.
Context
(),
fmt
.
Sprintf
(
"using channel #%d to retry (remain times %d)"
,
channel
.
Id
,
i
))
middleware
.
SetupContextForSelectedChannel
(
c
,
channel
,
originalModel
)
middleware
.
SetupContextForSelectedChannel
(
c
,
channel
,
originalModel
)
...
@@ -67,6 +69,7 @@ func Relay(c *gin.Context) {
...
@@ -67,6 +69,7 @@ func Relay(c *gin.Context) {
go
processChannelError
(
c
,
channelId
,
openaiErr
)
go
processChannelError
(
c
,
channelId
,
openaiErr
)
}
}
}
}
useChannel
:=
c
.
GetStringSlice
(
"use_channel"
)
if
len
(
useChannel
)
>
1
{
if
len
(
useChannel
)
>
1
{
retryLogStr
:=
fmt
.
Sprintf
(
"重试:%s"
,
strings
.
Trim
(
strings
.
Join
(
strings
.
Fields
(
fmt
.
Sprint
(
useChannel
)),
"->"
),
"[]"
))
retryLogStr
:=
fmt
.
Sprintf
(
"重试:%s"
,
strings
.
Trim
(
strings
.
Join
(
strings
.
Fields
(
fmt
.
Sprint
(
useChannel
)),
"->"
),
"[]"
))
common
.
LogInfo
(
c
.
Request
.
Context
(),
retryLogStr
)
common
.
LogInfo
(
c
.
Request
.
Context
(),
retryLogStr
)
...
...
model/log.go
View file @
a127461b
...
@@ -142,6 +142,15 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
...
@@ -142,6 +142,15 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
tx
=
tx
.
Where
(
"created_at <= ?"
,
endTimestamp
)
tx
=
tx
.
Where
(
"created_at <= ?"
,
endTimestamp
)
}
}
err
=
tx
.
Order
(
"id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Omit
(
"id"
)
.
Find
(
&
logs
)
.
Error
err
=
tx
.
Order
(
"id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Omit
(
"id"
)
.
Find
(
&
logs
)
.
Error
for
i
:=
range
logs
{
var
otherMap
map
[
string
]
interface
{}
otherMap
=
common
.
StrToMap
(
logs
[
i
]
.
Other
)
if
otherMap
!=
nil
{
// delete admin
delete
(
otherMap
,
"admin_info"
)
}
logs
[
i
]
.
Other
=
common
.
MapToJsonStr
(
otherMap
)
}
return
logs
,
err
return
logs
,
err
}
}
...
...
relay/relay-text.go
View file @
a127461b
...
@@ -320,6 +320,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, textRe
...
@@ -320,6 +320,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, textRe
other
[
"group_ratio"
]
=
groupRatio
other
[
"group_ratio"
]
=
groupRatio
other
[
"completion_ratio"
]
=
completionRatio
other
[
"completion_ratio"
]
=
completionRatio
other
[
"model_price"
]
=
modelPrice
other
[
"model_price"
]
=
modelPrice
adminInfo
:=
make
(
map
[
string
]
interface
{})
adminInfo
[
"use_channel"
]
=
ctx
.
GetStringSlice
(
"use_channel"
)
other
[
"admin_info"
]
=
adminInfo
model
.
RecordConsumeLog
(
ctx
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
promptTokens
,
completionTokens
,
logModel
,
tokenName
,
quota
,
logContent
,
relayInfo
.
TokenId
,
userQuota
,
int
(
useTimeSeconds
),
relayInfo
.
IsStream
,
other
)
model
.
RecordConsumeLog
(
ctx
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
promptTokens
,
completionTokens
,
logModel
,
tokenName
,
quota
,
logContent
,
relayInfo
.
TokenId
,
userQuota
,
int
(
useTimeSeconds
),
relayInfo
.
IsStream
,
other
)
//if quota != 0 {
//if quota != 0 {
...
...
web/src/components/LogsTable.js
View file @
a127461b
...
@@ -295,6 +295,30 @@ const LogsTable = () => {
...
@@ -295,6 +295,30 @@ const LogsTable = () => {
},
},
},
},
{
{
title
:
'重试'
,
dataIndex
:
'retry'
,
className
:
isAdmin
()
?
'tableShow'
:
'tableHiddle'
,
render
:
(
text
,
record
,
index
)
=>
{
let
content
=
'渠道:'
+
record
.
channel
;
if
(
record
.
other
!==
''
)
{
let
other
=
JSON
.
parse
(
record
.
other
);
if
(
other
.
admin_info
!==
undefined
)
{
if
(
other
.
admin_info
.
use_channel
!==
null
&&
other
.
admin_info
.
use_channel
!==
undefined
&&
other
.
admin_info
.
use_channel
!==
''
)
{
// channel id array
let
useChannel
=
other
.
admin_info
.
use_channel
;
let
useChannelStr
=
useChannel
.
join
(
'->'
);
content
=
`渠道:
${
useChannelStr
}
`
;
}
}
}
return
isAdminUser
?
<
div
>
{
content
}
<
/div> : <></
>
;
},
},
{
title
:
'详情'
,
title
:
'详情'
,
dataIndex
:
'content'
,
dataIndex
:
'content'
,
render
:
(
text
,
record
,
index
)
=>
{
render
:
(
text
,
record
,
index
)
=>
{
...
...
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