2
0

tools.go 2.7 KB

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