constants.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 ServerAddress = "http://localhost:3000"
  13. var PayAddress = ""
  14. var EpayId = ""
  15. var EpayKey = ""
  16. var Price = 7.3
  17. var Footer = ""
  18. var Logo = ""
  19. var TopUpLink = ""
  20. var ChatLink = ""
  21. var QuotaPerUnit = 500 * 1000.0 // $0.002 / 1K tokens
  22. var DisplayInCurrencyEnabled = true
  23. var DisplayTokenStatEnabled = true
  24. var DrawingEnabled = true
  25. var DataExportEnabled = true
  26. var DataExportInterval = 5 // unit: minute
  27. // Any options with "Secret", "Token" in its key won't be return by GetOptions
  28. var SessionSecret = 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 WeChatAuthEnabled = false
  38. var TurnstileCheckEnabled = false
  39. var RegisterEnabled = true
  40. var EmailDomainRestrictionEnabled = 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 SMTPAccount = ""
  58. var SMTPFrom = ""
  59. var SMTPToken = ""
  60. var GitHubClientId = ""
  61. var GitHubClientSecret = ""
  62. var WeChatServerAddress = ""
  63. var WeChatServerToken = ""
  64. var WeChatAccountQRCodeImageURL = ""
  65. var TurnstileSiteKey = ""
  66. var TurnstileSecretKey = ""
  67. var QuotaForNewUser = 0
  68. var QuotaForInviter = 0
  69. var QuotaForInvitee = 0
  70. var ChannelDisableThreshold = 5.0
  71. var AutomaticDisableChannelEnabled = false
  72. var QuotaRemindThreshold = 1000
  73. var PreConsumedQuota = 500
  74. var RetryTimes = 0
  75. var RootUserEmail = ""
  76. var IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
  77. var requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
  78. var RequestInterval = time.Duration(requestInterval) * time.Second
  79. var SyncFrequency = GetOrDefault("SYNC_FREQUENCY", 10*60) // unit is second
  80. var BatchUpdateEnabled = false
  81. var BatchUpdateInterval = GetOrDefault("BATCH_UPDATE_INTERVAL", 5)
  82. var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
  83. var GeminiSafetySetting = GetOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
  84. const (
  85. RequestIdKey = "X-Oneapi-Request-Id"
  86. )
  87. const (
  88. RoleGuestUser = 0
  89. RoleCommonUser = 1
  90. RoleAdminUser = 10
  91. RoleRootUser = 100
  92. )
  93. var (
  94. FileUploadPermission = RoleGuestUser
  95. FileDownloadPermission = RoleGuestUser
  96. ImageUploadPermission = RoleGuestUser
  97. ImageDownloadPermission = RoleGuestUser
  98. )
  99. // All duration's unit is seconds
  100. // Shouldn't larger then RateLimitKeyExpirationDuration
  101. var (
  102. GlobalApiRateLimitNum = GetOrDefault("GLOBAL_API_RATE_LIMIT", 180)
  103. GlobalApiRateLimitDuration int64 = 3 * 60
  104. GlobalWebRateLimitNum = GetOrDefault("GLOBAL_WEB_RATE_LIMIT", 60)
  105. GlobalWebRateLimitDuration int64 = 3 * 60
  106. UploadRateLimitNum = 10
  107. UploadRateLimitDuration int64 = 60
  108. DownloadRateLimitNum = 10
  109. DownloadRateLimitDuration int64 = 60
  110. CriticalRateLimitNum = 20
  111. CriticalRateLimitDuration int64 = 20 * 60
  112. )
  113. var RateLimitKeyExpirationDuration = 20 * time.Minute
  114. const (
  115. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  116. UserStatusDisabled = 2 // also don't use 0
  117. )
  118. const (
  119. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  120. TokenStatusDisabled = 2 // also don't use 0
  121. TokenStatusExpired = 3
  122. TokenStatusExhausted = 4
  123. )
  124. const (
  125. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  126. RedemptionCodeStatusDisabled = 2 // also don't use 0
  127. RedemptionCodeStatusUsed = 3 // also don't use 0
  128. )
  129. const (
  130. ChannelStatusUnknown = 0
  131. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  132. ChannelStatusManuallyDisabled = 2 // also don't use 0
  133. ChannelStatusAutoDisabled = 3
  134. )
  135. const (
  136. ChannelTypeUnknown = 0
  137. ChannelTypeOpenAI = 1
  138. ChannelTypeAPI2D = 2
  139. ChannelTypeAzure = 3
  140. ChannelTypeCloseAI = 4
  141. ChannelTypeOpenAISB = 5
  142. ChannelTypeOpenAIMax = 6
  143. ChannelTypeOhMyGPT = 7
  144. ChannelTypeCustom = 8
  145. ChannelTypeAILS = 9
  146. ChannelTypeAIProxy = 10
  147. ChannelTypePaLM = 11
  148. ChannelTypeAPI2GPT = 12
  149. ChannelTypeAIGC2D = 13
  150. ChannelTypeAnthropic = 14
  151. ChannelTypeBaidu = 15
  152. ChannelTypeZhipu = 16
  153. ChannelTypeAli = 17
  154. ChannelTypeXunfei = 18
  155. ChannelType360 = 19
  156. ChannelTypeOpenRouter = 20
  157. ChannelTypeAIProxyLibrary = 21
  158. ChannelTypeFastGPT = 22
  159. ChannelTypeTencent = 23
  160. ChannelTypeGemini = 24
  161. )
  162. var ChannelBaseURLs = []string{
  163. "", // 0
  164. "https://api.openai.com", // 1
  165. "https://oa.api2d.net", // 2
  166. "", // 3
  167. "https://api.closeai-proxy.xyz", // 4
  168. "https://api.openai-sb.com", // 5
  169. "https://api.openaimax.com", // 6
  170. "https://api.ohmygpt.com", // 7
  171. "", // 8
  172. "https://api.caipacity.com", // 9
  173. "https://api.aiproxy.io", // 10
  174. "", // 11
  175. "https://api.api2gpt.com", // 12
  176. "https://api.aigc2d.com", // 13
  177. "https://api.anthropic.com", // 14
  178. "https://aip.baidubce.com", // 15
  179. "https://open.bigmodel.cn", // 16
  180. "https://dashscope.aliyuncs.com", // 17
  181. "", // 18
  182. "https://ai.360.cn", // 19
  183. "https://openrouter.ai/api", // 20
  184. "https://api.aiproxy.io", // 21
  185. "https://fastgpt.run/api/openapi", // 22
  186. "https://hunyuan.cloud.tencent.com", //23
  187. "", //24
  188. }