feat: Modellimitgroup check
This commit is contained in:
@@ -110,6 +110,15 @@ func UpdateOption(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
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)
|
err = model.UpdateOption(option.Key, option.Value)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package setting
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@@ -46,3 +47,18 @@ func GetGroupRateLimit(group string) (totalCount, successCount int, found bool)
|
|||||||
}
|
}
|
||||||
return limits[0], limits[1], true
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user