constants.go 6.1 KB

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