feat(billing): 添加TTS模型计费功能
This commit is contained in:
@@ -22,6 +22,8 @@ func CalculateBilling(config map[string]any, billingData map[string]any) map[str
|
||||
return calculateInferenceTierBilling(config, billingData)
|
||||
case "video_resolution": //视频模型计费
|
||||
return calculateVideoResolutionBilling(config, billingData)
|
||||
case "tts":
|
||||
return calculateTTSBilling(config, billingData)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -116,6 +118,40 @@ func calculateVideoResolutionBilling(config map[string]any, data map[string]any)
|
||||
}
|
||||
}
|
||||
|
||||
func calculateTTSBilling(config map[string]any, data map[string]any) map[string]any {
|
||||
unit, _ := config["unit"].(string)
|
||||
usage := gconv.Float64(data["usage"])
|
||||
|
||||
tiers := config["pricing"].(map[string]any)["tiers"].([]any)
|
||||
var matched map[string]any
|
||||
for _, t := range tiers {
|
||||
tier := t.(map[string]any)
|
||||
if usage >= gconv.Float64(tier["min"]) && usage <= gconv.Float64(tier["max"]) {
|
||||
matched = tier
|
||||
break
|
||||
}
|
||||
}
|
||||
if matched == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
unitPrice := gconv.Float64(matched["unit_price"])
|
||||
totalFee := usage * unitPrice
|
||||
|
||||
return map[string]any{
|
||||
"model_name": data["model_name"],
|
||||
"total_tokens": int64(usage),
|
||||
"total_fee": totalFee,
|
||||
// 明细
|
||||
"prompt_tokens": 0,
|
||||
"completion_tokens": int64(usage),
|
||||
"usage": usage,
|
||||
"unit": unit,
|
||||
"unit_price": unitPrice,
|
||||
"tier": fmt.Sprintf("[%v, %v]", matched["min"], matched["max"]),
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== 数据提取 ========================
|
||||
|
||||
func ExtractRequestBilling(ctx context.Context, config map[string]any, requestPayload map[string]any) map[string]any {
|
||||
|
||||
Reference in New Issue
Block a user