constants.go 5.7 KB

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