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
d6d4623f
authored
Dec 07, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消费日志添加用户调用前余额
parent
8061becf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
16 deletions
+17
-16
controller/relay-audio.go
+1
-1
controller/relay-image.go
+1
-1
controller/relay-mj.go
+1
-1
controller/relay-text.go
+1
-1
model/log.go
+2
-2
model/token.go
+11
-10
No files found.
controller/relay-audio.go
View file @
d6d4623f
...
...
@@ -162,7 +162,7 @@ func relayAudioHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
if
quota
!=
0
{
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型倍率 %.2f,分组倍率 %.2f"
,
modelRatio
,
groupRatio
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
promptTokens
,
0
,
audioRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
promptTokens
,
0
,
audioRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
,
userQuota
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
...
...
controller/relay-image.go
View file @
d6d4623f
...
...
@@ -169,7 +169,7 @@ func relayImageHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
if
quota
!=
0
{
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型倍率 %.2f,分组倍率 %.2f"
,
modelRatio
,
groupRatio
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
0
,
0
,
imageRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
0
,
0
,
imageRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
,
userQuota
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
...
...
controller/relay-mj.go
View file @
d6d4623f
...
...
@@ -370,7 +370,7 @@ func relayMidjourneySubmit(c *gin.Context, relayMode int) *MidjourneyResponse {
if
quota
!=
0
{
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型倍率 %.2f,分组倍率 %.2f"
,
modelRatio
,
groupRatio
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
0
,
0
,
imageModel
,
tokenName
,
quota
,
logContent
,
tokenId
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
0
,
0
,
imageModel
,
tokenName
,
quota
,
logContent
,
tokenId
,
userQuota
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
...
...
controller/relay-text.go
View file @
d6d4623f
...
...
@@ -446,7 +446,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
// record all the consume log even if quota is 0
useTimeSeconds
:=
time
.
Now
()
.
Unix
()
-
startTime
.
Unix
()
logContent
:=
fmt
.
Sprintf
(
"模型倍率 %.2f,分组倍率 %.2f,用时 %d秒"
,
modelRatio
,
groupRatio
,
useTimeSeconds
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
promptTokens
,
completionTokens
,
textRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
)
model
.
RecordConsumeLog
(
ctx
,
userId
,
channelId
,
promptTokens
,
completionTokens
,
textRequest
.
Model
,
tokenName
,
quota
,
logContent
,
tokenId
,
userQuota
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
//if quota != 0 {
...
...
model/log.go
View file @
d6d4623f
...
...
@@ -54,8 +54,8 @@ func RecordLog(userId int, logType int, content string) {
}
}
func
RecordConsumeLog
(
ctx
context
.
Context
,
userId
int
,
channelId
int
,
promptTokens
int
,
completionTokens
int
,
modelName
string
,
tokenName
string
,
quota
int
,
content
string
,
tokenId
int
)
{
common
.
LogInfo
(
ctx
,
fmt
.
Sprintf
(
"record consume log: userId=%d,
channelId=%d, promptTokens=%d, completionTokens=%d, modelName=%s, tokenName=%s, quota=%d, content=%s"
,
userId
,
channelId
,
promptTokens
,
completionTokens
,
modelName
,
tokenName
,
quota
,
content
))
func
RecordConsumeLog
(
ctx
context
.
Context
,
userId
int
,
channelId
int
,
promptTokens
int
,
completionTokens
int
,
modelName
string
,
tokenName
string
,
quota
int
,
content
string
,
tokenId
int
,
userQuota
int
)
{
common
.
LogInfo
(
ctx
,
fmt
.
Sprintf
(
"record consume log: userId=%d,
用户调用前余额=%d, channelId=%d, promptTokens=%d, completionTokens=%d, modelName=%s, tokenName=%s, quota=%d, content=%s"
,
userId
,
userQuota
,
channelId
,
promptTokens
,
completionTokens
,
modelName
,
tokenName
,
quota
,
content
))
if
!
common
.
LogConsumeEnabled
{
return
}
...
...
model/token.go
View file @
d6d4623f
...
...
@@ -219,6 +219,17 @@ func PostConsumeTokenQuota(tokenId int, userQuota int, quota int, preConsumedQuo
return
err
}
if
!
token
.
UnlimitedQuota
{
if
quota
>
0
{
err
=
DecreaseTokenQuota
(
tokenId
,
quota
)
}
else
{
err
=
IncreaseTokenQuota
(
tokenId
,
-
quota
)
}
if
err
!=
nil
{
return
err
}
}
if
sendEmail
{
if
(
quota
+
preConsumedQuota
)
!=
0
{
quotaTooLow
:=
userQuota
>=
common
.
QuotaRemindThreshold
&&
userQuota
-
(
quota
+
preConsumedQuota
)
<
common
.
QuotaRemindThreshold
...
...
@@ -247,15 +258,5 @@ func PostConsumeTokenQuota(tokenId int, userQuota int, quota int, preConsumedQuo
}
}
if
!
token
.
UnlimitedQuota
{
if
quota
>
0
{
err
=
DecreaseTokenQuota
(
tokenId
,
quota
)
}
else
{
err
=
IncreaseTokenQuota
(
tokenId
,
-
quota
)
}
if
err
!=
nil
{
return
err
}
}
return
nil
}
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