constants.go 6.1 KB

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