constants.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. const (
  84. RequestIdKey = "X-Oneapi-Request-Id"
  85. )
  86. const (
  87. RoleGuestUser = 0
  88. RoleCommonUser = 1
  89. RoleAdminUser = 10
  90. RoleRootUser = 100
  91. )
  92. var (
  93. FileUploadPermission = RoleGuestUser
  94. FileDownloadPermission = RoleGuestUser
  95. ImageUploadPermission = RoleGuestUser
  96. ImageDownloadPermission = RoleGuestUser
  97. )
  98. // All duration's unit is seconds
  99. // Shouldn't larger then RateLimitKeyExpirationDuration
  100. var (
  101. GlobalApiRateLimitNum = GetOrDefault("GLOBAL_API_RATE_LIMIT", 180)
  102. GlobalApiRateLimitDuration int64 = 3 * 60
  103. GlobalWebRateLimitNum = GetOrDefault("GLOBAL_WEB_RATE_LIMIT", 60)
  104. GlobalWebRateLimitDuration int64 = 3 * 60
  105. UploadRateLimitNum = 10
  106. UploadRateLimitDuration int64 = 60
  107. DownloadRateLimitNum = 10
  108. DownloadRateLimitDuration int64 = 60
  109. CriticalRateLimitNum = 20
  110. CriticalRateLimitDuration int64 = 20 * 60
  111. )
  112. var RateLimitKeyExpirationDuration = 20 * time.Minute
  113. const (
  114. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  115. UserStatusDisabled = 2 // also don't use 0
  116. )
  117. const (
  118. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  119. TokenStatusDisabled = 2 // also don't use 0
  120. TokenStatusExpired = 3
  121. TokenStatusExhausted = 4
  122. )
  123. const (
  124. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  125. RedemptionCodeStatusDisabled = 2 // also don't use 0
  126. RedemptionCodeStatusUsed = 3 // also don't use 0
  127. )
  128. const (
  129. ChannelStatusUnknown = 0
  130. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  131. ChannelStatusManuallyDisabled = 2 // also don't use 0
  132. ChannelStatusAutoDisabled = 3
  133. )
  134. const (
  135. ChannelTypeUnknown = 0
  136. ChannelTypeOpenAI = 1
  137. ChannelTypeAPI2D = 2
  138. ChannelTypeAzure = 3
  139. ChannelTypeCloseAI = 4
  140. ChannelTypeOpenAISB = 5
  141. ChannelTypeOpenAIMax = 6
  142. ChannelTypeOhMyGPT = 7
  143. ChannelTypeCustom = 8
  144. ChannelTypeAILS = 9
  145. ChannelTypeAIProxy = 10
  146. ChannelTypePaLM = 11
  147. ChannelTypeAPI2GPT = 12
  148. ChannelTypeAIGC2D = 13
  149. ChannelTypeAnthropic = 14
  150. ChannelTypeBaidu = 15
  151. ChannelTypeZhipu = 16
  152. ChannelTypeAli = 17
  153. ChannelTypeXunfei = 18
  154. ChannelType360 = 19
  155. ChannelTypeOpenRouter = 20
  156. ChannelTypeAIProxyLibrary = 21
  157. ChannelTypeFastGPT = 22
  158. ChannelTypeTencent = 23
  159. ChannelTypeGemini = 24
  160. )
  161. var ChannelBaseURLs = []string{
  162. "", // 0
  163. "https://api.openai.com", // 1
  164. "https://oa.api2d.net", // 2
  165. "", // 3
  166. "https://api.closeai-proxy.xyz", // 4
  167. "https://api.openai-sb.com", // 5
  168. "https://api.openaimax.com", // 6
  169. "https://api.ohmygpt.com", // 7
  170. "", // 8
  171. "https://api.caipacity.com", // 9
  172. "https://api.aiproxy.io", // 10
  173. "", // 11
  174. "https://api.api2gpt.com", // 12
  175. "https://api.aigc2d.com", // 13
  176. "https://api.anthropic.com", // 14
  177. "https://aip.baidubce.com", // 15
  178. "https://open.bigmodel.cn", // 16
  179. "https://dashscope.aliyuncs.com", // 17
  180. "", // 18
  181. "https://ai.360.cn", // 19
  182. "https://openrouter.ai/api", // 20
  183. "https://api.aiproxy.io", // 21
  184. "https://fastgpt.run/api/openapi", // 22
  185. "https://hunyuan.cloud.tencent.com", //23
  186. "", //24
  187. }