feat: enhance group ratio handling in pricing calculations

This commit is contained in:
CaIon
2025-06-17 21:05:35 +08:00
parent 3c276d13c4
commit 0f35d2368f
8 changed files with 76 additions and 106 deletions

View File

@@ -3,7 +3,6 @@ package model
import (
"errors"
"fmt"
"log"
"math/rand"
"one-api/common"
"one-api/setting"
@@ -88,14 +87,18 @@ func CacheGetRandomSatisfiedChannel(c *gin.Context, group string, model string,
return nil, selectGroup, errors.New("auto groups is not enabled")
}
for _, autoGroup := range setting.AutoGroups {
log.Printf("autoGroup: %s", autoGroup)
if common.DebugEnabled {
println("autoGroup:", autoGroup)
}
channel, _ = getRandomSatisfiedChannel(autoGroup, model, retry)
if channel == nil {
continue
} else {
c.Set("auto_group", autoGroup)
selectGroup = autoGroup
log.Printf("selectGroup: %s", selectGroup)
if common.DebugEnabled {
println("selectGroup:", selectGroup)
}
break
}
}

View File

@@ -194,7 +194,7 @@ func updateOptionMap(key string, value string) (err error) {
common.ImageDownloadPermission = intValue
}
}
if strings.HasSuffix(key, "Enabled") || key == "DefaultCollapseSidebar" {
if strings.HasSuffix(key, "Enabled") || key == "DefaultCollapseSidebar" || key == "DefaultUseAutoGroup" {
boolValue := value == "true"
switch key {
case "PasswordRegisterEnabled":
@@ -263,6 +263,8 @@ func updateOptionMap(key string, value string) (err error) {
common.SMTPSSLEnabled = boolValue
case "WorkerAllowHttpImageRequestEnabled":
setting.WorkerAllowHttpImageRequestEnabled = boolValue
case "DefaultUseAutoGroup":
setting.DefaultUseAutoGroup = boolValue
}
}
switch key {
@@ -291,8 +293,6 @@ func updateOptionMap(key string, value string) (err error) {
err = setting.UpdateChatsByJsonString(value)
case "AutoGroups":
err = setting.UpdateAutoGroupsByJsonString(value)
case "DefaultUseAutoGroup":
setting.DefaultUseAutoGroup = value == "true"
case "CustomCallbackAddress":
setting.CustomCallbackAddress = value
case "EpayId":