constants.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. // Any options with "Secret", "Token" in its key won't be return by GetOptions
  21. var SessionSecret = uuid.New().String()
  22. var OptionMap map[string]string
  23. var OptionMapRWMutex sync.RWMutex
  24. var ItemsPerPage = 10
  25. var MaxRecentItems = 100
  26. var PasswordLoginEnabled = true
  27. var PasswordRegisterEnabled = true
  28. var EmailVerificationEnabled = false
  29. var GitHubOAuthEnabled = false
  30. var WeChatAuthEnabled = false
  31. var TurnstileCheckEnabled = false
  32. var RegisterEnabled = true
  33. var EmailDomainRestrictionEnabled = false
  34. var EmailDomainWhitelist = []string{
  35. "gmail.com",
  36. "163.com",
  37. "126.com",
  38. "qq.com",
  39. "outlook.com",
  40. "hotmail.com",
  41. "icloud.com",
  42. "yahoo.com",
  43. "foxmail.com",
  44. }
  45. var DebugEnabled = os.Getenv("DEBUG") == "true"
  46. var MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true"
  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 = GetOrDefault("SYNC_FREQUENCY", 10*60) // unit is second
  74. var BatchUpdateEnabled = false
  75. var BatchUpdateInterval = GetOrDefault("BATCH_UPDATE_INTERVAL", 5)
  76. var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
  77. const (
  78. RequestIdKey = "X-Oneapi-Request-Id"
  79. )
  80. const (
  81. RoleGuestUser = 0
  82. RoleCommonUser = 1
  83. RoleAdminUser = 10
  84. RoleRootUser = 100
  85. )
  86. var (
  87. FileUploadPermission = RoleGuestUser
  88. FileDownloadPermission = RoleGuestUser
  89. ImageUploadPermission = RoleGuestUser
  90. ImageDownloadPermission = RoleGuestUser
  91. )
  92. // All duration's unit is seconds
  93. // Shouldn't larger then RateLimitKeyExpirationDuration
  94. var (
  95. GlobalApiRateLimitNum = GetOrDefault("GLOBAL_API_RATE_LIMIT", 180)
  96. GlobalApiRateLimitDuration int64 = 3 * 60
  97. GlobalWebRateLimitNum = GetOrDefault("GLOBAL_WEB_RATE_LIMIT", 60)
  98. GlobalWebRateLimitDuration int64 = 3 * 60
  99. UploadRateLimitNum = 10
  100. UploadRateLimitDuration int64 = 60
  101. DownloadRateLimitNum = 10
  102. DownloadRateLimitDuration int64 = 60
  103. CriticalRateLimitNum = 20
  104. CriticalRateLimitDuration int64 = 20 * 60
  105. )
  106. var RateLimitKeyExpirationDuration = 20 * time.Minute
  107. const (
  108. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  109. UserStatusDisabled = 2 // also don't use 0
  110. )
  111. const (
  112. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  113. TokenStatusDisabled = 2 // also don't use 0
  114. TokenStatusExpired = 3
  115. TokenStatusExhausted = 4
  116. )
  117. const (
  118. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  119. RedemptionCodeStatusDisabled = 2 // also don't use 0
  120. RedemptionCodeStatusUsed = 3 // also don't use 0
  121. )
  122. const (
  123. ChannelStatusUnknown = 0
  124. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  125. ChannelStatusManuallyDisabled = 2 // also don't use 0
  126. ChannelStatusAutoDisabled = 3
  127. )
  128. const (
  129. ChannelTypeUnknown = 0
  130. ChannelTypeOpenAI = 1
  131. ChannelTypeAPI2D = 2
  132. ChannelTypeAzure = 3
  133. ChannelTypeCloseAI = 4
  134. ChannelTypeOpenAISB = 5
  135. ChannelTypeOpenAIMax = 6
  136. ChannelTypeOhMyGPT = 7
  137. ChannelTypeCustom = 8
  138. ChannelTypeAILS = 9
  139. ChannelTypeAIProxy = 10
  140. ChannelTypePaLM = 11
  141. ChannelTypeAPI2GPT = 12
  142. ChannelTypeAIGC2D = 13
  143. ChannelTypeAnthropic = 14
  144. ChannelTypeBaidu = 15
  145. ChannelTypeZhipu = 16
  146. ChannelTypeAli = 17
  147. ChannelTypeXunfei = 18
  148. ChannelType360 = 19
  149. ChannelTypeOpenRouter = 20
  150. ChannelTypeAIProxyLibrary = 21
  151. ChannelTypeFastGPT = 22
  152. ChannelTypeTencent = 23
  153. )
  154. var ChannelBaseURLs = []string{
  155. "", // 0
  156. "https://api.openai.com", // 1
  157. "https://oa.api2d.net", // 2
  158. "", // 3
  159. "https://api.closeai-proxy.xyz", // 4
  160. "https://api.openai-sb.com", // 5
  161. "https://api.openaimax.com", // 6
  162. "https://api.ohmygpt.com", // 7
  163. "", // 8
  164. "https://api.caipacity.com", // 9
  165. "https://api.aiproxy.io", // 10
  166. "", // 11
  167. "https://api.api2gpt.com", // 12
  168. "https://api.aigc2d.com", // 13
  169. "https://api.anthropic.com", // 14
  170. "https://aip.baidubce.com", // 15
  171. "https://open.bigmodel.cn", // 16
  172. "https://dashscope.aliyuncs.com", // 17
  173. "", // 18
  174. "https://ai.360.cn", // 19
  175. "https://openrouter.ai/api", // 20
  176. "https://api.aiproxy.io", // 21
  177. "https://fastgpt.run/api/openapi", // 22
  178. "https://hunyuan.cloud.tencent.com", //23
  179. }