constants.go 6.3 KB

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