constants.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 RootUserEmail = ""
  57. var IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
  58. var requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
  59. var RequestInterval = time.Duration(requestInterval) * time.Second
  60. const (
  61. RoleGuestUser = 0
  62. RoleCommonUser = 1
  63. RoleAdminUser = 10
  64. RoleRootUser = 100
  65. )
  66. var (
  67. FileUploadPermission = RoleGuestUser
  68. FileDownloadPermission = RoleGuestUser
  69. ImageUploadPermission = RoleGuestUser
  70. ImageDownloadPermission = RoleGuestUser
  71. )
  72. // All duration's unit is seconds
  73. // Shouldn't larger then RateLimitKeyExpirationDuration
  74. var (
  75. GlobalApiRateLimitNum = 180
  76. GlobalApiRateLimitDuration int64 = 3 * 60
  77. GlobalWebRateLimitNum = 60
  78. GlobalWebRateLimitDuration int64 = 3 * 60
  79. UploadRateLimitNum = 10
  80. UploadRateLimitDuration int64 = 60
  81. DownloadRateLimitNum = 10
  82. DownloadRateLimitDuration int64 = 60
  83. CriticalRateLimitNum = 20
  84. CriticalRateLimitDuration int64 = 20 * 60
  85. )
  86. var RateLimitKeyExpirationDuration = 20 * time.Minute
  87. const (
  88. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  89. UserStatusDisabled = 2 // also don't use 0
  90. )
  91. const (
  92. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  93. TokenStatusDisabled = 2 // also don't use 0
  94. TokenStatusExpired = 3
  95. TokenStatusExhausted = 4
  96. )
  97. const (
  98. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  99. RedemptionCodeStatusDisabled = 2 // also don't use 0
  100. RedemptionCodeStatusUsed = 3 // also don't use 0
  101. )
  102. const (
  103. ChannelStatusUnknown = 0
  104. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  105. ChannelStatusDisabled = 2 // also don't use 0
  106. )
  107. const (
  108. ChannelTypeUnknown = 0
  109. ChannelTypeOpenAI = 1
  110. ChannelTypeAPI2D = 2
  111. ChannelTypeAzure = 3
  112. ChannelTypeCloseAI = 4
  113. ChannelTypeOpenAISB = 5
  114. ChannelTypeOpenAIMax = 6
  115. ChannelTypeOhMyGPT = 7
  116. ChannelTypeCustom = 8
  117. ChannelTypeAILS = 9
  118. ChannelTypeAIProxy = 10
  119. ChannelTypePaLM = 11
  120. ChannelTypeAPI2GPT = 12
  121. ChannelTypeAIGC2D = 13
  122. )
  123. var ChannelBaseURLs = []string{
  124. "", // 0
  125. "https://api.openai.com", // 1
  126. "https://oa.api2d.net", // 2
  127. "", // 3
  128. "https://api.closeai-proxy.xyz", // 4
  129. "https://api.openai-sb.com", // 5
  130. "https://api.openaimax.com", // 6
  131. "https://api.ohmygpt.com", // 7
  132. "", // 8
  133. "https://api.caipacity.com", // 9
  134. "https://api.aiproxy.io", // 10
  135. "", // 11
  136. "https://api.api2gpt.com", // 12
  137. "https://api.aigc2d.com", // 13
  138. }