feat(*): 模型计费与渠道目录 - 支持视频 Token 报价结算和稳定模型展示
This commit is contained in:
1 parent
90add8c466
commit
1a79005d25
57 files changed
+2904
-341
No files matched your search
@@ -2,6 +2,21 @@ package app
|
||||
|
||||
import "infinite-canvas/backend/internal/model"
|
||||
|
||||
const maxChannelModelTokenPriceMicrocredits = int64(1_000_000) * CreditScale
|
||||
|
||||
func validateTokenPrices(capability string, inputPrice, outputPrice, cachedPrice int64) error {
|
||||
if inputPrice < 0 || outputPrice < 0 || cachedPrice < 0 {
|
||||
return BadAuthRequest("模型积分价格不能小于 0")
|
||||
}
|
||||
if capability == "video" && (inputPrice != 0 || cachedPrice != 0) {
|
||||
return BadAuthRequest("视频 Token 仅按视频用量计费,输入和缓存 Token 价格必须为 0")
|
||||
}
|
||||
if inputPrice > maxChannelModelTokenPriceMicrocredits || outputPrice > maxChannelModelTokenPriceMicrocredits || cachedPrice > maxChannelModelTokenPriceMicrocredits {
|
||||
return BadAuthRequest("Token 每百万用量价格不能超过 1,000,000 积分")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateChannelModelPrice 校验渠道模型价格配置的有效性
|
||||
// 根据 billingMode 检查必要的价格字段是否已配置
|
||||
func ValidateChannelModelPrice(billingMode string, capability string, protocol model.ChannelInterfaceType, unitPrice, inputPrice, outputPrice, cachedPrice int64) bool {
|
||||
@@ -13,14 +28,17 @@ func ValidateChannelModelPrice(billingMode string, capability string, protocol m
|
||||
// 按秒计费:0 表示免费,负数无效。
|
||||
return unitPrice >= 0
|
||||
case "token":
|
||||
if validateTokenPrices(capability, inputPrice, outputPrice, cachedPrice) != nil {
|
||||
return false
|
||||
}
|
||||
if capability == "video" {
|
||||
return model.IsVolcengineArkVideoProtocol(protocol) && inputPrice >= 0 && outputPrice >= 0 && cachedPrice >= 0
|
||||
return true
|
||||
}
|
||||
if capability != "" && capability != "text" {
|
||||
return false
|
||||
}
|
||||
// 文本模型:所有 Token 价格为 0 时表示免费。
|
||||
return inputPrice >= 0 && outputPrice >= 0 && cachedPrice >= 0
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user