tools.go 1.8 KB

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