feat: Modellimitgroup check

This commit is contained in:
tbphp
2025-05-05 20:00:06 +08:00
parent 1513ed7847
commit 88ed83f419
2 changed files with 25 additions and 0 deletions

View File

@@ -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)

View File

@@ -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
}