31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package billing
|
|
|
|
import (
|
|
"errors"
|
|
"math"
|
|
"strings"
|
|
)
|
|
|
|
const Seedream50ProModel = "doubao-seedream-5-0-pro-260628"
|
|
|
|
// CalculateSeedreamAmountFen applies Seedream's additive input-image price
|
|
// before the platform markup: the first reference image is free and every
|
|
// additional reference image costs 2 fen.
|
|
func CalculateSeedreamAmountFen(outputPriceFen int64, referenceImageCount int, markupMultiplier float64) (int64, error) {
|
|
if outputPriceFen <= 0 {
|
|
return 0, errors.New("seedream output price must be positive")
|
|
}
|
|
if referenceImageCount < 0 || referenceImageCount > 10 {
|
|
return 0, errors.New("seedream reference image count must be between 0 and 10")
|
|
}
|
|
if math.IsNaN(markupMultiplier) || math.IsInf(markupMultiplier, 0) || markupMultiplier < 1 {
|
|
return 0, errors.New("seedream markup multiplier must be at least 1")
|
|
}
|
|
extraInputPriceFen := int64(max(0, referenceImageCount-1) * 2)
|
|
return int64(math.Ceil(float64(outputPriceFen+extraInputPriceFen) * markupMultiplier)), nil
|
|
}
|
|
|
|
func IsSeedreamBillingModel(model string) bool {
|
|
return strings.TrimSpace(model) == Seedream50ProModel
|
|
}
|