1
0

tools.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. 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. // gpt-4.1, gpt-4o, or gpt-4o-search-preview 更贵,gpt-4.1-mini, gpt-4o-mini, gpt-4o-mini-search-preview 更便宜
  33. isHighTierModel := (strings.HasPrefix(modelName, "gpt-4.1") || strings.HasPrefix(modelName, "gpt-4o")) &&
  34. !strings.Contains(modelName, "mini")
  35. // 确定 search context size 对应的价格
  36. var priceWebSearchPerThousandCalls float64
  37. switch contextSize {
  38. case "low":
  39. if isHighTierModel {
  40. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceLow
  41. } else {
  42. priceWebSearchPerThousandCalls = WebSearchPriceLow
  43. }
  44. case "medium":
  45. if isHighTierModel {
  46. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  47. } else {
  48. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  49. }
  50. case "high":
  51. if isHighTierModel {
  52. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceHigh
  53. } else {
  54. priceWebSearchPerThousandCalls = WebSearchPriceHigh
  55. }
  56. default:
  57. // search context size 默认为 medium
  58. if isHighTierModel {
  59. priceWebSearchPerThousandCalls = WebSearchHighTierModelPriceMedium
  60. } else {
  61. priceWebSearchPerThousandCalls = WebSearchPriceMedium
  62. }
  63. }
  64. return priceWebSearchPerThousandCalls
  65. }
  66. func GetFileSearchPricePerThousand() float64 {
  67. return FileSearchPrice
  68. }
  69. func GetGeminiInputAudioPricePerMillionTokens(modelName string) float64 {
  70. if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-native-audio") {
  71. return Gemini25FlashNativeAudioInputAudioPrice
  72. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-lite") {
  73. return Gemini25FlashLitePreviewInputAudioPrice
  74. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview") {
  75. return Gemini25FlashPreviewInputAudioPrice
  76. } else if strings.HasPrefix(modelName, "gemini-2.5-flash") {
  77. return Gemini25FlashProductionInputAudioPrice
  78. } else if strings.HasPrefix(modelName, "gemini-2.0-flash") {
  79. return Gemini20FlashInputAudioPrice
  80. }
  81. return 0
  82. }