tools.go 2.4 KB

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