cache_ratio.go 6.2 KB

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