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
d72d8852
authored
Jan 11, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 完善令牌预扣费逻辑
parent
c8b3465a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
4 deletions
+4
-4
controller/relay-text.go
+3
-2
middleware/auth.go
+1
-2
No files found.
controller/relay-text.go
View file @
d72d8852
...
...
@@ -52,7 +52,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
tokenId
:=
c
.
GetInt
(
"token_id"
)
userId
:=
c
.
GetInt
(
"id"
)
group
:=
c
.
GetString
(
"group"
)
token
Quota
:=
c
.
GetInt
(
"token
_quota"
)
token
Unlimited
:=
c
.
GetBool
(
"token_unlimited
_quota"
)
startTime
:=
time
.
Now
()
var
textRequest
GeneralOpenAIRequest
...
...
@@ -263,8 +263,9 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
}
if
userQuota
>
100
*
preConsumedQuota
{
// 用户额度充足,判断令牌额度是否充足
if
tokenQuota
!=
-
1
{
if
!
tokenUnlimited
{
// 非无限令牌,判断令牌额度是否充足
tokenQuota
:=
c
.
GetInt
(
"token_quota"
)
if
tokenQuota
>
100
*
preConsumedQuota
{
// 令牌额度充足,信任令牌
preConsumedQuota
=
0
...
...
middleware/auth.go
View file @
d72d8852
...
...
@@ -115,10 +115,9 @@ func TokenAuth() func(c *gin.Context) {
c
.
Set
(
"id"
,
token
.
UserId
)
c
.
Set
(
"token_id"
,
token
.
Id
)
c
.
Set
(
"token_name"
,
token
.
Name
)
c
.
Set
(
"token_unlimited_quota"
,
token
.
UnlimitedQuota
)
if
!
token
.
UnlimitedQuota
{
c
.
Set
(
"token_quota"
,
token
.
RemainQuota
)
}
else
{
c
.
Set
(
"token_quota"
,
-
1
)
}
if
token
.
ModelLimitsEnabled
{
c
.
Set
(
"token_model_limit_enabled"
,
true
)
...
...
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