constants.go 6.4 KB

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