constants.go 8.1 KB

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