constants.go 6.9 KB

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