Переглянути джерело

fix(pricing): 修复渠道定价优先级问题

当模型配置了渠道定价但全局定价未设置时,不再提前报错。
将全局定价检查延迟到渠道选择后执行。

Co-Authored-By: Claude <noreply@anthropic.com>
feat/alipay-payment
fengsilin 1 місяць тому
джерело
коміт
b99337dab7
1 змінених файлів з 5 додано та 3 видалено
  1. +5
    -3
      relay/helper/price.go

+ 5
- 3
relay/helper/price.go Переглянути файл

@@ -54,7 +54,8 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
var channelPricingFound bool

// 尝试获取渠道定价(优先于全局定价)
if info != nil && info.ChannelMeta != nil && info.ChannelId > 0 {
channelMetaAvailable := info != nil && info.ChannelMeta != nil && info.ChannelId > 0
if channelMetaAvailable {
cpRatio, cpCompletionRatio, cpPrice, cpUsePrice, found := model.GetEffectivePricing(info.OriginModelName, info.ChannelId)
if found {
modelRatio = cpRatio
@@ -87,7 +88,8 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
preConsumedTokens += meta.MaxTokens
}
// 如果没有找到渠道定价,需要获取全局 modelRatio 和 completionRatio
if !channelPricingFound {
// 但如果 ChannelMeta 为 nil(渠道选择前),跳过检查,延迟到渠道选择后
if channelMetaAvailable && !channelPricingFound {
var success bool
var matchName string
modelRatio, success, matchName = ratio_setting.GetModelRatio(info.OriginModelName)
@@ -97,7 +99,7 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
acceptUnsetRatio = true
}
if !acceptUnsetRatio {
return types.PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置,请联系管理员设置或开自用模式;Model %s ratio or price not set, please set or start self-use mode", matchName, matchName)
return types.PriceData{}, fmt.Errorf("模型 %s 倍率或价格未配置,请联系管理员设置或开自用模式;Model %s ratio or price not set, please set or start self-use mode", matchName, matchName)
}
}
completionRatio = ratio_setting.GetCompletionRatio(info.OriginModelName)


Завантаження…
Відмінити
Зберегти