Skip to content

Commit

Permalink
perf: only return quota when it's not zero
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Sep 13, 2023
1 parent 01863d3 commit 420c375
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions controller/relay-text.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,15 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
isStream = isStream || strings.HasPrefix(resp.Header.Get("Content-Type"), "text/event-stream")

if resp.StatusCode != http.StatusOK {
go func() {
// return pre-consumed quota
err := model.PostConsumeTokenQuota(tokenId, -preConsumedQuota)
if err != nil {
common.SysError("error return pre-consumed quota: " + err.Error())
}
}()
if preConsumedQuota != 0 {
go func() {
// return pre-consumed quota
err := model.PostConsumeTokenQuota(tokenId, -preConsumedQuota)
if err != nil {
common.SysError("error return pre-consumed quota: " + err.Error())
}
}()
}
return relayErrorHandler(resp)
}
}
Expand Down

0 comments on commit 420c375

Please sign in to comment.