tools.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. const (
  15. // Gemini Audio Input Price
  16. Gemini25FlashPreviewInputAudioPrice = 1.00
  17. Gemini25FlashProductionInputAudioPrice = 1.00 // for `gemini-2.5-flash`
  18. Gemini25FlashNativeAudioInputAudioPrice = 3.00
  19. Gemini20FlashInputAudioPrice = 0.70
  20. )
  21. func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
  22. // 确定模型类型
  23. // https://platform.openai.com/docs/pricing Web search 价格按模型类型和 search context size 收费
  24. // gpt-4.1, gpt-4o, or gpt-4o-search-preview 更贵,gpt-4.1-mini, gpt-4o-mini, gpt-4o-mini-search-preview 更便宜
  25. isHighTierModel := (strings.HasPrefix(modelName, "gpt-4.1") || strings.HasPrefix(modelName, "gpt-4o")) &&
  26. !strings.Contains(modelName, "mini")
  27. // 确定 search context size 对应的价格
  28. var priceWebSearchPerThousandCalls float64
  29. switch contextSize {
  30. case "low":
  31. if isHighTierModel {
  32. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceLow
  33. } else {
  34. priceWebSearchPerThousandCalls = WebSearchPriceLow
  35. }
  36. case "medium":
  37. if isHighTierModel {
  38. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  39. } else {
  40. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  41. }
  42. case "high":
  43. if isHighTierModel {
  44. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceHigh
  45. } else {
  46. priceWebSearchPerThousandCalls = WebSearchPriceHigh
  47. }
  48. default:
  49. // search context size 默认为 medium
  50. if isHighTierModel {
  51. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  52. } else {
  53. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  54. }
  55. }
  56. return priceWebSearchPerThousandCalls
  57. }
  58. func GetFileSearchPricePerThousand() float64 {
  59. return FileSearchPrice
  60. }
  61. func GetGeminiInputAudioPricePerMillionTokens(modelName string) float64 {
  62. if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-native-audio") {
  63. return Gemini25FlashNativeAudioInputAudioPrice
  64. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview") {
  65. return Gemini25FlashPreviewInputAudioPrice
  66. } else if strings.HasPrefix(modelName, "gemini-2.5-flash") {
  67. return Gemini25FlashProductionInputAudioPrice
  68. } else if strings.HasPrefix(modelName, "gemini-2.0-flash") {
  69. return Gemini20FlashInputAudioPrice
  70. }
  71. return 0
  72. }