constants.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package common
  2. import (
  3. "os"
  4. "sync"
  5. "time"
  6. "github.com/google/uuid"
  7. )
  8. var StartTime = time.Now().Unix() // unit: second
  9. var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
  10. var SystemName = "One API"
  11. var ServerAddress = "http://localhost:3000"
  12. var Footer = ""
  13. var Logo = ""
  14. var TopUpLink = ""
  15. var ChatLink = ""
  16. var QuotaPerUnit = 500 * 1000.0 // $0.002 / 1K tokens
  17. var DisplayInCurrencyEnabled = false
  18. var UsingSQLite = false
  19. // Any options with "Secret", "Token" in its key won't be return by GetOptions
  20. var SessionSecret = uuid.New().String()
  21. var SQLitePath = "one-api.db"
  22. var OptionMap map[string]string
  23. var OptionMapRWMutex sync.RWMutex
  24. var ItemsPerPage = 10
  25. var MaxRecentItems = 100
  26. var PasswordLoginEnabled = true
  27. var PasswordRegisterEnabled = true
  28. var EmailVerificationEnabled = false
  29. var GitHubOAuthEnabled = false
  30. var WeChatAuthEnabled = false
  31. var TurnstileCheckEnabled = false
  32. var RegisterEnabled = true
  33. var LogConsumeEnabled = true
  34. var SMTPServer = ""
  35. var SMTPPort = 587
  36. var SMTPAccount = ""
  37. var SMTPFrom = ""
  38. var SMTPToken = ""
  39. var GitHubClientId = ""
  40. var GitHubClientSecret = ""
  41. var WeChatServerAddress = ""
  42. var WeChatServerToken = ""
  43. var WeChatAccountQRCodeImageURL = ""
  44. var TurnstileSiteKey = ""
  45. var TurnstileSecretKey = ""
  46. var QuotaForNewUser = 0
  47. var QuotaForInviter = 0
  48. var QuotaForInvitee = 0
  49. var ChannelDisableThreshold = 5.0
  50. var AutomaticDisableChannelEnabled = false
  51. var QuotaRemindThreshold = 1000
  52. var PreConsumedQuota = 500
  53. var RootUserEmail = ""
  54. var IsMasterNode = os.Getenv("SYNC_FREQUENCY") == ""
  55. const (
  56. RoleGuestUser = 0
  57. RoleCommonUser = 1
  58. RoleAdminUser = 10
  59. RoleRootUser = 100
  60. )
  61. var (
  62. FileUploadPermission = RoleGuestUser
  63. FileDownloadPermission = RoleGuestUser
  64. ImageUploadPermission = RoleGuestUser
  65. ImageDownloadPermission = RoleGuestUser
  66. )
  67. // All duration's unit is seconds
  68. // Shouldn't larger then RateLimitKeyExpirationDuration
  69. var (
  70. GlobalApiRateLimitNum = 180
  71. GlobalApiRateLimitDuration int64 = 3 * 60
  72. GlobalWebRateLimitNum = 60
  73. GlobalWebRateLimitDuration int64 = 3 * 60
  74. UploadRateLimitNum = 10
  75. UploadRateLimitDuration int64 = 60
  76. DownloadRateLimitNum = 10
  77. DownloadRateLimitDuration int64 = 60
  78. CriticalRateLimitNum = 20
  79. CriticalRateLimitDuration int64 = 20 * 60
  80. )
  81. var RateLimitKeyExpirationDuration = 20 * time.Minute
  82. const (
  83. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  84. UserStatusDisabled = 2 // also don't use 0
  85. )
  86. const (
  87. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  88. TokenStatusDisabled = 2 // also don't use 0
  89. TokenStatusExpired = 3
  90. TokenStatusExhausted = 4
  91. )
  92. const (
  93. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  94. RedemptionCodeStatusDisabled = 2 // also don't use 0
  95. RedemptionCodeStatusUsed = 3 // also don't use 0
  96. )
  97. const (
  98. ChannelStatusUnknown = 0
  99. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  100. ChannelStatusDisabled = 2 // also don't use 0
  101. )
  102. const (
  103. ChannelTypeUnknown = 0
  104. ChannelTypeOpenAI = 1
  105. ChannelTypeAPI2D = 2
  106. ChannelTypeAzure = 3
  107. ChannelTypeCloseAI = 4
  108. ChannelTypeOpenAISB = 5
  109. ChannelTypeOpenAIMax = 6
  110. ChannelTypeOhMyGPT = 7
  111. ChannelTypeCustom = 8
  112. ChannelTypeAILS = 9
  113. ChannelTypeAIProxy = 10
  114. ChannelTypePaLM = 11
  115. ChannelTypeAPI2GPT = 12
  116. )
  117. var ChannelBaseURLs = []string{
  118. "", // 0
  119. "https://api.openai.com", // 1
  120. "https://oa.api2d.net", // 2
  121. "", // 3
  122. "https://api.openai-proxy.org", // 4
  123. "https://api.openai-sb.com", // 5
  124. "https://api.openaimax.com", // 6
  125. "https://api.ohmygpt.com", // 7
  126. "", // 8
  127. "https://api.caipacity.com", // 9
  128. "https://api.aiproxy.io", // 10
  129. "", // 11
  130. "https://api.api2gpt.com", // 12
  131. }