Просмотр исходного кода

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

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

Co-Authored-By: Claude <noreply@anthropic.com>
feat/alipay-payment
fengsilin 1 месяц назад
Родитель
Сommit
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 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) cpRatio, cpCompletionRatio, cpPrice, cpUsePrice, found := model.GetEffectivePricing(info.OriginModelName, info.ChannelId)
if found { if found {
modelRatio = cpRatio modelRatio = cpRatio
@@ -87,7 +88,8 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
preConsumedTokens += meta.MaxTokens preConsumedTokens += meta.MaxTokens
} }
// 如果没有找到渠道定价,需要获取全局 modelRatio 和 completionRatio // 如果没有找到渠道定价,需要获取全局 modelRatio 和 completionRatio
if !channelPricingFound {
// 但如果 ChannelMeta 为 nil(渠道选择前),跳过检查,延迟到渠道选择后
if channelMetaAvailable && !channelPricingFound {
var success bool var success bool
var matchName string var matchName string
modelRatio, success, matchName = ratio_setting.GetModelRatio(info.OriginModelName) modelRatio, success, matchName = ratio_setting.GetModelRatio(info.OriginModelName)
@@ -97,7 +99,7 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens
acceptUnsetRatio = true acceptUnsetRatio = true
} }
if !acceptUnsetRatio { 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) completionRatio = ratio_setting.GetCompletionRatio(info.OriginModelName)


Загрузка…
Отмена
Сохранить