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)