constants.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 TelegramOAuthEnabled = false
  45. var TurnstileCheckEnabled = false
  46. var RegisterEnabled = true
  47. var EmailDomainRestrictionEnabled = false // 是否启用邮箱域名限制
  48. var EmailAliasRestrictionEnabled = false // 是否启用邮箱别名限制
  49. var EmailDomainWhitelist = []string{
  50. "gmail.com",
  51. "163.com",
  52. "126.com",
  53. "qq.com",
  54. "outlook.com",
  55. "hotmail.com",
  56. "icloud.com",
  57. "yahoo.com",
  58. "foxmail.com",
  59. }
  60. var DebugEnabled = os.Getenv("DEBUG") == "true"
  61. var MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true"
  62. var LogConsumeEnabled = true
  63. var SMTPServer = ""
  64. var SMTPPort = 587
  65. var SMTPSSLEnabled = false
  66. var SMTPAccount = ""
  67. var SMTPFrom = ""
  68. var SMTPToken = ""
  69. var GitHubClientId = ""
  70. var GitHubClientSecret = ""
  71. var WeChatServerAddress = ""
  72. var WeChatServerToken = ""
  73. var WeChatAccountQRCodeImageURL = ""
  74. var TurnstileSiteKey = ""
  75. var TurnstileSecretKey = ""
  76. var TelegramBotToken = ""
  77. var TelegramBotName = ""
  78. var QuotaForNewUser = 0
  79. var QuotaForInviter = 0
  80. var QuotaForInvitee = 0
  81. var ChannelDisableThreshold = 5.0
  82. var AutomaticDisableChannelEnabled = false
  83. var AutomaticEnableChannelEnabled = false
  84. var QuotaRemindThreshold = 1000
  85. var PreConsumedQuota = 500
  86. var RetryTimes = 0
  87. var RootUserEmail = ""
  88. var IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
  89. var requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
  90. var RequestInterval = time.Duration(requestInterval) * time.Second
  91. var SyncFrequency = GetOrDefault("SYNC_FREQUENCY", 60) // unit is second
  92. var BatchUpdateEnabled = false
  93. var BatchUpdateInterval = GetOrDefault("BATCH_UPDATE_INTERVAL", 5)
  94. var RelayTimeout = GetOrDefault("RELAY_TIMEOUT", 0) // unit is second
  95. var GeminiSafetySetting = GetOrDefaultString("GEMINI_SAFETY_SETTING", "BLOCK_NONE")
  96. const (
  97. RequestIdKey = "X-Oneapi-Request-Id"
  98. )
  99. const (
  100. RoleGuestUser = 0
  101. RoleCommonUser = 1
  102. RoleAdminUser = 10
  103. RoleRootUser = 100
  104. )
  105. var (
  106. FileUploadPermission = RoleGuestUser
  107. FileDownloadPermission = RoleGuestUser
  108. ImageUploadPermission = RoleGuestUser
  109. ImageDownloadPermission = RoleGuestUser
  110. )
  111. // All duration's unit is seconds
  112. // Shouldn't larger then RateLimitKeyExpirationDuration
  113. var (
  114. GlobalApiRateLimitNum = GetOrDefault("GLOBAL_API_RATE_LIMIT", 180)
  115. GlobalApiRateLimitDuration int64 = 3 * 60
  116. GlobalWebRateLimitNum = GetOrDefault("GLOBAL_WEB_RATE_LIMIT", 60)
  117. GlobalWebRateLimitDuration int64 = 3 * 60
  118. UploadRateLimitNum = 10
  119. UploadRateLimitDuration int64 = 60
  120. DownloadRateLimitNum = 10
  121. DownloadRateLimitDuration int64 = 60
  122. CriticalRateLimitNum = 20
  123. CriticalRateLimitDuration int64 = 20 * 60
  124. )
  125. var RateLimitKeyExpirationDuration = 20 * time.Minute
  126. const (
  127. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  128. UserStatusDisabled = 2 // also don't use 0
  129. )
  130. const (
  131. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  132. TokenStatusDisabled = 2 // also don't use 0
  133. TokenStatusExpired = 3
  134. TokenStatusExhausted = 4
  135. )
  136. const (
  137. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  138. RedemptionCodeStatusDisabled = 2 // also don't use 0
  139. RedemptionCodeStatusUsed = 3 // also don't use 0
  140. )
  141. const (
  142. ChannelStatusUnknown = 0
  143. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  144. ChannelStatusManuallyDisabled = 2 // also don't use 0
  145. ChannelStatusAutoDisabled = 3
  146. )
  147. const (
  148. ChannelTypeUnknown = 0
  149. ChannelTypeOpenAI = 1
  150. ChannelTypeMidjourney = 2
  151. ChannelTypeAzure = 3
  152. ChannelTypeOllama = 4
  153. ChannelTypeMidjourneyPlus = 5
  154. ChannelTypeOpenAIMax = 6
  155. ChannelTypeOhMyGPT = 7
  156. ChannelTypeCustom = 8
  157. ChannelTypeAILS = 9
  158. ChannelTypeAIProxy = 10
  159. ChannelTypePaLM = 11
  160. ChannelTypeAPI2GPT = 12
  161. ChannelTypeAIGC2D = 13
  162. ChannelTypeAnthropic = 14
  163. ChannelTypeBaidu = 15
  164. ChannelTypeZhipu = 16
  165. ChannelTypeAli = 17
  166. ChannelTypeXunfei = 18
  167. ChannelType360 = 19
  168. ChannelTypeOpenRouter = 20
  169. ChannelTypeAIProxyLibrary = 21
  170. ChannelTypeFastGPT = 22
  171. ChannelTypeTencent = 23
  172. ChannelTypeGemini = 24
  173. ChannelTypeMoonshot = 25
  174. ChannelTypeZhipu_v4 = 26
  175. ChannelTypePerplexity = 27
  176. ChannelTypeLingYiWanWu = 31
  177. )
  178. var ChannelBaseURLs = []string{
  179. "", // 0
  180. "https://api.openai.com", // 1
  181. "https://oa.api2d.net", // 2
  182. "", // 3
  183. "http://localhost:11434", // 4
  184. "https://api.openai-sb.com", // 5
  185. "https://api.openaimax.com", // 6
  186. "https://api.ohmygpt.com", // 7
  187. "", // 8
  188. "https://api.caipacity.com", // 9
  189. "https://api.aiproxy.io", // 10
  190. "", // 11
  191. "https://api.api2gpt.com", // 12
  192. "https://api.aigc2d.com", // 13
  193. "https://api.anthropic.com", // 14
  194. "https://aip.baidubce.com", // 15
  195. "https://open.bigmodel.cn", // 16
  196. "https://dashscope.aliyuncs.com", // 17
  197. "", // 18
  198. "https://ai.360.cn", // 19
  199. "https://openrouter.ai/api", // 20
  200. "https://api.aiproxy.io", // 21
  201. "https://fastgpt.run/api/openapi", // 22
  202. "https://hunyuan.cloud.tencent.com", //23
  203. "https://generativelanguage.googleapis.com", //24
  204. "https://api.moonshot.cn", //25
  205. "https://open.bigmodel.cn", //26
  206. "https://api.perplexity.ai", //27
  207. "", //28
  208. "", //29
  209. "", //30
  210. "https://api.lingyiwanwu.com", //31
  211. }