constants.go 3.8 KB

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