constants.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 LogConsumeEnabled = true
  48. var SMTPServer = ""
  49. var SMTPPort = 587
  50. var SMTPAccount = ""
  51. var SMTPFrom = ""
  52. var SMTPToken = ""
  53. var GitHubClientId = ""
  54. var GitHubClientSecret = ""
  55. var WeChatServerAddress = ""
  56. var WeChatServerToken = ""
  57. var WeChatAccountQRCodeImageURL = ""
  58. var TurnstileSiteKey = ""
  59. var TurnstileSecretKey = ""
  60. var QuotaForNewUser = 0
  61. var QuotaForInviter = 0
  62. var QuotaForInvitee = 0
  63. var ChannelDisableThreshold = 5.0
  64. var AutomaticDisableChannelEnabled = false
  65. var QuotaRemindThreshold = 1000
  66. var PreConsumedQuota = 500
  67. var ApproximateTokenEnabled = false
  68. var RetryTimes = 0
  69. var RootUserEmail = ""
  70. var IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
  71. var requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
  72. var RequestInterval = time.Duration(requestInterval) * time.Second
  73. var SyncFrequency = 10 * 60 // unit is second, will be overwritten by SYNC_FREQUENCY
  74. const (
  75. RoleGuestUser = 0
  76. RoleCommonUser = 1
  77. RoleAdminUser = 10
  78. RoleRootUser = 100
  79. )
  80. var (
  81. FileUploadPermission = RoleGuestUser
  82. FileDownloadPermission = RoleGuestUser
  83. ImageUploadPermission = RoleGuestUser
  84. ImageDownloadPermission = RoleGuestUser
  85. )
  86. // All duration's unit is seconds
  87. // Shouldn't larger then RateLimitKeyExpirationDuration
  88. var (
  89. GlobalApiRateLimitNum = 180
  90. GlobalApiRateLimitDuration int64 = 3 * 60
  91. GlobalWebRateLimitNum = 60
  92. GlobalWebRateLimitDuration int64 = 3 * 60
  93. UploadRateLimitNum = 10
  94. UploadRateLimitDuration int64 = 60
  95. DownloadRateLimitNum = 10
  96. DownloadRateLimitDuration int64 = 60
  97. CriticalRateLimitNum = 20
  98. CriticalRateLimitDuration int64 = 20 * 60
  99. )
  100. var RateLimitKeyExpirationDuration = 20 * time.Minute
  101. const (
  102. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  103. UserStatusDisabled = 2 // also don't use 0
  104. )
  105. const (
  106. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  107. TokenStatusDisabled = 2 // also don't use 0
  108. TokenStatusExpired = 3
  109. TokenStatusExhausted = 4
  110. )
  111. const (
  112. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  113. RedemptionCodeStatusDisabled = 2 // also don't use 0
  114. RedemptionCodeStatusUsed = 3 // also don't use 0
  115. )
  116. const (
  117. ChannelStatusUnknown = 0
  118. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  119. ChannelStatusDisabled = 2 // also don't use 0
  120. )
  121. const (
  122. ChannelTypeUnknown = 0
  123. ChannelTypeOpenAI = 1
  124. ChannelTypeAPI2D = 2
  125. ChannelTypeAzure = 3
  126. ChannelTypeCloseAI = 4
  127. ChannelTypeOpenAISB = 5
  128. ChannelTypeOpenAIMax = 6
  129. ChannelTypeOhMyGPT = 7
  130. ChannelTypeCustom = 8
  131. ChannelTypeAILS = 9
  132. ChannelTypeAIProxy = 10
  133. ChannelTypePaLM = 11
  134. ChannelTypeAPI2GPT = 12
  135. ChannelTypeAIGC2D = 13
  136. ChannelTypeAnthropic = 14
  137. ChannelTypeBaidu = 15
  138. ChannelTypeZhipu = 16
  139. ChannelTypeAli = 17
  140. ChannelTypeXunfei = 18
  141. )
  142. var ChannelBaseURLs = []string{
  143. "", // 0
  144. "https://api.openai.com", // 1
  145. "https://oa.api2d.net", // 2
  146. "", // 3
  147. "https://api.closeai-proxy.xyz", // 4
  148. "https://api.openai-sb.com", // 5
  149. "https://api.openaimax.com", // 6
  150. "https://api.ohmygpt.com", // 7
  151. "", // 8
  152. "https://api.caipacity.com", // 9
  153. "https://api.aiproxy.io", // 10
  154. "", // 11
  155. "https://api.api2gpt.com", // 12
  156. "https://api.aigc2d.com", // 13
  157. "https://api.anthropic.com", // 14
  158. "https://aip.baidubce.com", // 15
  159. "https://open.bigmodel.cn", // 16
  160. "https://dashscope.aliyuncs.com", // 17
  161. "", // 18
  162. }