constants.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 = "One API"
  12. var ServerAddress = "http://localhost:3000"
  13. var Footer = ""
  14. var Logo = ""
  15. var TopUpLink = ""
  16. var ChatLink = ""
  17. var QuotaPerUnit = 500 * 1000.0 // $0.002 / 1K tokens
  18. var DisplayInCurrencyEnabled = true
  19. var DisplayTokenStatEnabled = true
  20. var UsingSQLite = false
  21. // Any options with "Secret", "Token" in its key won't be return by GetOptions
  22. var SessionSecret = uuid.New().String()
  23. var SQLitePath = "one-api.db"
  24. var OptionMap map[string]string
  25. var OptionMapRWMutex sync.RWMutex
  26. var ItemsPerPage = 10
  27. var MaxRecentItems = 100
  28. var PasswordLoginEnabled = true
  29. var PasswordRegisterEnabled = true
  30. var EmailVerificationEnabled = false
  31. var GitHubOAuthEnabled = false
  32. var WeChatAuthEnabled = false
  33. var TurnstileCheckEnabled = false
  34. var RegisterEnabled = true
  35. var LogConsumeEnabled = true
  36. var SMTPServer = ""
  37. var SMTPPort = 587
  38. var SMTPAccount = ""
  39. var SMTPFrom = ""
  40. var SMTPToken = ""
  41. var GitHubClientId = ""
  42. var GitHubClientSecret = ""
  43. var WeChatServerAddress = ""
  44. var WeChatServerToken = ""
  45. var WeChatAccountQRCodeImageURL = ""
  46. var TurnstileSiteKey = ""
  47. var TurnstileSecretKey = ""
  48. var QuotaForNewUser = 0
  49. var QuotaForInviter = 0
  50. var QuotaForInvitee = 0
  51. var ChannelDisableThreshold = 5.0
  52. var AutomaticDisableChannelEnabled = false
  53. var QuotaRemindThreshold = 1000
  54. var PreConsumedQuota = 500
  55. var ApproximateTokenEnabled = false
  56. var RetryTimes = 0
  57. var RootUserEmail = ""
  58. var IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
  59. var requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
  60. var RequestInterval = time.Duration(requestInterval) * time.Second
  61. var SyncFrequency = 10 * 60 // unit is second, will be overwritten by SYNC_FREQUENCY
  62. var NormalPrice = 1.5
  63. var StablePrice = 6.0
  64. var BasePrice = 1.5
  65. const (
  66. RoleGuestUser = 0
  67. RoleCommonUser = 1
  68. RoleAdminUser = 10
  69. RoleRootUser = 100
  70. )
  71. var (
  72. FileUploadPermission = RoleGuestUser
  73. FileDownloadPermission = RoleGuestUser
  74. ImageUploadPermission = RoleGuestUser
  75. ImageDownloadPermission = RoleGuestUser
  76. )
  77. // All duration's unit is seconds
  78. // Shouldn't larger then RateLimitKeyExpirationDuration
  79. var (
  80. GlobalApiRateLimitNum = 180
  81. GlobalApiRateLimitDuration int64 = 3 * 60
  82. GlobalWebRateLimitNum = 60
  83. GlobalWebRateLimitDuration int64 = 3 * 60
  84. UploadRateLimitNum = 10
  85. UploadRateLimitDuration int64 = 60
  86. DownloadRateLimitNum = 10
  87. DownloadRateLimitDuration int64 = 60
  88. CriticalRateLimitNum = 20
  89. CriticalRateLimitDuration int64 = 20 * 60
  90. )
  91. var RateLimitKeyExpirationDuration = 20 * time.Minute
  92. const (
  93. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  94. UserStatusDisabled = 2 // also don't use 0
  95. )
  96. const (
  97. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  98. TokenStatusDisabled = 2 // also don't use 0
  99. TokenStatusExpired = 3
  100. TokenStatusExhausted = 4
  101. )
  102. const (
  103. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  104. RedemptionCodeStatusDisabled = 2 // also don't use 0
  105. RedemptionCodeStatusUsed = 3 // also don't use 0
  106. )
  107. const (
  108. ChannelStatusUnknown = 0
  109. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  110. ChannelStatusDisabled = 2 // also don't use 0
  111. )
  112. const (
  113. ChannelTypeUnknown = 0
  114. ChannelTypeOpenAI = 1
  115. ChannelTypeAPI2D = 2
  116. ChannelTypeAzure = 3
  117. ChannelTypeCloseAI = 4
  118. ChannelTypeOpenAISB = 5
  119. ChannelTypeOpenAIMax = 6
  120. ChannelTypeOhMyGPT = 7
  121. ChannelTypeCustom = 8
  122. ChannelTypeAILS = 9
  123. ChannelTypeAIProxy = 10
  124. ChannelTypePaLM = 11
  125. ChannelTypeAPI2GPT = 12
  126. ChannelTypeAIGC2D = 13
  127. ChannelTypeAnthropic = 14
  128. ChannelTypeBaidu = 15
  129. ChannelTypeZhipu = 16
  130. )
  131. var ChannelBaseURLs = []string{
  132. "", // 0
  133. "https://api.openai.com", // 1
  134. "https://oa.api2d.net", // 2
  135. "", // 3
  136. "https://api.closeai-proxy.xyz", // 4
  137. "https://api.openai-sb.com", // 5
  138. "https://api.openaimax.com", // 6
  139. "https://api.ohmygpt.com", // 7
  140. "", // 8
  141. "https://api.caipacity.com", // 9
  142. "https://api.aiproxy.io", // 10
  143. "", // 11
  144. "https://api.api2gpt.com", // 12
  145. "https://api.aigc2d.com", // 13
  146. "https://api.anthropic.com", // 14
  147. "https://aip.baidubce.com", // 15
  148. "https://open.bigmodel.cn", // 16
  149. }