constants.go 8.3 KB

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