constants.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 = "New API"
  12. var Footer = ""
  13. var Logo = ""
  14. var TopUpLink = ""
  15. var ChatLink = ""
  16. var ChatLink2 = ""
  17. var QuotaPerUnit = 500 * 1000.0 // $0.002 / 1K tokens
  18. var DisplayInCurrencyEnabled = true
  19. var DisplayTokenStatEnabled = true
  20. var DrawingEnabled = true
  21. var DataExportEnabled = true
  22. var DataExportInterval = 5 // unit: minute
  23. var DataExportDefaultTime = "hour" // unit: minute
  24. var DefaultCollapseSidebar = false // default value of collapse sidebar
  25. // Any options with "Secret", "Token" in its key won't be return by GetOptions
  26. var SessionSecret = uuid.New().String()
  27. var OptionMap map[string]string
  28. var OptionMapRWMutex sync.RWMutex
  29. var ItemsPerPage = 10
  30. var MaxRecentItems = 100
  31. var PasswordLoginEnabled = true
  32. var PasswordRegisterEnabled = true
  33. var EmailVerificationEnabled = false
  34. var GitHubOAuthEnabled = false
  35. var WeChatAuthEnabled = false
  36. var TelegramOAuthEnabled = false
  37. var TurnstileCheckEnabled = false
  38. var RegisterEnabled = true
  39. var EmailDomainRestrictionEnabled = false // 是否启用邮箱域名限制
  40. var EmailAliasRestrictionEnabled = false // 是否启用邮箱别名限制
  41. var EmailDomainWhitelist = []string{
  42. "gmail.com",
  43. "163.com",
  44. "126.com",
  45. "qq.com",
  46. "outlook.com",
  47. "hotmail.com",
  48. "icloud.com",
  49. "yahoo.com",
  50. "foxmail.com",
  51. }
  52. var DebugEnabled = os.Getenv("DEBUG") == "true"
  53. var MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true"
  54. var LogConsumeEnabled = true
  55. var SMTPServer = ""
  56. var SMTPPort = 587
  57. var SMTPSSLEnabled = false
  58. var SMTPAccount = ""
  59. var SMTPFrom = ""
  60. var SMTPToken = ""
  61. var GitHubClientId = ""
  62. var GitHubClientSecret = ""
  63. var WeChatServerAddress = ""
  64. var WeChatServerToken = ""
  65. var WeChatAccountQRCodeImageURL = ""
  66. var TurnstileSiteKey = ""
  67. var TurnstileSecretKey = ""
  68. var TelegramBotToken = ""
  69. var TelegramBotName = ""
  70. var QuotaForNewUser = 0
  71. var QuotaForInviter = 0
  72. var QuotaForInvitee = 0
  73. var ChannelDisableThreshold = 5.0
  74. var AutomaticDisableChannelEnabled = false
  75. var AutomaticEnableChannelEnabled = false
  76. var QuotaRemindThreshold = 1000
  77. var PreConsumedQuota = 500
  78. var RetryTimes = 0
  79. var RootUserEmail = ""
  80. var IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
  81. var requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
  82. var RequestInterval = time.Duration(requestInterval) * time.Second
  83. var SyncFrequency = GetOrDefault("SYNC_FREQUENCY", 60) // unit is second
  84. var BatchUpdateEnabled = false
  85. var BatchUpdateInterval = GetOrDefault("BATCH_UPDATE_INTERVAL", 5)
  86. var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
  87. var GeminiSafetySetting = GetOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
  88. const (
  89. RequestIdKey = "X-Oneapi-Request-Id"
  90. )
  91. const (
  92. RoleGuestUser = 0
  93. RoleCommonUser = 1
  94. RoleAdminUser = 10
  95. RoleRootUser = 100
  96. )
  97. var (
  98. FileUploadPermission = RoleGuestUser
  99. FileDownloadPermission = RoleGuestUser
  100. ImageUploadPermission = RoleGuestUser
  101. ImageDownloadPermission = RoleGuestUser
  102. )
  103. // All duration's unit is seconds
  104. // Shouldn't larger then RateLimitKeyExpirationDuration
  105. var (
  106. GlobalApiRateLimitNum = GetOrDefault("GLOBAL_API_RATE_LIMIT", 180)
  107. GlobalApiRateLimitDuration int64 = 3 * 60
  108. GlobalWebRateLimitNum = GetOrDefault("GLOBAL_WEB_RATE_LIMIT", 60)
  109. GlobalWebRateLimitDuration int64 = 3 * 60
  110. UploadRateLimitNum = 10
  111. UploadRateLimitDuration int64 = 60
  112. DownloadRateLimitNum = 10
  113. DownloadRateLimitDuration int64 = 60
  114. CriticalRateLimitNum = 20
  115. CriticalRateLimitDuration int64 = 20 * 60
  116. )
  117. var RateLimitKeyExpirationDuration = 20 * time.Minute
  118. const (
  119. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  120. UserStatusDisabled = 2 // also don't use 0
  121. )
  122. const (
  123. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  124. TokenStatusDisabled = 2 // also don't use 0
  125. TokenStatusExpired = 3
  126. TokenStatusExhausted = 4
  127. )
  128. const (
  129. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  130. RedemptionCodeStatusDisabled = 2 // also don't use 0
  131. RedemptionCodeStatusUsed = 3 // also don't use 0
  132. )
  133. const (
  134. ChannelStatusUnknown = 0
  135. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  136. ChannelStatusManuallyDisabled = 2 // also don't use 0
  137. ChannelStatusAutoDisabled = 3
  138. )
  139. const (
  140. ChannelTypeUnknown = 0
  141. ChannelTypeOpenAI = 1
  142. ChannelTypeMidjourney = 2
  143. ChannelTypeAzure = 3
  144. ChannelTypeOllama = 4
  145. ChannelTypeMidjourneyPlus = 5
  146. ChannelTypeOpenAIMax = 6
  147. ChannelTypeOhMyGPT = 7
  148. ChannelTypeCustom = 8
  149. ChannelTypeAILS = 9
  150. ChannelTypeAIProxy = 10
  151. ChannelTypePaLM = 11
  152. ChannelTypeAPI2GPT = 12
  153. ChannelTypeAIGC2D = 13
  154. ChannelTypeAnthropic = 14
  155. ChannelTypeBaidu = 15
  156. ChannelTypeZhipu = 16
  157. ChannelTypeAli = 17
  158. ChannelTypeXunfei = 18
  159. ChannelType360 = 19
  160. ChannelTypeOpenRouter = 20
  161. ChannelTypeAIProxyLibrary = 21
  162. ChannelTypeFastGPT = 22
  163. ChannelTypeTencent = 23
  164. ChannelTypeGemini = 24
  165. ChannelTypeMoonshot = 25
  166. ChannelTypeZhipu_v4 = 26
  167. ChannelTypePerplexity = 27
  168. ChannelTypeLingYiWanWu = 31
  169. ChannelTypeAws = 33
  170. ChannelTypeCohere = 34
  171. ChannelTypeMiniMax = 35
  172. ChannelTypeDummy // this one is only for count, do not add any channel after this
  173. )
  174. var ChannelBaseURLs = []string{
  175. "", // 0
  176. "https://api.openai.com", // 1
  177. "https://oa.api2d.net", // 2
  178. "", // 3
  179. "http://localhost:11434", // 4
  180. "https://api.openai-sb.com", // 5
  181. "https://api.openaimax.com", // 6
  182. "https://api.ohmygpt.com", // 7
  183. "", // 8
  184. "https://api.caipacity.com", // 9
  185. "https://api.aiproxy.io", // 10
  186. "", // 11
  187. "https://api.api2gpt.com", // 12
  188. "https://api.aigc2d.com", // 13
  189. "https://api.anthropic.com", // 14
  190. "https://aip.baidubce.com", // 15
  191. "https://open.bigmodel.cn", // 16
  192. "https://dashscope.aliyuncs.com", // 17
  193. "", // 18
  194. "https://ai.360.cn", // 19
  195. "https://openrouter.ai/api", // 20
  196. "https://api.aiproxy.io", // 21
  197. "https://fastgpt.run/api/openapi", // 22
  198. "https://hunyuan.cloud.tencent.com", //23
  199. "https://generativelanguage.googleapis.com", //24
  200. "https://api.moonshot.cn", //25
  201. "https://open.bigmodel.cn", //26
  202. "https://api.perplexity.ai", //27
  203. "", //28
  204. "", //29
  205. "", //30
  206. "https://api.lingyiwanwu.com", //31
  207. "", //32
  208. "", //33
  209. "https://api.cohere.ai", //34
  210. "https://api.minimax.chat", //35
  211. }