mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 11:48:38 +00:00
fix(channel_select): adjust priority retry logic for cross-group channel selection
This commit is contained in:
@@ -22,23 +22,26 @@ func CacheGetRandomSatisfiedChannel(c *gin.Context, tokenGroup string, modelName
|
|||||||
return nil, selectGroup, errors.New("auto groups is not enabled")
|
return nil, selectGroup, errors.New("auto groups is not enabled")
|
||||||
}
|
}
|
||||||
autoGroups := GetUserAutoGroup(userGroup)
|
autoGroups := GetUserAutoGroup(userGroup)
|
||||||
// 如果 token 启用了跨分组重试,获取上次失败的 auto group 索引,从下一个开始尝试
|
|
||||||
startIndex := 0
|
startIndex := 0
|
||||||
|
priorityRetry := retry
|
||||||
crossGroupRetry := common.GetContextKeyBool(c, constant.ContextKeyTokenCrossGroupRetry)
|
crossGroupRetry := common.GetContextKeyBool(c, constant.ContextKeyTokenCrossGroupRetry)
|
||||||
if crossGroupRetry && retry > 0 {
|
if crossGroupRetry && retry > 0 {
|
||||||
logger.LogDebug(c, "Auto group retry cross group, retry: %d", retry)
|
logger.LogDebug(c, "Auto group retry cross group, retry: %d", retry)
|
||||||
if lastIndex, exists := common.GetContextKey(c, constant.ContextKeyAutoGroupIndex); exists {
|
if lastIndex, exists := common.GetContextKey(c, constant.ContextKeyAutoGroupIndex); exists {
|
||||||
if idx, ok := lastIndex.(int); ok {
|
if idx, ok := lastIndex.(int); ok {
|
||||||
startIndex = idx + 1
|
startIndex = idx + 1
|
||||||
|
priorityRetry = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.LogDebug(c, "Auto group retry cross group, start index: %d", startIndex)
|
logger.LogDebug(c, "Auto group retry cross group, start index: %d", startIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := startIndex; i < len(autoGroups); i++ {
|
for i := startIndex; i < len(autoGroups); i++ {
|
||||||
autoGroup := autoGroups[i]
|
autoGroup := autoGroups[i]
|
||||||
logger.LogDebug(c, "Auto selecting group: %s", autoGroup)
|
logger.LogDebug(c, "Auto selecting group: %s", autoGroup)
|
||||||
channel, _ = model.GetRandomSatisfiedChannel(autoGroup, modelName, 0)
|
channel, _ = model.GetRandomSatisfiedChannel(autoGroup, modelName, priorityRetry)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
|
priorityRetry = 0
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
c.Set("auto_group", autoGroup)
|
c.Set("auto_group", autoGroup)
|
||||||
|
|||||||
Reference in New Issue
Block a user