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
a539b200
authored
Dec 05, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
预扣费增加用户余额检测
parent
4bd14684
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
3 deletions
+3
-3
controller/relay-text.go
+2
-2
controller/relay-utils.go
+1
-1
No files found.
controller/relay-text.go
View file @
a539b200
...
...
@@ -221,7 +221,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
if
err
!=
nil
{
return
errorWrapper
(
err
,
"get_user_quota_failed"
,
http
.
StatusInternalServerError
)
}
if
userQuota
-
preConsumedQuota
<
0
{
if
userQuota
<
0
||
userQuota
-
preConsumedQuota
<
0
{
return
errorWrapper
(
errors
.
New
(
"user quota is not enough"
),
"insufficient_user_quota"
,
http
.
StatusForbidden
)
}
err
=
model
.
CacheDecreaseUserQuota
(
userId
,
preConsumedQuota
)
...
...
@@ -232,7 +232,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
// in this case, we do not pre-consume quota
// because the user has enough quota
preConsumedQuota
=
0
//
common.LogInfo(c.Request.Context(), fmt.Sprintf("user %d has enough quota %d, trusted and no need to pre-consume", userId, userQuota))
common
.
LogInfo
(
c
.
Request
.
Context
(),
fmt
.
Sprintf
(
"user %d has enough quota %d, trusted and no need to pre-consume"
,
userId
,
userQuota
))
}
if
preConsumedQuota
>
0
{
userQuota
,
err
=
model
.
PreConsumeTokenQuota
(
tokenId
,
preConsumedQuota
)
...
...
controller/relay-utils.go
View file @
a539b200
...
...
@@ -233,7 +233,7 @@ func shouldDisableChannel(err *OpenAIError, statusCode int) bool {
if
statusCode
==
http
.
StatusUnauthorized
{
return
true
}
if
err
.
Type
==
"insufficient_quota"
||
err
.
Code
==
"invalid_api_key"
||
err
.
Code
==
"account_deactivated"
{
if
err
.
Type
==
"insufficient_quota"
||
err
.
Code
==
"invalid_api_key"
||
err
.
Code
==
"account_deactivated"
||
err
.
Code
==
"billing_not_active"
{
return
true
}
return
false
...
...
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