tools.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package operation_setting
  2. import "strings"
  3. const (
  4. WebSearchHighTierModelPriceLow = 30.00
  5. WebSearchHighTierModelPriceMedium = 35.00
  6. WebSearchHighTierModelPriceHigh = 50.00
  7. WebSearchPriceLow = 25.00
  8. WebSearchPriceMedium = 27.50
  9. WebSearchPriceHigh = 30.00
  10. )
  11. func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
  12. // 确定模型类型
  13. // https://platform.openai.com/docs/pricing Web search 价格按模型类型和 search context size 收费
  14. // gpt-4.1, gpt-4o, or gpt-4o-search-preview 更贵,gpt-4.1-mini, gpt-4o-mini, gpt-4o-mini-search-preview 更便宜
  15. isHighTierModel := (strings.HasPrefix(modelName, "gpt-4.1") || strings.HasPrefix(modelName, "gpt-4o")) &&
  16. !strings.Contains(modelName, "mini")
  17. // 确定 search context size 对应的价格
  18. var priceWebSearchPerThousandCalls float64
  19. switch contextSize {
  20. case "low":
  21. if isHighTierModel {
  22. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceLow
  23. } else {
  24. priceWebSearchPerThousandCalls = WebSearchPriceLow
  25. }
  26. case "medium":
  27. if isHighTierModel {
  28. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  29. } else {
  30. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  31. }
  32. case "high":
  33. if isHighTierModel {
  34. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceHigh
  35. } else {
  36. priceWebSearchPerThousandCalls = WebSearchPriceHigh
  37. }
  38. default:
  39. // search context size 默认为 medium
  40. if isHighTierModel {
  41. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  42. } else {
  43. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  44. }
  45. }
  46. return priceWebSearchPerThousandCalls
  47. }