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
103cca01
authored
May 05, 2025
by
tbphp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Modellimitgroup check
parent
cd40bdbd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
controller/option.go
+9
-0
setting/rate_limit.go
+16
-0
No files found.
controller/option.go
View file @
103cca01
...
...
@@ -110,6 +110,15 @@ func UpdateOption(c *gin.Context) {
})
return
}
case
"ModelRequestRateLimitGroup"
:
err
=
setting
.
CheckModelRequestRateLimitGroup
(
option
.
Value
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
}
}
err
=
model
.
UpdateOption
(
option
.
Key
,
option
.
Value
)
...
...
setting/rate_limit.go
View file @
103cca01
...
...
@@ -2,6 +2,7 @@ package setting
import
(
"encoding/json"
"fmt"
"one-api/common"
"sync"
)
...
...
@@ -46,3 +47,18 @@ func GetGroupRateLimit(group string) (totalCount, successCount int, found bool)
}
return
limits
[
0
],
limits
[
1
],
true
}
func
CheckModelRequestRateLimitGroup
(
jsonStr
string
)
error
{
checkModelRequestRateLimitGroup
:=
make
(
map
[
string
][
2
]
int
)
err
:=
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
checkModelRequestRateLimitGroup
)
if
err
!=
nil
{
return
err
}
for
group
,
limits
:=
range
checkModelRequestRateLimitGroup
{
if
limits
[
0
]
<
0
||
limits
[
1
]
<
0
{
return
fmt
.
Errorf
(
"group %s has negative rate limit values: [%d, %d]"
,
group
,
limits
[
0
],
limits
[
1
])
}
}
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