constants.go 5.4 KB

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