tools.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package operation_setting
  2. import "strings"
  3. const (
  4. // Web search
  5. WebSearchHighTierModelPriceLow = 10.00
  6. WebSearchHighTierModelPriceMedium = 10.00
  7. WebSearchHighTierModelPriceHigh = 10.00
  8. WebSearchPriceLow = 25.00
  9. WebSearchPriceMedium = 25.00
  10. WebSearchPriceHigh = 25.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. Gemini25FlashLitePreviewInputAudioPrice = 0.50
  19. Gemini25FlashNativeAudioInputAudioPrice = 3.00
  20. Gemini20FlashInputAudioPrice = 0.70
  21. )
  22. const (
  23. // Claude Web search
  24. ClaudeWebSearchPrice = 10.00
  25. )
  26. func GetClaudeWebSearchPricePerThousand() float64 {
  27. return ClaudeWebSearchPrice
  28. }
  29. func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
  30. // 确定模型类型
  31. // https://platform.openai.com/docs/pricing Web search 价格按模型类型和 search context size 收费
  32. // 新版计费规则不再关联 search context size,故在const区域将各size的价格设为一致。
  33. // gpt-4o and gpt-4.1 models (including mini models) 等普通模型更贵,o3, o4-mini, o3-pro, and deep research models 等高级模型更便宜
  34. isHighTierModel :=
  35. strings.HasPrefix(modelName, "o3") ||
  36. strings.HasPrefix(modelName, "o4") ||
  37. strings.Contains(modelName, "deep-research")
  38. // 确定 search context size 对应的价格
  39. var priceWebSearchPerThousandCalls float64
  40. switch contextSize {
  41. case "low":
  42. if isHighTierModel {
  43. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceLow
  44. } else {
  45. priceWebSearchPerThousandCalls = WebSearchPriceLow
  46. }
  47. case "medium":
  48. if isHighTierModel {
  49. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  50. } else {
  51. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  52. }
  53. case "high":
  54. if isHighTierModel {
  55. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceHigh
  56. } else {
  57. priceWebSearchPerThousandCalls = WebSearchPriceHigh
  58. }
  59. default:
  60. // search context size 默认为 medium
  61. if isHighTierModel {
  62. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  63. } else {
  64. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  65. }
  66. }
  67. return priceWebSearchPerThousandCalls
  68. }
  69. func GetFileSearchPricePerThousand() float64 {
  70. return FileSearchPrice
  71. }
  72. func GetGeminiInputAudioPricePerMillionTokens(modelName string) float64 {
  73. if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-native-audio") {
  74. return Gemini25FlashNativeAudioInputAudioPrice
  75. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-lite") {
  76. return Gemini25FlashLitePreviewInputAudioPrice
  77. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview") {
  78. return Gemini25FlashPreviewInputAudioPrice
  79. } else if strings.HasPrefix(modelName, "gemini-2.5-flash") {
  80. return Gemini25FlashProductionInputAudioPrice
  81. } else if strings.HasPrefix(modelName, "gemini-2.0-flash") {
  82. return Gemini20FlashInputAudioPrice
  83. }
  84. return 0
  85. }