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
995b3147
authored
Aug 12, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: use a goroutine to handle quota post consumption (#364)
parent
c563e1ed
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
controller/relay-text.go
+6
-3
No files found.
controller/relay-text.go
View file @
995b3147
...
@@ -305,9 +305,12 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
...
@@ -305,9 +305,12 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
}
}
var
textResponse
TextResponse
var
textResponse
TextResponse
tokenName
:=
c
.
GetString
(
"token_name"
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
defer
func
()
{
defer
func
()
{
c
.
Writer
.
Flush
()
// c.Writer.Flush()
go
func
()
{
if
consumeQuota
{
if
consumeQuota
{
quota
:=
0
quota
:=
0
completionRatio
:=
1.0
completionRatio
:=
1.0
...
@@ -342,15 +345,15 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
...
@@ -342,15 +345,15 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
common
.
SysError
(
"error update user quota cache: "
+
err
.
Error
())
common
.
SysError
(
"error update user quota cache: "
+
err
.
Error
())
}
}
if
quota
!=
0
{
if
quota
!=
0
{
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型倍率 %.2f,分组倍率 %.2f"
,
modelRatio
,
groupRatio
)
logContent
:=
fmt
.
Sprintf
(
"模型倍率 %.2f,分组倍率 %.2f"
,
modelRatio
,
groupRatio
)
model
.
RecordConsumeLog
(
userId
,
promptTokens
,
completionTokens
,
textRequest
.
Model
,
tokenName
,
quota
,
logContent
)
model
.
RecordConsumeLog
(
userId
,
promptTokens
,
completionTokens
,
textRequest
.
Model
,
tokenName
,
quota
,
logContent
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
userId
,
quota
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
model
.
UpdateChannelUsedQuota
(
channelId
,
quota
)
}
}
}
}
}()
}()
}()
switch
apiType
{
switch
apiType
{
case
APITypeOpenAI
:
case
APITypeOpenAI
:
if
isStream
{
if
isStream
{
...
...
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