constants.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 NormalPrice = 1.5
  76. var StablePrice = 6.0
  77. var BasePrice = 1.5
  78. const (
  79. RoleGuestUser = 0
  80. RoleCommonUser = 1
  81. RoleAdminUser = 10
  82. RoleRootUser = 100
  83. )
  84. var (
  85. FileUploadPermission = RoleGuestUser
  86. FileDownloadPermission = RoleGuestUser
  87. ImageUploadPermission = RoleGuestUser
  88. ImageDownloadPermission = RoleGuestUser
  89. )
  90. // All duration's unit is seconds
  91. // Shouldn't larger then RateLimitKeyExpirationDuration
  92. var (
  93. GlobalApiRateLimitNum = 180
  94. GlobalApiRateLimitDuration int64 = 3 * 60
  95. GlobalWebRateLimitNum = 60
  96. GlobalWebRateLimitDuration int64 = 3 * 60
  97. UploadRateLimitNum = 10
  98. UploadRateLimitDuration int64 = 60
  99. DownloadRateLimitNum = 10
  100. DownloadRateLimitDuration int64 = 60
  101. CriticalRateLimitNum = 20
  102. CriticalRateLimitDuration int64 = 20 * 60
  103. )
  104. var RateLimitKeyExpirationDuration = 20 * time.Minute
  105. const (
  106. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  107. UserStatusDisabled = 2 // also don't use 0
  108. )
  109. const (
  110. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  111. TokenStatusDisabled = 2 // also don't use 0
  112. TokenStatusExpired = 3
  113. TokenStatusExhausted = 4
  114. )
  115. const (
  116. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  117. RedemptionCodeStatusDisabled = 2 // also don't use 0
  118. RedemptionCodeStatusUsed = 3 // also don't use 0
  119. )
  120. const (
  121. ChannelStatusUnknown = 0
  122. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  123. ChannelStatusDisabled = 2 // also don't use 0
  124. )
  125. const (
  126. ChannelTypeUnknown = 0
  127. ChannelTypeOpenAI = 1
  128. ChannelTypeAPI2D = 2
  129. ChannelTypeAzure = 3
  130. ChannelTypeCloseAI = 4
  131. ChannelTypeOpenAISB = 5
  132. ChannelTypeOpenAIMax = 6
  133. ChannelTypeOhMyGPT = 7
  134. ChannelTypeCustom = 8
  135. ChannelTypeAILS = 9
  136. ChannelTypeAIProxy = 10
  137. ChannelTypePaLM = 11
  138. ChannelTypeAPI2GPT = 12
  139. ChannelTypeAIGC2D = 13
  140. ChannelTypeAnthropic = 14
  141. ChannelTypeBaidu = 15
  142. ChannelTypeZhipu = 16
  143. ChannelTypeAli = 17
  144. ChannelTypeXunfei = 18
  145. )
  146. var ChannelBaseURLs = []string{
  147. "", // 0
  148. "https://api.openai.com", // 1
  149. "https://oa.api2d.net", // 2
  150. "", // 3
  151. "https://api.closeai-proxy.xyz", // 4
  152. "https://api.openai-sb.com", // 5
  153. "https://api.openaimax.com", // 6
  154. "https://api.ohmygpt.com", // 7
  155. "", // 8
  156. "https://api.caipacity.com", // 9
  157. "https://api.aiproxy.io", // 10
  158. "", // 11
  159. "https://api.api2gpt.com", // 12
  160. "https://api.aigc2d.com", // 13
  161. "https://api.anthropic.com", // 14
  162. "https://aip.baidubce.com", // 15
  163. "https://open.bigmodel.cn", // 16
  164. "https://dashscope.aliyuncs.com", // 17
  165. "", // 18
  166. }