Versions in this module Expand all Collapse all v0 v0.0.1 Feb 6, 2025 Changes in this version + const BatchUpdateTypeChannelUsedQuota + const BatchUpdateTypeCount + const BatchUpdateTypeRequestCount + const BatchUpdateTypeTokenQuota + const BatchUpdateTypeUsedQuota + const BatchUpdateTypeUserQuota + const ChannelStatusAutoDisabled + const ChannelStatusEnabled + const ChannelStatusManuallyDisabled + const ChannelStatusUnknown + const LogTypeConsume + const LogTypeManage + const LogTypeSystem + const LogTypeTopup + const LogTypeUnknown + const RedemptionCodeStatusDisabled + const RedemptionCodeStatusEnabled + const RedemptionCodeStatusUsed + const RoleAdminUser + const RoleCommonUser + const RoleGuestUser + const RoleRootUser + const TokenStatusDisabled + const TokenStatusEnabled + const TokenStatusExhausted + const TokenStatusExpired + const UserStatusDeleted + const UserStatusDisabled + const UserStatusEnabled + var DB *gorm.DB + var GroupModelsCacheSeconds = config.SyncFrequency + var LOG_DB *gorm.DB + var TokenCacheSeconds = config.SyncFrequency + var UserId2GroupCacheSeconds = config.SyncFrequency + var UserId2QuotaCacheSeconds = config.SyncFrequency + var UserId2StatusCacheSeconds = config.SyncFrequency + func BatchInsertChannels(channels []Channel) error + func CacheDecreaseUserQuota(id int, quota int64) error + func CacheGetGroupModels(ctx context.Context, group string) ([]string, error) + func CacheGetUserGroup(id int) (group string, err error) + func CacheGetUserQuota(ctx context.Context, id int) (quota int64, err error) + func CacheIsUserEnabled(userId int) (bool, error) + func CacheUpdateUserQuota(ctx context.Context, id int) error + func CloseDB() error + func CreateRootAccountIfNeed() error + func DecreaseTokenQuota(id int, quota int64) (err error) + func DecreaseUserQuota(id int, quota int64) (err error) + func DeleteChannelByStatus(status int64) (int64, error) + func DeleteDisabledChannel() (int64, error) + func DeleteOldLog(targetTimestamp int64) (int64, error) + func DeleteRedemptionById(id int) (err error) + func DeleteTokenById(id int, userId int) (err error) + func DeleteUserById(id int) (err error) + func GetGroupModels(ctx context.Context, group string) ([]string, error) + func GetMaxUserId() int + func GetRootUserEmail() (email string) + func GetUserEmail(id int) (email string, err error) + func GetUserGroup(id int) (group string, err error) + func GetUserIdByAffCode(affCode string) (int, error) + func GetUserQuota(id int) (quota int64, err error) + func GetUserUsedQuota(id int) (quota int64, err error) + func GetUsernameById(id int) (username string) + func IncreaseTokenQuota(id int, quota int64) (err error) + func IncreaseUserQuota(id int, quota int64) (err error) + func InitBatchUpdater() + func InitChannelCache() + func InitDB() + func InitLogDB() + func InitOptionMap() + func IsAdmin(userId int) bool + func IsEmailAlreadyTaken(email string) bool + func IsGitHubIdAlreadyTaken(githubId string) bool + func IsLarkIdAlreadyTaken(githubId string) bool + func IsOidcIdAlreadyTaken(oidcId string) bool + func IsUserEnabled(userId int) (bool, error) + func IsUsernameAlreadyTaken(username string) bool + func IsWeChatIdAlreadyTaken(wechatId string) bool + func PostConsumeTokenQuota(tokenId int, quota int64) (err error) + func PreConsumeTokenQuota(tokenId int, quota int64) (err error) + func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptTokens int, ...) + func RecordLog(userId int, logType int, content string) + func RecordTopupLog(userId int, content string, quota int) + func Redeem(key string, userId int) (quota int64, err error) + func ResetUserPasswordByEmail(email string, password string) error + func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, ...) (quota int64) + func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelName string, ...) (token int) + func SyncChannelCache(frequency int) + func SyncOptions(frequency int) + func UpdateAbilityStatus(channelId int, status bool) error + func UpdateChannelStatusById(id int, status int) + func UpdateChannelUsedQuota(id int, quota int64) + func UpdateOption(key string, value string) error + func UpdateUserUsedQuotaAndRequestCount(id int, quota int64) + type Ability struct + ChannelId int + Enabled bool + Group string + Model string + Priority *int64 + type Channel struct + Balance float64 + BalanceUpdatedTime int64 + BaseURL *string + Config string + CreatedTime int64 + Group string + Id int + Key string + ModelMapping *string + Models string + Name string + Other *string + Priority *int64 + ResponseTime int + Status int + SystemPrompt *string + TestTime int64 + Type int + UsedQuota int64 + Weight *uint + func CacheGetRandomSatisfiedChannel(group string, model string, ignoreFirstPriority bool) (*Channel, error) + func GetAllChannels(startIdx int, num int, scope string) ([]*Channel, error) + func GetChannelById(id int, selectAll bool) (*Channel, error) + func GetRandomSatisfiedChannel(group string, model string, ignoreFirstPriority bool) (*Channel, error) + func SearchChannels(keyword string) (channels []*Channel, err error) + func (channel *Channel) AddAbilities() error + func (channel *Channel) Delete() error + func (channel *Channel) DeleteAbilities() error + func (channel *Channel) GetBaseURL() string + func (channel *Channel) GetModelMapping() map[string]string + func (channel *Channel) GetPriority() int64 + func (channel *Channel) Insert() error + func (channel *Channel) LoadConfig() (ChannelConfig, error) + func (channel *Channel) Update() error + func (channel *Channel) UpdateAbilities() error + func (channel *Channel) UpdateBalance(balance float64) + func (channel *Channel) UpdateResponseTime(responseTime int64) + type ChannelConfig struct + AK string + APIVersion string + LibraryID string + Plugin string + Region string + SK string + UserID string + VertexAIADC string + VertexAIProjectID string + type Log struct + ChannelId int + CompletionTokens int + Content string + CreatedAt int64 + Id int + ModelName string + PromptTokens int + Quota int + TokenName string + Type int + UserId int + Username string + func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName string, ...) (logs []*Log, err error) + func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int64, ...) (logs []*Log, err error) + func SearchAllLogs(keyword string) (logs []*Log, err error) + func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) + type LogStatistic struct + CompletionTokens int + Day string + ModelName string + PromptTokens int + Quota int + RequestCount int + func SearchLogsByDayAndModel(userId, start, end int) (LogStatistics []*LogStatistic, err error) + type Option struct + Key string + Value string + func AllOption() ([]*Option, error) + type Redemption struct + Count int + CreatedTime int64 + Id int + Key string + Name string + Quota int64 + RedeemedTime int64 + Status int + UserId int + func GetAllRedemptions(startIdx int, num int) ([]*Redemption, error) + func GetRedemptionById(id int) (*Redemption, error) + func SearchRedemptions(keyword string) (redemptions []*Redemption, err error) + func (redemption *Redemption) Delete() error + func (redemption *Redemption) Insert() error + func (redemption *Redemption) SelectUpdate() error + func (redemption *Redemption) Update() error + type Token struct + AccessedTime int64 + CreatedTime int64 + ExpiredTime int64 + Id int + Key string + Models *string + Name string + RemainQuota int64 + Status int + Subnet *string + UnlimitedQuota bool + UsedQuota int64 + UserId int + func CacheGetTokenByKey(key string) (*Token, error) + func GetAllUserTokens(userId int, startIdx int, num int, order string) ([]*Token, error) + func GetTokenById(id int) (*Token, error) + func GetTokenByIds(id int, userId int) (*Token, error) + func SearchUserTokens(userId int, keyword string) (tokens []*Token, err error) + func ValidateUserToken(key string) (token *Token, err error) + func (t *Token) Delete() error + func (t *Token) GetModels() string + func (t *Token) Insert() error + func (t *Token) SelectUpdate() error + func (t *Token) Update() error + type User struct + AccessToken string + AffCode string + DisplayName string + Email string + GitHubId string + Group string + Id int + InviterId int + LarkId string + OidcId string + Password string + Quota int64 + RequestCount int + Role int + Status int + UsedQuota int64 + Username string + VerificationCode string + WeChatId string + func GetAllUsers(startIdx int, num int, order string) (users []*User, err error) + func GetUserById(id int, selectAll bool) (*User, error) + func SearchUsers(keyword string) (users []*User, err error) + func ValidateAccessToken(token string) (user *User) + func (user *User) Delete() error + func (user *User) FillUserByEmail() error + func (user *User) FillUserByGitHubId() error + func (user *User) FillUserById() error + func (user *User) FillUserByLarkId() error + func (user *User) FillUserByOidcId() error + func (user *User) FillUserByUsername() error + func (user *User) FillUserByWeChatId() error + func (user *User) Insert(inviterId int) error + func (user *User) Update(updatePassword bool) error + func (user *User) ValidateAndFill() (err error)