tools.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. GeminiRoboticsER15InputAudioPrice = 1.00
  29. )
  30. const (
  31. // Claude Web search
  32. ClaudeWebSearchPrice = 10.00
  33. )
  34. func GetClaudeWebSearchPricePerThousand() float64 {
  35. return ClaudeWebSearchPrice
  36. }
  37. func GetWebSearchPricePerThousand(modelName string, contextSize string) float64 {
  38. // 确定模型类型
  39. // https://platform.openai.com/docs/pricing Web search 价格按模型类型收费
  40. // 新版计费规则不再关联 search context size,故在const区域将各size的价格设为一致。
  41. // gpt-5, gpt-5-mini, gpt-5-nano 和 o 系列模型价格为 10.00 美元/千次调用,产生额外 token 计入 input_tokens
  42. // gpt-4o, gpt-4.1, gpt-4o-mini 和 gpt-4.1-mini 价格为 25.00 美元/千次调用,不产生额外 token
  43. isNormalPriceModel :=
  44. strings.HasPrefix(modelName, "o3") ||
  45. strings.HasPrefix(modelName, "o4") ||
  46. strings.HasPrefix(modelName, "gpt-5")
  47. var priceWebSearchPerThousandCalls float64
  48. if isNormalPriceModel {
  49. priceWebSearchPerThousandCalls = WebSearchPrice
  50. } else {
  51. priceWebSearchPerThousandCalls = WebSearchPriceHigh
  52. }
  53. return priceWebSearchPerThousandCalls
  54. }
  55. func GetFileSearchPricePerThousand() float64 {
  56. return FileSearchPrice
  57. }
  58. func GetGeminiInputAudioPricePerMillionTokens(modelName string) float64 {
  59. if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-native-audio") {
  60. return Gemini25FlashNativeAudioInputAudioPrice
  61. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview-lite") {
  62. return Gemini25FlashLitePreviewInputAudioPrice
  63. } else if strings.HasPrefix(modelName, "gemini-2.5-flash-preview") {
  64. return Gemini25FlashPreviewInputAudioPrice
  65. } else if strings.HasPrefix(modelName, "gemini-2.5-flash") {
  66. return Gemini25FlashProductionInputAudioPrice
  67. } else if strings.HasPrefix(modelName, "gemini-2.0-flash") {
  68. return Gemini20FlashInputAudioPrice
  69. } else if strings.HasPrefix(modelName, "gemini-robotics-er-1.5") {
  70. return GeminiRoboticsER15InputAudioPrice
  71. }
  72. return 0
  73. }
  74. func GetGPTImage1PriceOnceCall(quality string, size string) float64 {
  75. prices := map[string]map[string]float64{
  76. "low": {
  77. "1024x1024": GPTImage1Low1024x1024,
  78. "1024x1536": GPTImage1Low1024x1536,
  79. "1536x1024": GPTImage1Low1536x1024,
  80. },
  81. "medium": {
  82. "1024x1024": GPTImage1Medium1024x1024,
  83. "1024x1536": GPTImage1Medium1024x1536,
  84. "1536x1024": GPTImage1Medium1536x1024,
  85. },
  86. "high": {
  87. "1024x1024": GPTImage1High1024x1024,
  88. "1024x1536": GPTImage1High1024x1536,
  89. "1536x1024": GPTImage1High1536x1024,
  90. },
  91. }
  92. if qualityMap, exists := prices[quality]; exists {
  93. if price, exists := qualityMap[size]; exists {
  94. return price
  95. }
  96. }
  97. return GPTImage1High1024x1024
  98. }