cache_ratio.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package ratio_setting
  2. import (
  3. "github.com/QuantumNous/new-api/types"
  4. )
  5. var defaultCacheRatio = map[string]float64{
  6. "gemini-3-flash-preview": 0.25,
  7. "gemini-3-pro-preview": 0.25,
  8. "gpt-4": 0.5,
  9. "o1": 0.5,
  10. "o1-2024-12-17": 0.5,
  11. "o1-preview-2024-09-12": 0.5,
  12. "o1-preview": 0.5,
  13. "o1-mini-2024-09-12": 0.5,
  14. "o1-mini": 0.5,
  15. "o3-mini": 0.5,
  16. "o3-mini-2025-01-31": 0.5,
  17. "gpt-4o-2024-11-20": 0.5,
  18. "gpt-4o-2024-08-06": 0.5,
  19. "gpt-4o": 0.5,
  20. "gpt-4o-mini-2024-07-18": 0.5,
  21. "gpt-4o-mini": 0.5,
  22. "gpt-4o-realtime-preview": 0.5,
  23. "gpt-4o-mini-realtime-preview": 0.5,
  24. "gpt-4.5-preview": 0.5,
  25. "gpt-4.5-preview-2025-02-27": 0.5,
  26. "gpt-4.1": 0.25,
  27. "gpt-4.1-mini": 0.25,
  28. "gpt-4.1-nano": 0.25,
  29. "gpt-5": 0.1,
  30. "gpt-5-2025-08-07": 0.1,
  31. "gpt-5-chat-latest": 0.1,
  32. "gpt-5-mini": 0.1,
  33. "gpt-5-mini-2025-08-07": 0.1,
  34. "gpt-5-nano": 0.1,
  35. "gpt-5-nano-2025-08-07": 0.1,
  36. "deepseek-chat": 0.25,
  37. "deepseek-reasoner": 0.25,
  38. "deepseek-coder": 0.25,
  39. "claude-3-sonnet-20240229": 0.1,
  40. "claude-3-opus-20240229": 0.1,
  41. "claude-3-haiku-20240307": 0.1,
  42. "claude-3-5-haiku-20241022": 0.1,
  43. "claude-haiku-4-5-20251001": 0.1,
  44. "claude-3-5-sonnet-20240620": 0.1,
  45. "claude-3-5-sonnet-20241022": 0.1,
  46. "claude-3-7-sonnet-20250219": 0.1,
  47. "claude-3-7-sonnet-20250219-thinking": 0.1,
  48. "claude-sonnet-4-20250514": 0.1,
  49. "claude-sonnet-4-20250514-thinking": 0.1,
  50. "claude-opus-4-20250514": 0.1,
  51. "claude-opus-4-20250514-thinking": 0.1,
  52. "claude-opus-4-1-20250805": 0.1,
  53. "claude-opus-4-1-20250805-thinking": 0.1,
  54. "claude-sonnet-4-5-20250929": 0.1,
  55. "claude-sonnet-4-5-20250929-thinking": 0.1,
  56. "claude-opus-4-5-20251101": 0.1,
  57. "claude-opus-4-5-20251101-thinking": 0.1,
  58. "claude-opus-4-6": 0.1,
  59. "claude-opus-4-6-thinking": 0.1,
  60. "claude-opus-4-6-max": 0.1,
  61. "claude-opus-4-6-high": 0.1,
  62. "claude-opus-4-6-medium": 0.1,
  63. "claude-opus-4-6-low": 0.1,
  64. }
  65. var defaultCreateCacheRatio = map[string]float64{
  66. "claude-3-sonnet-20240229": 1.25,
  67. "claude-3-opus-20240229": 1.25,
  68. "claude-3-haiku-20240307": 1.25,
  69. "claude-3-5-haiku-20241022": 1.25,
  70. "claude-haiku-4-5-20251001": 1.25,
  71. "claude-3-5-sonnet-20240620": 1.25,
  72. "claude-3-5-sonnet-20241022": 1.25,
  73. "claude-3-7-sonnet-20250219": 1.25,
  74. "claude-3-7-sonnet-20250219-thinking": 1.25,
  75. "claude-sonnet-4-20250514": 1.25,
  76. "claude-sonnet-4-20250514-thinking": 1.25,
  77. "claude-opus-4-20250514": 1.25,
  78. "claude-opus-4-20250514-thinking": 1.25,
  79. "claude-opus-4-1-20250805": 1.25,
  80. "claude-opus-4-1-20250805-thinking": 1.25,
  81. "claude-sonnet-4-5-20250929": 1.25,
  82. "claude-sonnet-4-5-20250929-thinking": 1.25,
  83. "claude-opus-4-5-20251101": 1.25,
  84. "claude-opus-4-5-20251101-thinking": 1.25,
  85. "claude-opus-4-6": 1.25,
  86. "claude-opus-4-6-thinking": 1.25,
  87. "claude-opus-4-6-max": 1.25,
  88. "claude-opus-4-6-high": 1.25,
  89. "claude-opus-4-6-medium": 1.25,
  90. "claude-opus-4-6-low": 1.25,
  91. }
  92. //var defaultCreateCacheRatio = map[string]float64{}
  93. var cacheRatioMap = types.NewRWMap[string, float64]()
  94. var createCacheRatioMap = types.NewRWMap[string, float64]()
  95. // GetCacheRatioMap returns a copy of the cache ratio map
  96. func GetCacheRatioMap() map[string]float64 {
  97. return cacheRatioMap.ReadAll()
  98. }
  99. // CacheRatio2JSONString converts the cache ratio map to a JSON string
  100. func CacheRatio2JSONString() string {
  101. return cacheRatioMap.MarshalJSONString()
  102. }
  103. // CreateCacheRatio2JSONString converts the create cache ratio map to a JSON string
  104. func CreateCacheRatio2JSONString() string {
  105. return createCacheRatioMap.MarshalJSONString()
  106. }
  107. // UpdateCacheRatioByJSONString updates the cache ratio map from a JSON string
  108. func UpdateCacheRatioByJSONString(jsonStr string) error {
  109. return types.LoadFromJsonStringWithCallback(cacheRatioMap, jsonStr, InvalidateExposedDataCache)
  110. }
  111. // UpdateCreateCacheRatioByJSONString updates the create cache ratio map from a JSON string
  112. func UpdateCreateCacheRatioByJSONString(jsonStr string) error {
  113. return types.LoadFromJsonStringWithCallback(createCacheRatioMap, jsonStr, InvalidateExposedDataCache)
  114. }
  115. // GetCacheRatio returns the cache ratio for a model
  116. func GetCacheRatio(name string) (float64, bool) {
  117. ratio, ok := cacheRatioMap.Get(name)
  118. if !ok {
  119. return 1, false // Default to 1 if not found
  120. }
  121. return ratio, true
  122. }
  123. func GetCreateCacheRatio(name string) (float64, bool) {
  124. ratio, ok := createCacheRatioMap.Get(name)
  125. if !ok {
  126. return 1.25, false // Default to 1.25 if not found
  127. }
  128. return ratio, true
  129. }
  130. func GetCacheRatioCopy() map[string]float64 {
  131. return cacheRatioMap.ReadAll()
  132. }
  133. func GetCreateCacheRatioCopy() map[string]float64 {
  134. return createCacheRatioMap.ReadAll()
  135. }