From b99337dab7f628840c07fdb34e90654b05850e32 Mon Sep 17 00:00:00 2001 From: fengsilin Date: Wed, 1 Apr 2026 17:21:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(pricing):=20=E4=BF=AE=E5=A4=8D=E6=B8=A0?= =?UTF-8?q?=E9=81=93=E5=AE=9A=E4=BB=B7=E4=BC=98=E5=85=88=E7=BA=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当模型配置了渠道定价但全局定价未设置时,不再提前报错。 将全局定价检查延迟到渠道选择后执行。 Co-Authored-By: Claude --- relay/helper/price.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/relay/helper/price.go b/relay/helper/price.go index 78a0532..fc82e31 100644 --- a/relay/helper/price.go +++ b/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)