tools.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package operation_setting
  2. import "strings"
  3. const (
  4. // Web search
  5. WebSearchPriceHigh = 25.00
  6. WebSearchPrice = 10.00
  7. // File search
  8. FileSearchPrice = 2.5
  9. )
  10. const (
  11. GPTImage1Low1024x1024 = 0.011
  12. GPTImage1Low1024x1536 = 0.016
  13. GPTImage1Low1536x1024 = 0.016
  14. GPTImage1Medium1024x1024 = 0.042
  15. GPTImage1Medium1024x1536 = 0.063
  16. GPTImage1Medium1536x1024 = 0.063
  17. GPTImage1High1024x1024 = 0.167
  18. GPTImage1High1024x1536 = 0.25
  19. GPTImage1High1536x1024 = 0.25
  20. )
  21. const (
  22. // Gemini Audio Input Price
  23. Gemini25FlashPreviewInputAudioPrice = 1.00
  24. Gemini25FlashProductionInputAudioPrice = 1.00 // for `gemini-2.5-flash`
  25. Gemini25FlashLitePreviewInputAudioPrice = 0.50
  26. Gemini25FlashNativeAudioInputAudioPrice = 3.00
  27. Gemini20FlashInputAudioPrice = 0.70
  28. )
  29. const (
  30. // Claude Web search
  31. ClaudeWebSearchPrice = 10.00
  32. )
  33. func GetClaudeWebSearchPricePerThousand() float64 {
  34. return ClaudeWebSearchPrice
  35. }
  36. func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
  37. // 确定模型类型
  38. // https://platform.openai.com/docs/pricing Web search 价格按模型类型收费
  39. // 新版计费规则不再关联 search context size,故在const区域将各size的价格设为一致。
  40. // gpt-5, gpt-5-mini, gpt-5-nano 和 o 系列模型价格为 10.00 美元/千次调用,产生额外 token 计入 input_tokens
  41. // gpt-4o, gpt-4.1, gpt-4o-mini 和 gpt-4.1-mini 价格为 25.00 美元/千次调用,不产生额外 token
  42. isNormalPriceModel :=
  43. strings.HasPrefix(modelName, "o3") ||
  44. strings.HasPrefix(modelName, "o4") ||
  45. strings.HasPrefix(modelName, "gpt-5")
  46. var priceWebSearchPerThousandCalls float64
  47. if isNormalPriceModel {
  48. priceWebSearchPerThousandCalls = WebSearchPrice
  49. } else {
  50. priceWebSearchPerThousandCalls = WebSearchPriceHigh
  51. }
  52. return priceWebSearchPerThousandCalls
  53. }
  54. func GetFileSearchPricePerThousand() float64 {
  55. return FileSearchPrice
  56. }
  57. func GetGeminiInputAudioPricePerMillionTokens(modelName string) float64 {
  58. if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-native-audio") {
  59. return Gemini25FlashNativeAudioInputAudioPrice
  60. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-lite") {
  61. return Gemini25FlashLitePreviewInputAudioPrice
  62. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview") {
  63. return Gemini25FlashPreviewInputAudioPrice
  64. } else if strings.HasPrefix(modelName, "gemini-2.5-flash") {
  65. return Gemini25FlashProductionInputAudioPrice
  66. } else if strings.HasPrefix(modelName, "gemini-2.0-flash") {
  67. return Gemini20FlashInputAudioPrice
  68. }
  69. return 0
  70. }
  71. func GetGPTImage1PriceOnceCall(quality string, size string) float64 {
  72. prices := map[string]map[string]float64{
  73. "low": {
  74. "1024x1024": GPTImage1Low1024x1024,
  75. "1024x1536": GPTImage1Low1024x1536,
  76. "1536x1024": GPTImage1Low1536x1024,
  77. },
  78. "medium": {
  79. "1024x1024": GPTImage1Medium1024x1024,
  80. "1024x1536": GPTImage1Medium1024x1536,
  81. "1536x1024": GPTImage1Medium1536x1024,
  82. },
  83. "high": {
  84. "1024x1024": GPTImage1High1024x1024,
  85. "1024x1536": GPTImage1High1024x1536,
  86. "1536x1024": GPTImage1High1536x1024,
  87. },
  88. }
  89. if qualityMap, exists := prices[quality]; exists {
  90. if price, exists := qualityMap[size]; exists {
  91. return price
  92. }
  93. }
  94. return GPTImage1High1024x1024
  95. }