|
|
|
@@ -54,7 +54,7 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens |
|
|
|
var channelPricingFound bool |
|
|
|
|
|
|
|
// 尝试获取渠道定价(优先于全局定价) |
|
|
|
if info.ChannelMeta != nil && info.ChannelId > 0 { |
|
|
|
if info != nil && info.ChannelMeta != nil && info.ChannelId > 0 { |
|
|
|
cpRatio, cpCompletionRatio, cpPrice, cpUsePrice, found := model.GetEffectivePricing(info.OriginModelName, info.ChannelId) |
|
|
|
if found { |
|
|
|
modelRatio = cpRatio |
|
|
|
@@ -207,3 +207,39 @@ func ContainPriceOrRatio(modelName string) bool { |
|
|
|
} |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
// UpdatePriceDataForChannelPricing 在渠道选择后更新 PriceData 以使用渠道定价 |
|
|
|
// ModelPriceHelper 在渠道选择之前被调用,此时 ChannelMeta 为 nil,导致渠道定价无法使用。 |
|
|
|
// 需要在渠道选择后调用此函数更新价格数据,用于后续的日志记录和计费计算。 |
|
|
|
func UpdatePriceDataForChannelPricing(c *gin.Context, info *relaycommon.RelayInfo, channelId int) { |
|
|
|
if info == nil || channelId <= 0 { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
cpRatio, cpCompletionRatio, cpPrice, cpUsePrice, found := model.GetEffectivePricing(info.OriginModelName, channelId) |
|
|
|
if !found { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 更新 PriceData 中的定价相关字段 |
|
|
|
info.PriceData.ModelRatio = cpRatio |
|
|
|
info.PriceData.CompletionRatio = cpCompletionRatio |
|
|
|
info.PriceData.UsePrice = cpUsePrice |
|
|
|
// 按次计费模式下使用渠道价格,按量计费模式下设置 ModelPrice = -1 让前端识别计费模式 |
|
|
|
if cpUsePrice { |
|
|
|
info.PriceData.ModelPrice = cpPrice |
|
|
|
} else { |
|
|
|
info.PriceData.ModelPrice = -1 |
|
|
|
} |
|
|
|
|
|
|
|
// 重新计算预扣费额度(用于后续可能的引用) |
|
|
|
if cpUsePrice { |
|
|
|
info.PriceData.QuotaToPreConsume = int(cpPrice * common.QuotaPerUnit * info.PriceData.GroupRatioInfo.GroupRatio) |
|
|
|
} else { |
|
|
|
estimateTokens := info.GetEstimatePromptTokens() |
|
|
|
if estimateTokens > 0 { |
|
|
|
ratio := cpRatio * info.PriceData.GroupRatioInfo.GroupRatio |
|
|
|
info.PriceData.QuotaToPreConsume = int(float64(estimateTokens) * ratio) |
|
|
|
} |
|
|
|
} |
|
|
|
} |