refactor: simplify WebSearchPrice const
This commit is contained in:
@@ -4,12 +4,8 @@ import "strings"
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Web search
|
// Web search
|
||||||
WebSearchHighTierModelPriceLow = 10.00
|
|
||||||
WebSearchHighTierModelPriceMedium = 10.00
|
|
||||||
WebSearchHighTierModelPriceHigh = 10.00
|
|
||||||
WebSearchPriceLow = 25.00
|
|
||||||
WebSearchPriceMedium = 25.00
|
|
||||||
WebSearchPriceHigh = 25.00
|
WebSearchPriceHigh = 25.00
|
||||||
|
WebSearchPrice = 10.00
|
||||||
// File search
|
// File search
|
||||||
FileSearchPrice = 2.5
|
FileSearchPrice = 2.5
|
||||||
)
|
)
|
||||||
@@ -34,42 +30,19 @@ func GetClaudeWebSearchPricePerThousand() float64 {
|
|||||||
|
|
||||||
func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
|
func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
|
||||||
// 确定模型类型
|
// 确定模型类型
|
||||||
// https://platform.openai.com/docs/pricing Web search 价格按模型类型和 search context size 收费
|
// https://platform.openai.com/docs/pricing Web search 价格按模型类型收费
|
||||||
// 新版计费规则不再关联 search context size,故在const区域将各size的价格设为一致。
|
// 新版计费规则不再关联 search context size,故在const区域将各size的价格设为一致。
|
||||||
// gpt-4o and gpt-4.1 models (including mini models) 等普通模型更贵,o3, o4-mini, o3-pro, and deep research models 等高级模型更便宜
|
// gpt-4o and gpt-4.1 models (including mini models) 等模型更贵,o3, o4-mini, o3-pro, and deep research models 等模型更便宜
|
||||||
isHighTierModel :=
|
isNormalPriceModel :=
|
||||||
strings.HasPrefix(modelName, "o3") ||
|
strings.HasPrefix(modelName, "o3") ||
|
||||||
strings.HasPrefix(modelName, "o4") ||
|
strings.HasPrefix(modelName, "o4") ||
|
||||||
strings.Contains(modelName, "deep-research")
|
strings.Contains(modelName, "deep-research")
|
||||||
// 确定 search context size 对应的价格
|
|
||||||
var priceWebSearchPerThousandCalls float64
|
var priceWebSearchPerThousandCalls float64
|
||||||
switch contextSize {
|
if isNormalPriceModel {
|
||||||
case "low":
|
priceWebSearchPerThousandCalls = WebSearchPrice
|
||||||
if isHighTierModel {
|
|
||||||
priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceLow
|
|
||||||
} else {
|
|
||||||
priceWebSearchPerThousandCalls = WebSearchPriceLow
|
|
||||||
}
|
|
||||||
case "medium":
|
|
||||||
if isHighTierModel {
|
|
||||||
priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
|
|
||||||
} else {
|
|
||||||
priceWebSearchPerThousandCalls = WebSearchPriceMedium
|
|
||||||
}
|
|
||||||
case "high":
|
|
||||||
if isHighTierModel {
|
|
||||||
priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceHigh
|
|
||||||
} else {
|
} else {
|
||||||
priceWebSearchPerThousandCalls = WebSearchPriceHigh
|
priceWebSearchPerThousandCalls = WebSearchPriceHigh
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
// search context size 默认为 medium
|
|
||||||
if isHighTierModel {
|
|
||||||
priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
|
|
||||||
} else {
|
|
||||||
priceWebSearchPerThousandCalls = WebSearchPriceMedium
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return priceWebSearchPerThousandCalls
|
return priceWebSearchPerThousandCalls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user