constants.go 4.6 KB

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