constants.go 6.5 KB

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