constants.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package common
  2. import (
  3. "os"
  4. "strconv"
  5. "sync"
  6. "time"
  7. "github.com/google/uuid"
  8. )
  9. var StartTime = time.Now().Unix() // unit: second
  10. var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
  11. var SystemName = "One API"
  12. var ServerAddress = "http://localhost:3000"
  13. var PayAddress = ""
  14. var EpayId = ""
  15. var EpayKey = ""
  16. var Price = 7.3
  17. var Footer = ""
  18. var Logo = ""
  19. var TopUpLink = ""
  20. var ChatLink = ""
  21. var QuotaPerUnit = 500 * 1000.0 // $0.002 / 1K tokens
  22. var DisplayInCurrencyEnabled = true
  23. var DisplayTokenStatEnabled = true
  24. // Any options with "Secret", "Token" in its key won't be return by GetOptions
  25. var SessionSecret = uuid.New().String()
  26. var OptionMap map[string]string
  27. var OptionMapRWMutex sync.RWMutex
  28. var ItemsPerPage = 10
  29. var MaxRecentItems = 100
  30. var PasswordLoginEnabled = true
  31. var PasswordRegisterEnabled = true
  32. var EmailVerificationEnabled = false
  33. var GitHubOAuthEnabled = false
  34. var WeChatAuthEnabled = false
  35. var TurnstileCheckEnabled = false
  36. var RegisterEnabled = true
  37. var EmailDomainRestrictionEnabled = false
  38. var EmailDomainWhitelist = []string{
  39. "gmail.com",
  40. "163.com",
  41. "126.com",
  42. "qq.com",
  43. "outlook.com",
  44. "hotmail.com",
  45. "icloud.com",
  46. "yahoo.com",
  47. "foxmail.com",
  48. }
  49. var DebugEnabled = os.Getenv("DEBUG") == "true"
  50. var MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true"
  51. var LogConsumeEnabled = true
  52. var SMTPServer = ""
  53. var SMTPPort = 587
  54. var SMTPAccount = ""
  55. var SMTPFrom = ""
  56. var SMTPToken = ""
  57. var GitHubClientId = ""
  58. var GitHubClientSecret = ""
  59. var WeChatServerAddress = ""
  60. var WeChatServerToken = ""
  61. var WeChatAccountQRCodeImageURL = ""
  62. var TurnstileSiteKey = ""
  63. var TurnstileSecretKey = ""
  64. var QuotaForNewUser = 0
  65. var QuotaForInviter = 0
  66. var QuotaForInvitee = 0
  67. var ChannelDisableThreshold = 5.0
  68. var AutomaticDisableChannelEnabled = false
  69. var QuotaRemindThreshold = 1000
  70. var PreConsumedQuota = 500
  71. var RetryTimes = 0
  72. var RootUserEmail = ""
  73. var IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
  74. var requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
  75. var RequestInterval = time.Duration(requestInterval) * time.Second
  76. var SyncFrequency = GetOrDefault("SYNC_FREQUENCY", 10*60) // unit is second
  77. var BatchUpdateEnabled = false
  78. var BatchUpdateInterval = GetOrDefault("BATCH_UPDATE_INTERVAL", 5)
  79. var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
  80. const (
  81. RequestIdKey = "X-Oneapi-Request-Id"
  82. )
  83. const (
  84. RoleGuestUser = 0
  85. RoleCommonUser = 1
  86. RoleAdminUser = 10
  87. RoleRootUser = 100
  88. )
  89. var (
  90. FileUploadPermission = RoleGuestUser
  91. FileDownloadPermission = RoleGuestUser
  92. ImageUploadPermission = RoleGuestUser
  93. ImageDownloadPermission = RoleGuestUser
  94. )
  95. // All duration's unit is seconds
  96. // Shouldn't larger then RateLimitKeyExpirationDuration
  97. var (
  98. GlobalApiRateLimitNum = GetOrDefault("GLOBAL_API_RATE_LIMIT", 180)
  99. GlobalApiRateLimitDuration int64 = 3 * 60
  100. GlobalWebRateLimitNum = GetOrDefault("GLOBAL_WEB_RATE_LIMIT", 60)
  101. GlobalWebRateLimitDuration int64 = 3 * 60
  102. UploadRateLimitNum = 10
  103. UploadRateLimitDuration int64 = 60
  104. DownloadRateLimitNum = 10
  105. DownloadRateLimitDuration int64 = 60
  106. CriticalRateLimitNum = 20
  107. CriticalRateLimitDuration int64 = 20 * 60
  108. )
  109. var RateLimitKeyExpirationDuration = 20 * time.Minute
  110. const (
  111. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  112. UserStatusDisabled = 2 // also don't use 0
  113. )
  114. const (
  115. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  116. TokenStatusDisabled = 2 // also don't use 0
  117. TokenStatusExpired = 3
  118. TokenStatusExhausted = 4
  119. )
  120. const (
  121. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  122. RedemptionCodeStatusDisabled = 2 // also don't use 0
  123. RedemptionCodeStatusUsed = 3 // also don't use 0
  124. )
  125. const (
  126. ChannelStatusUnknown = 0
  127. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  128. ChannelStatusManuallyDisabled = 2 // also don't use 0
  129. ChannelStatusAutoDisabled = 3
  130. )
  131. const (
  132. ChannelTypeUnknown = 0
  133. ChannelTypeOpenAI = 1
  134. ChannelTypeAPI2D = 2
  135. ChannelTypeAzure = 3
  136. ChannelTypeCloseAI = 4
  137. ChannelTypeOpenAISB = 5
  138. ChannelTypeOpenAIMax = 6
  139. ChannelTypeOhMyGPT = 7
  140. ChannelTypeCustom = 8
  141. ChannelTypeAILS = 9
  142. ChannelTypeAIProxy = 10
  143. ChannelTypePaLM = 11
  144. ChannelTypeAPI2GPT = 12
  145. ChannelTypeAIGC2D = 13
  146. ChannelTypeAnthropic = 14
  147. ChannelTypeBaidu = 15
  148. ChannelTypeZhipu = 16
  149. ChannelTypeAli = 17
  150. ChannelTypeXunfei = 18
  151. ChannelType360 = 19
  152. ChannelTypeOpenRouter = 20
  153. ChannelTypeAIProxyLibrary = 21
  154. ChannelTypeFastGPT = 22
  155. ChannelTypeTencent = 23
  156. )
  157. var ChannelBaseURLs = []string{
  158. "", // 0
  159. "https://api.openai.com", // 1
  160. "https://oa.api2d.net", // 2
  161. "", // 3
  162. "https://api.closeai-proxy.xyz", // 4
  163. "https://api.openai-sb.com", // 5
  164. "https://api.openaimax.com", // 6
  165. "https://api.ohmygpt.com", // 7
  166. "", // 8
  167. "https://api.caipacity.com", // 9
  168. "https://api.aiproxy.io", // 10
  169. "", // 11
  170. "https://api.api2gpt.com", // 12
  171. "https://api.aigc2d.com", // 13
  172. "https://api.anthropic.com", // 14
  173. "https://aip.baidubce.com", // 15
  174. "https://open.bigmodel.cn", // 16
  175. "https://dashscope.aliyuncs.com", // 17
  176. "", // 18
  177. "https://ai.360.cn", // 19
  178. "https://openrouter.ai/api", // 20
  179. "https://api.aiproxy.io", // 21
  180. "https://fastgpt.run/api/openapi", // 22
  181. "https://hunyuan.cloud.tencent.com", //23
  182. }