|
|
|
@@ -4,6 +4,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"github.com/QuantumNous/new-api/common" |
|
|
|
"github.com/QuantumNous/new-api/constant" |
|
|
|
"github.com/QuantumNous/new-api/logger" |
|
|
|
"github.com/QuantumNous/new-api/model" |
|
|
|
relaycommon "github.com/QuantumNous/new-api/relay/common" |
|
|
|
@@ -52,10 +53,16 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens |
|
|
|
var cacheRatio, cacheCreationRatio, imageRatio, audioRatio, audioCompletionRatio float64 |
|
|
|
|
|
|
|
// 尝试获取渠道定价(优先于全局定价) |
|
|
|
channelMetaAvailable := info != nil && info.ChannelMeta != nil && info.ChannelId > 0 |
|
|
|
if channelMetaAvailable { |
|
|
|
cp, found := model.GetEffectivePricing(info.OriginModelName, info.ChannelId) |
|
|
|
if found { |
|
|
|
// ChannelMeta 在 InitChannelMeta 之前为 nil,但 Distribute 已将 channelId 写入 context |
|
|
|
channelId := 0 |
|
|
|
if info != nil && info.ChannelMeta != nil && info.ChannelId > 0 { |
|
|
|
channelId = info.ChannelId |
|
|
|
} else { |
|
|
|
channelId = common.GetContextKeyInt(c, constant.ContextKeyChannelId) |
|
|
|
} |
|
|
|
if channelId > 0 { |
|
|
|
cp, found := model.GetEffectivePricing(info.OriginModelName, channelId) |
|
|
|
if found && cp != nil { |
|
|
|
modelRatio = cp.ModelRatio |
|
|
|
completionRatio = cp.CompletionRatio |
|
|
|
modelPrice = cp.ModelPrice |
|
|
|
@@ -67,9 +74,6 @@ func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens |
|
|
|
imageRatio = cp.ImageRatio |
|
|
|
audioRatio = cp.AudioRatio |
|
|
|
audioCompletionRatio = cp.AudioCompletionRatio |
|
|
|
if common.DebugEnabled { |
|
|
|
println(fmt.Sprintf("[ChannelPricing] hit: model=%s channel=%d source=cache", info.OriginModelName, info.ChannelId)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|