constants.go 8.3 KB

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