Documentation
¶
Index ¶
- Constants
- Variables
- func BatchInsertChannels(channels []*Channel) (err error)
- func BatchRecordLogs(requestID string, requestAt time.Time, retryAt time.Time, ...) (err error)
- func CacheDeleteGroup(id string) error
- func CacheDeleteGroupMCP(groupID, mcpID string) error
- func CacheDeletePublicMCP(mcpID string) error
- func CacheDeletePublicMCPReusingParam(mcpID, groupID string) error
- func CacheDeleteToken(key string) error
- func CacheSetGroup(group *GroupCache) error
- func CacheSetGroupMCP(groupMCP *GroupMCPCache) error
- func CacheSetPublicMCP(publicMCP *PublicMCPCache) error
- func CacheSetPublicMCPReusingParam(param PublicMCPReusingParamCache) error
- func CacheSetStore(store *StoreCache) error
- func CacheSetToken(token *TokenCache) error
- func CacheUpdateGroupMCPStatus(groupID, mcpID string, status GroupMCPStatus) error
- func CacheUpdateGroupRPMRatio(id string, rpmRatio float64) error
- func CacheUpdateGroupStatus(id string, status int) error
- func CacheUpdateGroupTPMRatio(id string, tpmRatio float64) error
- func CacheUpdateGroupUsedAmountOnlyIncrease(id string, amount float64) error
- func CacheUpdatePublicMCPStatus(mcpID string, status PublicMCPStatus) error
- func CacheUpdateTokenName(key, name string) error
- func CacheUpdateTokenStatus(key string, status int) error
- func CacheUpdateTokenUsedAmountOnlyIncrease(key string, amount float64) error
- func CheckModelConfigExist(models []string) error
- func CleanBatchUpdatesSummary(ctx context.Context)
- func CleanLog(batchSize int, optimize bool) (err error)
- func ClearLastTestErrorAt(id int) error
- func CloseDB() error
- func CreateConsumeError(requestID string, requestAt time.Time, group, tokenName, model, content string, ...) error
- func CreateGroup(group *Group) error
- func CreateGroupMCP(mcp *GroupMCP) error
- func CreateGroupSummaryIndexs(db *gorm.DB) error
- func CreateGroupSummaryMinuteIndexs(db *gorm.DB) error
- func CreateLogIndexes(db *gorm.DB) error
- func CreatePublicMCP(mcp *PublicMCP) error
- func CreateSummaryIndexs(db *gorm.DB) error
- func CreateSummaryMinuteIndexs(db *gorm.DB) error
- func DeleteChannelByID(id int) (err error)
- func DeleteChannelsByIDs(ids []int) (err error)
- func DeleteGroupByID(id string) (err error)
- func DeleteGroupLogs(groupID string) (int64, error)
- func DeleteGroupMCP(id, groupID string) (err error)
- func DeleteGroupModelConfig(groupID, model string) error
- func DeleteGroupModelConfigs(groupID string, models []string) error
- func DeleteGroupTokenByID(groupID string, id int) (err error)
- func DeleteGroupTokensByIDs(group string, ids []int) (err error)
- func DeleteGroupsByIDs(ids []string) (err error)
- func DeleteModelConfig(model string) error
- func DeleteModelConfigsByModels(models []string) error
- func DeleteOldLog(timestamp time.Time) (int64, error)
- func DeletePublicMCP(id string) (err error)
- func DeletePublicMCPReusingParam(mcpID, groupID string) (err error)
- func DeleteTokenByID(id int) (err error)
- func DeleteTokensByIDs(ids []int) (err error)
- func GetGroupLastRequestTimeMinute(group string) (time.Time, error)
- func GetGroupTokenLastRequestTimeMinute(group, token string) (time.Time, error)
- func GetGroupUsedModels(group, tokenName string, start, end time.Time) ([]string, error)
- func GetGroupUsedModelsMinute(group, tokenName string, start, end time.Time) ([]string, error)
- func GetGroupUsedTokenNames(group string, start, end time.Time) ([]string, error)
- func GetGroupUsedTokenNamesMinute(group string, start, end time.Time) ([]string, error)
- func GetIPGroups(threshold int, start, end time.Time) (map[string][]string, error)
- func GetModelConfigBool(config map[ModelConfigKey]any, key ModelConfigKey) (bool, bool)
- func GetModelConfigFloat(config map[ModelConfigKey]any, key ModelConfigKey) (float64, bool)
- func GetModelConfigInt(config map[ModelConfigKey]any, key ModelConfigKey) (int, bool)
- func GetModelConfigStringSlice(config map[ModelConfigKey]any, key ModelConfigKey) ([]string, bool)
- func GetModelConfigUint(config map[ModelConfigKey]any, key ModelConfigKey) (uint64, bool)
- func GetModelConfigWithModels(models []string) ([]string, []string, error)
- func GetPublicMCPsEmbedConfig(ids []string) (map[string]MCPEmbeddingConfig, error)
- func GetPublicMCPsEnabled(ids []string) ([]string, error)
- func GetUsedChannels(start, end time.Time) ([]int, error)
- func GetUsedChannelsMinute(start, end time.Time) ([]int, error)
- func GetUsedModels(start, end time.Time) ([]string, error)
- func GetUsedModelsMinute(start, end time.Time) ([]string, error)
- func HandleNotFound(err error, errMsg ...string) error
- func HandleUpdateResult(result *gorm.DB, entityName string) error
- func IgnoreNotFound(err error) error
- func InitDB()
- func InitLogDB()
- func InitModelConfigAndChannelCache() error
- func InitOption2DB() error
- func InsertToken(token *Token, autoCreateGroup, ignoreExist bool) error
- func NewModelConfig(opts ...ModelConfigOption) map[ModelConfigKey]any
- func NotFoundError(errMsg ...string) error
- func OnConflictDoNothing() *gorm.DB
- func OpenMySQL(dsn string) (*gorm.DB, error)
- func OpenPostgreSQL(dsn string) (*gorm.DB, error)
- func OpenSQLite(sqlitePath string) (*gorm.DB, error)
- func ProcessBatchUpdatesSummary()
- func RecordConsumeLog(requestID string, createAt time.Time, requestAt time.Time, retryAt time.Time, ...) error
- func RecordRetryLog(requestID string, createAt time.Time, requestAt time.Time, retryAt time.Time, ...) error
- func SaveGroupModelConfig(groupModelConfig GroupModelConfig) (err error)
- func SaveGroupModelConfigs(groupID string, groupModelConfigs []GroupModelConfig) (err error)
- func SaveModelConfig(config ModelConfig) (err error)
- func SaveModelConfigs(configs []ModelConfig) (err error)
- func SavePublicMCP(mcp *PublicMCP) (err error)
- func SavePublicMCPReusingParam(param *PublicMCPReusingParam) (err error)
- func SavePublicMCPs(msps []PublicMCP) (err error)
- func SortModelConfigsFunc(i, j ModelConfig) int
- func StartBatchProcessorSummary(ctx context.Context, wg *sync.WaitGroup)
- func String2Int(keyword string) int
- func SyncModelConfigAndChannelCache(ctx context.Context, wg *sync.WaitGroup, frequency time.Duration)
- func SyncOptions(ctx context.Context, wg *sync.WaitGroup, frequency time.Duration)
- func UpdateChannel(channel *Channel) (err error)
- func UpdateChannelStatusByID(id, status int) error
- func UpdateChannelUsedAmount(id int, amount float64, requestCount int) error
- func UpdateGroup(id string, group *Group) (err error)
- func UpdateGroupMCP(mcp *GroupMCP) (err error)
- func UpdateGroupMCPStatus(id, groupID string, status GroupMCPStatus) (err error)
- func UpdateGroupModelConfig(groupModelConfig GroupModelConfig) (err error)
- func UpdateGroupModelConfigs(groupID string, groupModelConfigs []GroupModelConfig) (err error)
- func UpdateGroupRPMRatio(id string, rpmRatio float64) (err error)
- func UpdateGroupStatus(id string, status int) (err error)
- func UpdateGroupTPMRatio(id string, tpmRatio float64) (err error)
- func UpdateGroupToken(id int, group string, token *Token) (err error)
- func UpdateGroupTokenName(group string, id int, name string) (err error)
- func UpdateGroupTokenStatus(group string, id, status int) (err error)
- func UpdateGroupUsedAmountAndRequestCount(id string, amount float64, count int) (err error)
- func UpdateGroupsStatus(ids []string, status int) (rowsAffected int64, err error)
- func UpdateOption(key, value string) error
- func UpdateOptions(options map[string]string) error
- func UpdatePublicMCP(mcp *PublicMCP) (err error)
- func UpdatePublicMCPReusingParam(param *PublicMCPReusingParam) (err error)
- func UpdatePublicMCPStatus(id string, status PublicMCPStatus) (err error)
- func UpdateToken(id int, token *Token) (err error)
- func UpdateTokenName(id int, name string) (err error)
- func UpdateTokenStatus(id, status int) (err error)
- func UpdateTokenUsedAmount(id int, amount float64, requestCount int) (err error)
- func UpsertGroupSummary(unique GroupSummaryUnique, data SummaryData) error
- func UpsertGroupSummaryMinute(unique GroupSummaryMinuteUnique, data SummaryData) error
- func UpsertSummary(unique SummaryUnique, data SummaryData) error
- func UpsertSummaryMinute(unique SummaryMinuteUnique, data SummaryData) error
- type Channel
- func GetAllChannels() (channels []*Channel, err error)
- func GetChannelByID(id int) (*Channel, error)
- func GetChannels(page, perPage, id int, name, key string, channelType int, ...) (channels []*Channel, total int64, err error)
- func LoadChannelByID(id int) (*Channel, error)
- func LoadChannels() ([]*Channel, error)
- func LoadDisabledChannels() ([]*Channel, error)
- func LoadEnabledChannels() ([]*Channel, error)
- func SearchChannels(keyword string, page, perPage, id int, name, key string, channelType int, ...) (channels []*Channel, total int64, err error)
- func (c *Channel) BeforeDelete(tx *gorm.DB) (err error)
- func (c *Channel) GetBalanceThreshold() float64
- func (c *Channel) GetPriority() int32
- func (c *Channel) GetSets() []string
- func (c *Channel) MarshalJSON() ([]byte, error)
- func (c *Channel) UpdateBalance(balance float64) error
- func (c *Channel) UpdateModelTest(testAt time.Time, model, actualModel string, mode mode.Mode, took float64, ...) (*ChannelTest, error)
- type ChannelConfig
- type ChannelTest
- type ChannelType
- type ChannelUpdate
- type ChartData
- type CodeType
- type ConditionalPrice
- type ConsumeError
- type DashboardResponse
- type EmptyNullString
- type GetGroupLogsResult
- type GetLogsResult
- type Group
- func GetGroupByID(id string, preloadGroupModelConfigs bool) (*Group, error)
- func GetGroups(page, perPage int, order string, onlyDisabled bool) (groups []*Group, total int64, err error)
- func SearchGroup(keyword string, page, perPage int, order string, status int) (groups []*Group, total int64, err error)
- type GroupCache
- type GroupDashboardResponse
- type GroupMCP
- type GroupMCPCache
- type GroupMCPProxyConfig
- type GroupMCPStatus
- type GroupMCPType
- type GroupModelConfig
- type GroupSummary
- type GroupSummaryMinute
- type GroupSummaryMinuteUnique
- type GroupSummaryMinuteUpdate
- type GroupSummaryUnique
- type GroupSummaryUpdate
- type GroupUpdate
- type Log
- type MCPEmbeddingConfig
- type MCPOpenAPIConfig
- type MCPPrice
- type ModelCaches
- type ModelConfig
- func GetAllModelConfigs() (configs []ModelConfig, err error)
- func GetModelConfig(model string) (ModelConfig, error)
- func GetModelConfigs(page, perPage int, model string) (configs []*ModelConfig, total int64, err error)
- func GetModelConfigsByModels(models []string) (configs []ModelConfig, err error)
- func NewDefaultModelConfig(model string) ModelConfig
- func SearchModelConfigs(keyword string, page, perPage int, model string, owner ModelOwner) (configs []ModelConfig, total int64, err error)
- func (c *ModelConfig) BeforeSave(_ *gorm.DB) (err error)
- func (c *ModelConfig) LoadFromGroupModelConfig(groupModelConfig GroupModelConfig) ModelConfig
- func (c *ModelConfig) LoadPluginConfig(pluginName string, config any) error
- func (c *ModelConfig) MarshalJSON() ([]byte, error)
- func (c *ModelConfig) MaxContextTokens() (int, bool)
- func (c *ModelConfig) MaxInputTokens() (int, bool)
- func (c *ModelConfig) MaxOutputTokens() (int, bool)
- func (c *ModelConfig) SupportFormats() ([]string, bool)
- func (c *ModelConfig) SupportToolChoice() (bool, bool)
- func (c *ModelConfig) SupportVision() (bool, bool)
- func (c *ModelConfig) SupportVoices() ([]string, bool)
- type ModelConfigCache
- type ModelConfigKey
- type ModelConfigOption
- func WithModelConfigImageQualitys(qualitys ...string) ModelConfigOption
- func WithModelConfigImageSizes(sizes ...string) ModelConfigOption
- func WithModelConfigMaxContextTokens(maxContextTokens int) ModelConfigOption
- func WithModelConfigMaxInputTokens(maxInputTokens int) ModelConfigOption
- func WithModelConfigMaxOutputTokens(maxOutputTokens int) ModelConfigOption
- func WithModelConfigSupportFormats(supportFormats []string) ModelConfigOption
- func WithModelConfigSupportVoices(supportVoices []string) ModelConfigOption
- func WithModelConfigToolChoice(toolChoice bool) ModelConfigOption
- func WithModelConfigVision(vision bool) ModelConfigOption
- type ModelOwner
- type Option
- type Params
- type Price
- func (p *Price) GetAudioInputPriceUnit() int64
- func (p *Price) GetCacheCreationPriceUnit() int64
- func (p *Price) GetCachedPriceUnit() int64
- func (p *Price) GetImageInputPriceUnit() int64
- func (p *Price) GetInputPriceUnit() int64
- func (p *Price) GetOutputPriceUnit() int64
- func (p *Price) GetWebSearchPriceUnit() int64
- func (p *Price) SelectConditionalPrice(usage Usage) Price
- func (p *Price) ValidateConditionalPrices() error
- type PriceCondition
- type ProxyParamType
- type PublicMCP
- type PublicMCPCache
- type PublicMCPProxyConfig
- type PublicMCPProxyReusingParam
- type PublicMCPReusingParam
- type PublicMCPReusingParamCache
- type PublicMCPStatus
- type PublicMCPType
- type RequestDetail
- type RetryLog
- type ReusingParam
- type Store
- type StoreCache
- type Summary
- type SummaryData
- type SummaryDataV2
- type SummaryMinute
- type SummaryMinuteUnique
- type SummaryMinuteUpdate
- type SummaryUnique
- type SummaryUpdate
- type TestConfig
- type TimeSpanType
- type TimeSummaryDataV2
- type Token
- func GetGroupTokenByID(group string, id int) (*Token, error)
- func GetTokenByID(id int) (*Token, error)
- func GetTokenByKey(key string) (*Token, error)
- func GetTokens(group string, page, perPage int, order string, status int) (tokens []*Token, total int64, err error)
- func SearchGroupTokens(group, keyword string, page, perPage int, order string, status int, ...) (tokens []*Token, total int64, err error)
- func SearchTokens(group, keyword string, page, perPage int, order string, status int, ...) (tokens []*Token, total int64, err error)
- type TokenCache
- type TokenUpdate
- type Usage
- type ZeroNullFloat64
- type ZeroNullInt64
Constants ¶
const ( SyncFrequency = time.Minute * 3 TokenCacheKey = "token:%s" GroupCacheKey = "group:%s" GroupModelTPMKey = "group:%s:model_tpm" )
const ( ChannelStatusUnknown = 0 ChannelStatusEnabled = 1 ChannelStatusDisabled = 2 )
const ( GroupStatusEnabled = 1 GroupStatusDisabled = 2 GroupStatusInternal = 3 )
const ( ErrPublicMCPNotFound = "public mcp" ErrMCPReusingParamNotFound = "mcp reusing param" )
const ( TokenStatusEnabled = 1 TokenStatusDisabled = 2 )
const (
ChannelDefaultSet = "default"
)
const (
DefaultPriority = 10
)
const (
ErrChannelNotFound = "channel"
)
const (
ErrGroupMCPNotFound = "group mcp"
)
const (
ErrGroupNotFound = "group"
)
const ErrModelConfigNotFound = "model config"
const (
ErrStoreNotFound = "store id"
)
const (
ErrTokenNotFound = "token"
)
const (
GroupMCPCacheKey = "group_mcp:%s:%s" // group_id:mcp_id
)
const (
GroupModelConfigCacheKey = "group_model_config"
)
const (
// /1K tokens
PriceUnit = 1000
)
const (
PublicMCPCacheKey = "public_mcp:%s" // mcp_id
)
const (
PublicMCPReusingParamCacheKey = "public_mcp_param:%s:%s" // mcp_id:group_id
)
const (
StoreCacheKey = "store:%s" // store_id
)
Variables ¶
var ( DB *gorm.DB LogDB *gorm.DB )
var ErrUnknownOptionKey = errors.New("unknown option key")
Functions ¶
func BatchInsertChannels ¶
func BatchRecordLogs ¶
func BatchRecordLogs( requestID string, requestAt time.Time, retryAt time.Time, firstByteAt time.Time, group string, code int, channelID int, modelName string, tokenID int, tokenName string, endpoint string, content string, mode int, ip string, retryTimes int, requestDetail *RequestDetail, downstreamResult bool, usage Usage, modelPrice Price, amount float64, user string, metadata map[string]string, ) (err error)
func CacheDeleteGroup ¶
func CacheDeleteGroupMCP ¶
func CacheDeletePublicMCP ¶
func CacheDeleteToken ¶
func CacheSetGroup ¶
func CacheSetGroup(group *GroupCache) error
func CacheSetGroupMCP ¶
func CacheSetGroupMCP(groupMCP *GroupMCPCache) error
func CacheSetPublicMCP ¶
func CacheSetPublicMCP(publicMCP *PublicMCPCache) error
func CacheSetPublicMCPReusingParam ¶
func CacheSetPublicMCPReusingParam(param PublicMCPReusingParamCache) error
func CacheSetStore ¶
func CacheSetStore(store *StoreCache) error
func CacheSetToken ¶
func CacheSetToken(token *TokenCache) error
func CacheUpdateGroupMCPStatus ¶
func CacheUpdateGroupMCPStatus(groupID, mcpID string, status GroupMCPStatus) error
func CacheUpdateGroupStatus ¶
func CacheUpdatePublicMCPStatus ¶
func CacheUpdatePublicMCPStatus(mcpID string, status PublicMCPStatus) error
func CacheUpdateTokenName ¶
func CacheUpdateTokenStatus ¶
func CheckModelConfigExist ¶
func ClearLastTestErrorAt ¶
func CreateConsumeError ¶
func CreateGroup ¶
func CreateGroupMCP ¶
CreateGroupMCP creates a new GroupMCP
func CreateLogIndexes ¶
func CreateSummaryIndexs ¶
func DeleteChannelByID ¶
func DeleteChannelsByIDs ¶
func DeleteGroupByID ¶
func DeleteGroupLogs ¶
func DeleteGroupMCP ¶
DeleteGroupMCP deletes a GroupMCP by ID and GroupID
func DeleteGroupModelConfig ¶
func DeleteGroupModelConfigs ¶
func DeleteGroupTokenByID ¶
func DeleteGroupTokensByIDs ¶
func DeleteGroupsByIDs ¶
func DeleteModelConfig ¶
func DeletePublicMCP ¶
DeletePublicMCP deletes an MCP by ID
func DeletePublicMCPReusingParam ¶
DeletePublicMCPReusingParam deletes a GroupMCPReusingParam
func DeleteTokenByID ¶
func DeleteTokensByIDs ¶
func GetGroupUsedModels ¶
func GetGroupUsedTokenNames ¶
func GetIPGroups ¶
func GetModelConfigBool ¶
func GetModelConfigBool(config map[ModelConfigKey]any, key ModelConfigKey) (bool, bool)
func GetModelConfigFloat ¶
func GetModelConfigFloat(config map[ModelConfigKey]any, key ModelConfigKey) (float64, bool)
func GetModelConfigInt ¶
func GetModelConfigInt(config map[ModelConfigKey]any, key ModelConfigKey) (int, bool)
func GetModelConfigStringSlice ¶
func GetModelConfigStringSlice(config map[ModelConfigKey]any, key ModelConfigKey) ([]string, bool)
func GetModelConfigUint ¶
func GetModelConfigUint(config map[ModelConfigKey]any, key ModelConfigKey) (uint64, bool)
func GetPublicMCPsEmbedConfig ¶
func GetPublicMCPsEmbedConfig(ids []string) (map[string]MCPEmbeddingConfig, error)
func GetPublicMCPsEnabled ¶
func HandleNotFound ¶
func IgnoreNotFound ¶
func InitModelConfigAndChannelCache ¶
func InitModelConfigAndChannelCache() error
InitModelConfigAndChannelCache initializes the channel cache from database
func InitOption2DB ¶
func InitOption2DB() error
func InsertToken ¶
func NewModelConfig ¶
func NewModelConfig(opts ...ModelConfigOption) map[ModelConfigKey]any
func NotFoundError ¶
func OnConflictDoNothing ¶
func ProcessBatchUpdatesSummary ¶
func ProcessBatchUpdatesSummary()
func RecordConsumeLog ¶
func RecordConsumeLog( requestID string, createAt time.Time, requestAt time.Time, retryAt time.Time, firstByteAt time.Time, group string, code int, channelID int, modelName string, tokenID int, tokenName string, endpoint string, content string, mode int, ip string, retryTimes int, requestDetail *RequestDetail, usage Usage, modelPrice Price, amount float64, user string, metadata map[string]string, ) error
func RecordRetryLog ¶
func SaveGroupModelConfig ¶
func SaveGroupModelConfig(groupModelConfig GroupModelConfig) (err error)
func SaveGroupModelConfigs ¶
func SaveGroupModelConfigs(groupID string, groupModelConfigs []GroupModelConfig) (err error)
func SaveModelConfig ¶
func SaveModelConfig(config ModelConfig) (err error)
func SaveModelConfigs ¶
func SaveModelConfigs(configs []ModelConfig) (err error)
func SavePublicMCP ¶
func SavePublicMCPReusingParam ¶
func SavePublicMCPReusingParam(param *PublicMCPReusingParam) (err error)
func SavePublicMCPs ¶
func SortModelConfigsFunc ¶
func SortModelConfigsFunc(i, j ModelConfig) int
func String2Int ¶
func SyncOptions ¶
func UpdateChannel ¶
func UpdateChannelStatusByID ¶
func UpdateChannelUsedAmount ¶
func UpdateGroup ¶
func UpdateGroupMCP ¶
UpdateGroupMCP updates an existing GroupMCP
func UpdateGroupMCPStatus ¶
func UpdateGroupMCPStatus(id, groupID string, status GroupMCPStatus) (err error)
func UpdateGroupModelConfig ¶
func UpdateGroupModelConfig(groupModelConfig GroupModelConfig) (err error)
func UpdateGroupModelConfigs ¶
func UpdateGroupModelConfigs(groupID string, groupModelConfigs []GroupModelConfig) (err error)
func UpdateGroupRPMRatio ¶
func UpdateGroupStatus ¶
func UpdateGroupTPMRatio ¶
func UpdateGroupTokenName ¶
func UpdateGroupTokenStatus ¶
func UpdateGroupsStatus ¶
func UpdateOption ¶
func UpdateOptions ¶
func UpdatePublicMCP ¶
UpdatePublicMCP updates an existing MCP
func UpdatePublicMCPReusingParam ¶
func UpdatePublicMCPReusingParam(param *PublicMCPReusingParam) (err error)
UpdatePublicMCPReusingParam updates an existing GroupMCPReusingParam
func UpdatePublicMCPStatus ¶
func UpdatePublicMCPStatus(id string, status PublicMCPStatus) (err error)
func UpdateToken ¶
func UpdateTokenName ¶
func UpdateTokenStatus ¶
func UpdateTokenUsedAmount ¶
func UpsertGroupSummary ¶
func UpsertGroupSummary(unique GroupSummaryUnique, data SummaryData) error
func UpsertGroupSummaryMinute ¶
func UpsertGroupSummaryMinute(unique GroupSummaryMinuteUnique, data SummaryData) error
func UpsertSummary ¶
func UpsertSummary(unique SummaryUnique, data SummaryData) error
func UpsertSummaryMinute ¶
func UpsertSummaryMinute(unique SummaryMinuteUnique, data SummaryData) error
Types ¶
type Channel ¶
type Channel struct { DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` CreatedAt time.Time `gorm:"index" json:"created_at"` LastTestErrorAt time.Time ` json:"last_test_error_at"` ChannelTests []*ChannelTest `gorm:"foreignKey:ChannelID;references:ID" json:"channel_tests,omitempty"` BalanceUpdatedAt time.Time ` json:"balance_updated_at"` ModelMapping map[string]string `gorm:"serializer:fastjson;type:text" json:"model_mapping"` Key string `gorm:"type:text;index" json:"key"` Name string `gorm:"index" json:"name"` BaseURL string `gorm:"index" json:"base_url"` Models []string `gorm:"serializer:fastjson;type:text" json:"models"` Balance float64 ` json:"balance"` ID int `gorm:"primaryKey" json:"id"` UsedAmount float64 `gorm:"index" json:"used_amount"` RequestCount int `gorm:"index" json:"request_count"` Status int `gorm:"default:1;index" json:"status"` Type ChannelType `gorm:"default:0;index" json:"type"` Priority int32 ` json:"priority"` EnabledAutoBalanceCheck bool ` json:"enabled_auto_balance_check"` BalanceThreshold float64 ` json:"balance_threshold"` Config *ChannelConfig `gorm:"serializer:fastjson;type:text" json:"config,omitempty"` Sets []string `gorm:"serializer:fastjson;type:text" json:"sets,omitempty"` }
func GetAllChannels ¶
func GetChannelByID ¶
func GetChannels ¶
func LoadChannelByID ¶
func LoadChannels ¶
func LoadDisabledChannels ¶
func LoadEnabledChannels ¶
func SearchChannels ¶
func (*Channel) GetBalanceThreshold ¶
func (*Channel) GetPriority ¶
func (*Channel) MarshalJSON ¶
func (*Channel) UpdateBalance ¶
type ChannelConfig ¶
type ChannelConfig struct {
Spec json.RawMessage `json:"spec"`
}
func (*ChannelConfig) SpecConfig ¶
func (c *ChannelConfig) SpecConfig(obj any) error
func (*ChannelConfig) UnmarshalJSON ¶
func (c *ChannelConfig) UnmarshalJSON(data []byte) error
validate spec json is map[string]any
type ChannelTest ¶
type ChannelTest struct { TestAt time.Time `json:"test_at"` Model string `json:"model" gorm:"primaryKey"` ActualModel string `json:"actual_model"` Response string `json:"response" gorm:"type:text"` ChannelName string `json:"channel_name"` ChannelType ChannelType `json:"channel_type"` ChannelID int `json:"channel_id" gorm:"primaryKey"` Took float64 `json:"took"` Success bool `json:"success"` Mode mode.Mode `json:"mode"` Code int `json:"code"` }
func (*ChannelTest) MarshalJSON ¶
func (ct *ChannelTest) MarshalJSON() ([]byte, error)
type ChannelType ¶
type ChannelType int
const ( ChannelTypeOpenAI ChannelType = 1 ChannelTypeAzure ChannelType = 3 ChannelTypeAzure2 ChannelType = 4 ChannelTypeGoogleGeminiOpenAI ChannelType = 12 ChannelTypeBaiduV2 ChannelType = 13 ChannelTypeAnthropic ChannelType = 14 ChannelTypeBaidu ChannelType = 15 ChannelTypeZhipu ChannelType = 16 ChannelTypeAli ChannelType = 17 ChannelTypeXunfei ChannelType = 18 ChannelTypeAI360 ChannelType = 19 ChannelTypeOpenRouter ChannelType = 20 ChannelTypeTencent ChannelType = 23 ChannelTypeGoogleGemini ChannelType = 24 ChannelTypeMoonshot ChannelType = 25 ChannelTypeBaichuan ChannelType = 26 ChannelTypeMinimax ChannelType = 27 ChannelTypeMistral ChannelType = 28 ChannelTypeGroq ChannelType = 29 ChannelTypeOllama ChannelType = 30 ChannelTypeLingyiwanwu ChannelType = 31 ChannelTypeStepfun ChannelType = 32 ChannelTypeAWS ChannelType = 33 ChannelTypeCoze ChannelType = 34 ChannelTypeCohere ChannelType = 35 ChannelTypeDeepseek ChannelType = 36 ChannelTypeCloudflare ChannelType = 37 ChannelTypeDoubao ChannelType = 40 ChannelTypeNovita ChannelType = 41 ChannelTypeVertexAI ChannelType = 42 ChannelTypeSiliconflow ChannelType = 43 ChannelTypeDoubaoAudio ChannelType = 44 ChannelTypeXAI ChannelType = 45 ChannelTypeDoc2x ChannelType = 46 ChannelTypeJina ChannelType = 47 ChannelTypeTextEmbeddingsInference ChannelType = 48 )
func AllChannelTypes ¶
func AllChannelTypes() []ChannelType
func (ChannelType) String ¶
func (c ChannelType) String() string
type ChannelUpdate ¶
type ChartData ¶
type ChartData struct { Timestamp int64 `json:"timestamp"` RequestCount int64 `json:"request_count"` UsedAmount float64 `json:"used_amount"` TotalTimeMilliseconds int64 `json:"total_time_milliseconds,omitempty"` TotalTTFBMilliseconds int64 `json:"total_ttfb_milliseconds,omitempty"` InputTokens int64 `json:"input_tokens,omitempty"` ImageInputTokens int64 `json:"image_input_tokens,omitempty"` AudioInputTokens int64 `json:"audio_input_tokens,omitempty"` OutputTokens int64 `json:"output_tokens,omitempty"` CachedTokens int64 `json:"cached_tokens,omitempty"` CacheCreationTokens int64 `json:"cache_creation_tokens,omitempty"` TotalTokens int64 `json:"total_tokens,omitempty"` ExceptionCount int64 `json:"exception_count"` WebSearchCount int64 `json:"web_search_count,omitempty"` MaxRPM int64 `json:"max_rpm,omitempty"` MaxTPM int64 `json:"max_tpm,omitempty"` }
type ConditionalPrice ¶
type ConditionalPrice struct { Condition PriceCondition `json:"condition"` Price Price `json:"price"` }
type ConsumeError ¶
type ConsumeError struct { RequestAt time.Time `gorm:"index;index:idx_consume_error_group_reqat,priority:2" json:"request_at"` CreatedAt time.Time ` json:"created_at"` GroupID string `gorm:"index;index:idx_consume_error_group_reqat,priority:1" json:"group_id"` RequestID string `gorm:"index" json:"request_id"` TokenName EmptyNullString `gorm:"not null" json:"token_name"` Model string ` json:"model"` Content string `gorm:"type:text" json:"content"` ID int `gorm:"primaryKey" json:"id"` UsedAmount float64 ` json:"used_amount"` TokenID int ` json:"token_id"` }
func SearchConsumeError ¶
func (*ConsumeError) MarshalJSON ¶
func (c *ConsumeError) MarshalJSON() ([]byte, error)
type DashboardResponse ¶
type DashboardResponse struct { ChartData []*ChartData `json:"chart_data"` TotalCount int64 `json:"total_count"` ExceptionCount int64 `json:"exception_count"` TotalTimeMilliseconds int64 `json:"total_time_milliseconds,omitempty"` TotalTTFBMilliseconds int64 `json:"total_ttfb_milliseconds,omitempty"` RPM int64 `json:"rpm"` TPM int64 `json:"tpm"` MaxRPM int64 `json:"max_rpm,omitempty"` MaxTPM int64 `json:"max_tpm,omitempty"` UsedAmount float64 `json:"used_amount"` InputTokens int64 `json:"input_tokens,omitempty"` ImageInputTokens int64 `json:"image_input_tokens,omitempty"` AudioInputTokens int64 `json:"audio_input_tokens,omitempty"` OutputTokens int64 `json:"output_tokens,omitempty"` TotalTokens int64 `json:"total_tokens,omitempty"` CachedTokens int64 `json:"cached_tokens,omitempty"` CacheCreationTokens int64 `json:"cache_creation_tokens,omitempty"` WebSearchCount int64 `json:"web_search_count,omitempty"` Channels []int `json:"channels,omitempty"` Models []string `json:"models,omitempty"` }
func GetDashboardData ¶
func GetDashboardData( start, end time.Time, modelName string, channelID int, timeSpan TimeSpanType, timezone *time.Location, ) (*DashboardResponse, error)
func GetDashboardDataMinute ¶
func GetDashboardDataMinute( start, end time.Time, modelName string, channelID int, timeSpan TimeSpanType, timezone *time.Location, ) (*DashboardResponse, error)
type EmptyNullString ¶
type EmptyNullString string
func (*EmptyNullString) Scan ¶
func (ns *EmptyNullString) Scan(value any) error
Scan implements the [Scanner] interface.
func (EmptyNullString) String ¶
func (ns EmptyNullString) String() string
func (EmptyNullString) Value ¶
func (ns EmptyNullString) Value() (driver.Value, error)
Value implements the driver.Valuer interface.
type GetGroupLogsResult ¶
type GetGroupLogsResult struct { GetLogsResult Models []string `json:"models"` TokenNames []string `json:"token_names"` }
func GetGroupLogs ¶
func SearchGroupLogs ¶
func SearchGroupLogs( group string, keyword string, requestID string, tokenID int, tokenName string, modelName string, startTimestamp time.Time, endTimestamp time.Time, order string, codeType CodeType, code int, withBody bool, ip string, user string, page int, perPage int, ) (*GetGroupLogsResult, error)
type GetLogsResult ¶
type GetLogsResult struct { Logs []*Log `json:"logs"` Total int64 `json:"total"` Channels []int `json:"channels,omitempty"` }
type Group ¶
type Group struct { CreatedAt time.Time `json:"created_at"` ID string `json:"id" gorm:"primaryKey"` Tokens []Token `json:"-" gorm:"foreignKey:GroupID"` GroupModelConfigs []GroupModelConfig `json:"-" gorm:"foreignKey:GroupID"` PublicMCPReusingParams []PublicMCPReusingParam `json:"-" gorm:"foreignKey:GroupID"` GroupMCPs []GroupMCP `json:"-" gorm:"foreignKey:GroupID"` Status int `json:"status" gorm:"default:1;index"` RPMRatio float64 `json:"rpm_ratio,omitempty" gorm:"index"` TPMRatio float64 `json:"tpm_ratio,omitempty" gorm:"index"` UsedAmount float64 `json:"used_amount" gorm:"index"` RequestCount int `json:"request_count" gorm:"index"` AvailableSets []string `json:"available_sets,omitempty" gorm:"serializer:fastjson;type:text"` BalanceAlertEnabled bool `gorm:"default:false" json:"balance_alert_enabled"` BalanceAlertThreshold float64 `gorm:"default:0" json:"balance_alert_threshold"` }
func SearchGroup ¶
func (*Group) ToGroupCache ¶
func (g *Group) ToGroupCache() *GroupCache
type GroupCache ¶
type GroupCache struct { ID string `json:"-" redis:"-"` Status int `json:"status" redis:"st"` UsedAmount float64 `json:"used_amount" redis:"ua"` RPMRatio float64 `json:"rpm_ratio" redis:"rpm_r"` TPMRatio float64 `json:"tpm_ratio" redis:"tpm_r"` AvailableSets redisStringSlice `json:"available_sets" redis:"ass"` ModelConfigs redisGroupModelConfigMap `json:"model_configs" redis:"mc"` BalanceAlertEnabled bool `json:"balance_alert_enabled" redis:"bae"` BalanceAlertThreshold float64 `json:"balance_alert_threshold" redis:"bat"` }
func CacheGetGroup ¶
func CacheGetGroup(id string) (*GroupCache, error)
func (*GroupCache) GetAvailableSets ¶
func (g *GroupCache) GetAvailableSets() []string
type GroupDashboardResponse ¶
type GroupDashboardResponse struct { DashboardResponse TokenNames []string `json:"token_names"` }
func GetGroupDashboardData ¶
func GetGroupDashboardData( group string, start, end time.Time, tokenName string, modelName string, timeSpan TimeSpanType, timezone *time.Location, ) (*GroupDashboardResponse, error)
func GetGroupDashboardDataMinute ¶
func GetGroupDashboardDataMinute( group string, start, end time.Time, tokenName string, modelName string, timeSpan TimeSpanType, timezone *time.Location, ) (*GroupDashboardResponse, error)
type GroupMCP ¶
type GroupMCP struct { ID string `gorm:"primaryKey" json:"id"` GroupID string `gorm:"primaryKey" json:"group_id"` Group *Group `gorm:"foreignKey:GroupID" json:"-"` Status GroupMCPStatus `gorm:"index;default:1" json:"status"` CreatedAt time.Time `gorm:"index,autoCreateTime" json:"created_at"` UpdateAt time.Time `gorm:"index,autoUpdateTime" json:"update_at"` Name string ` json:"name"` Type GroupMCPType `gorm:"index" json:"type"` Description string ` json:"description"` ProxyConfig *GroupMCPProxyConfig `gorm:"serializer:fastjson;type:text" json:"proxy_config,omitempty"` OpenAPIConfig *MCPOpenAPIConfig `gorm:"serializer:fastjson;type:text" json:"openapi_config,omitempty"` }
func GetAllGroupMCPs ¶
func GetAllGroupMCPs(status GroupMCPStatus) ([]GroupMCP, error)
func GetGroupMCPByID ¶
GetGroupMCPByID retrieves a GroupMCP by ID and GroupID
func GetGroupMCPs ¶
func GetGroupMCPs( groupID string, page, perPage int, id string, mcpType GroupMCPType, keyword string, status GroupMCPStatus, ) (mcps []GroupMCP, total int64, err error)
GetGroupMCPs retrieves GroupMCPs with pagination and filtering
func (*GroupMCP) ToGroupMCPCache ¶
func (g *GroupMCP) ToGroupMCPCache() *GroupMCPCache
type GroupMCPCache ¶
type GroupMCPCache struct { ID string `json:"id" redis:"i"` GroupID string `json:"group_id" redis:"g"` Status GroupMCPStatus `json:"status" redis:"s"` Type GroupMCPType `json:"type" redis:"t"` ProxyConfig *GroupMCPProxyConfig `json:"proxy_config" redis:"pc"` OpenAPIConfig *MCPOpenAPIConfig `json:"openapi_config" redis:"oc"` }
func CacheGetGroupMCP ¶
func CacheGetGroupMCP(groupID, mcpID string) (*GroupMCPCache, error)
type GroupMCPProxyConfig ¶
type GroupMCPStatus ¶
type GroupMCPStatus int
const ( GroupMCPStatusEnabled GroupMCPStatus = iota + 1 GroupMCPStatusDisabled )
type GroupMCPType ¶
type GroupMCPType string
const ( GroupMCPTypeProxySSE GroupMCPType = "mcp_proxy_sse" GroupMCPTypeProxyStreamable GroupMCPType = "mcp_proxy_streamable" GroupMCPTypeOpenAPI GroupMCPType = "mcp_openapi" )
type GroupModelConfig ¶
type GroupModelConfig struct { GroupID string `gorm:"primaryKey" json:"group_id"` Group *Group `gorm:"foreignKey:GroupID" json:"-"` Model string `gorm:"primaryKey" json:"model"` OverrideLimit bool `json:"override_limit"` RPM int64 `json:"rpm"` TPM int64 `json:"tpm"` OverridePrice bool `json:"override_price"` ImagePrices map[string]float64 `json:"image_prices,omitempty" gorm:"serializer:fastjson;type:text"` Price Price `json:"price,omitempty" gorm:"embedded"` OverrideRetryTimes bool `json:"override_retry_times"` RetryTimes int64 `json:"retry_times"` OverrideForceSaveDetail bool `json:"override_force_save_detail"` ForceSaveDetail bool `json:"force_save_detail"` }
func GetGroupModelConfig ¶
func GetGroupModelConfig(groupID, model string) (*GroupModelConfig, error)
func GetGroupModelConfigs ¶
func GetGroupModelConfigs(groupID string) ([]GroupModelConfig, error)
func (*GroupModelConfig) BeforeSave ¶
func (g *GroupModelConfig) BeforeSave(_ *gorm.DB) (err error)
type GroupSummary ¶
type GroupSummary struct { ID int `gorm:"primaryKey"` Unique GroupSummaryUnique `gorm:"embedded"` Data SummaryData `gorm:"embedded"` }
only summary result only requests
func (*GroupSummary) BeforeCreate ¶
func (l *GroupSummary) BeforeCreate(_ *gorm.DB) (err error)
type GroupSummaryMinute ¶
type GroupSummaryMinute struct { ID int `gorm:"primaryKey"` Unique GroupSummaryMinuteUnique `gorm:"embedded"` Data SummaryData `gorm:"embedded"` }
only summary result only requests
func (*GroupSummaryMinute) BeforeCreate ¶
func (l *GroupSummaryMinute) BeforeCreate(_ *gorm.DB) (err error)
type GroupSummaryMinuteUnique ¶
type GroupSummaryMinuteUnique struct { GroupID string `gorm:"not null;uniqueIndex:idx_groupsummary_minute_unique,priority:1"` TokenName string `gorm:"not null;uniqueIndex:idx_groupsummary_minute_unique,priority:2"` Model string `gorm:"not null;uniqueIndex:idx_groupsummary_minute_unique,priority:3"` MinuteTimestamp int64 `gorm:"not null;uniqueIndex:idx_groupsummary_minute_unique,priority:4,sort:desc"` }
type GroupSummaryMinuteUpdate ¶
type GroupSummaryMinuteUpdate struct { GroupSummaryMinuteUnique SummaryData }
type GroupSummaryUnique ¶
type GroupSummaryUnique struct { GroupID string `gorm:"not null;uniqueIndex:idx_groupsummary_unique,priority:1"` TokenName string `gorm:"not null;uniqueIndex:idx_groupsummary_unique,priority:2"` Model string `gorm:"not null;uniqueIndex:idx_groupsummary_unique,priority:3"` HourTimestamp int64 `gorm:"not null;uniqueIndex:idx_groupsummary_unique,priority:4,sort:desc"` }
type GroupSummaryUpdate ¶
type GroupSummaryUpdate struct { GroupSummaryUnique SummaryData }
type GroupUpdate ¶
type Log ¶
type Log struct { RequestDetail *RequestDetail `gorm:"foreignKey:LogID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"request_detail,omitempty"` RequestAt time.Time ` json:"request_at"` RetryAt time.Time ` json:"retry_at,omitempty"` TTFBMilliseconds ZeroNullInt64 ` json:"ttfb_milliseconds,omitempty"` CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"` TokenName string ` json:"token_name,omitempty"` Endpoint EmptyNullString ` json:"endpoint,omitempty"` Content EmptyNullString `gorm:"type:text" json:"content,omitempty"` GroupID string ` json:"group,omitempty"` Model string ` json:"model"` RequestID EmptyNullString `gorm:"index:,where:request_id is not null" json:"request_id"` ID int `gorm:"primaryKey" json:"id"` TokenID int `gorm:"index" json:"token_id,omitempty"` ChannelID int ` json:"channel,omitempty"` Code int `gorm:"index" json:"code,omitempty"` Mode int ` json:"mode,omitempty"` IP EmptyNullString `gorm:"index:,where:ip is not null" json:"ip,omitempty"` RetryTimes ZeroNullInt64 ` json:"retry_times,omitempty"` Price Price `gorm:"embedded" json:"price,omitempty"` Usage Usage `gorm:"embedded" json:"usage,omitempty"` UsedAmount float64 ` json:"used_amount,omitempty"` // https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids User EmptyNullString ` json:"user,omitempty"` Metadata map[string]string `gorm:"serializer:fastjson;type:text" json:"metadata,omitempty"` }
func (*Log) MarshalJSON ¶
type MCPEmbeddingConfig ¶
type MCPEmbeddingConfig struct { Init map[string]string `json:"init"` Reusing map[string]ReusingParam `json:"reusing"` }
type MCPOpenAPIConfig ¶
type ModelCaches ¶
type ModelCaches struct { ModelConfig ModelConfigCache // map[set][]model EnabledModelsBySet map[string][]string // map[set][]modelconfig EnabledModelConfigsBySet map[string][]ModelConfig // map[model]modelconfig EnabledModelConfigsMap map[string]ModelConfig // map[set]map[model][]channel EnabledModel2ChannelsBySet map[string]map[string][]*Channel // map[set]map[model][]channel DisabledModel2ChannelsBySet map[string]map[string][]*Channel }
func LoadModelCaches ¶
func LoadModelCaches() *ModelCaches
type ModelConfig ¶
type ModelConfig struct { CreatedAt time.Time `gorm:"index;autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"index;autoUpdateTime" json:"updated_at"` Config map[ModelConfigKey]any `gorm:"serializer:fastjson;type:text" json:"config,omitempty"` Plugin map[string]json.RawMessage `gorm:"serializer:fastjson;type:text" json:"plugin,omitempty"` Model string `gorm:"primaryKey" json:"model"` Owner ModelOwner `gorm:"type:varchar(255);index" json:"owner"` Type mode.Mode ` json:"type"` ExcludeFromTests bool ` json:"exclude_from_tests,omitempty"` RPM int64 ` json:"rpm,omitempty"` TPM int64 ` json:"tpm,omitempty"` // map[size]map[quality]price_per_image ImageQualityPrices map[string]map[string]float64 `gorm:"serializer:fastjson;type:text" json:"image_quality_prices,omitempty"` // map[size]price_per_image ImagePrices map[string]float64 `gorm:"serializer:fastjson;type:text" json:"image_prices,omitempty"` Price Price `gorm:"embedded" json:"price,omitempty"` RetryTimes int64 ` json:"retry_times,omitempty"` Timeout int64 ` json:"timeout,omitempty"` MaxErrorRate float64 ` json:"max_error_rate,omitempty"` ForceSaveDetail bool ` json:"force_save_detail,omitempty"` }
func GetAllModelConfigs ¶
func GetAllModelConfigs() (configs []ModelConfig, err error)
func GetModelConfig ¶
func GetModelConfig(model string) (ModelConfig, error)
func GetModelConfigs ¶
func GetModelConfigs( page, perPage int, model string, ) (configs []*ModelConfig, total int64, err error)
func GetModelConfigsByModels ¶
func GetModelConfigsByModels(models []string) (configs []ModelConfig, err error)
func NewDefaultModelConfig ¶
func NewDefaultModelConfig(model string) ModelConfig
func SearchModelConfigs ¶
func SearchModelConfigs( keyword string, page, perPage int, model string, owner ModelOwner, ) (configs []ModelConfig, total int64, err error)
func (*ModelConfig) BeforeSave ¶
func (c *ModelConfig) BeforeSave(_ *gorm.DB) (err error)
func (*ModelConfig) LoadFromGroupModelConfig ¶
func (c *ModelConfig) LoadFromGroupModelConfig(groupModelConfig GroupModelConfig) ModelConfig
func (*ModelConfig) LoadPluginConfig ¶
func (c *ModelConfig) LoadPluginConfig(pluginName string, config any) error
func (*ModelConfig) MarshalJSON ¶
func (c *ModelConfig) MarshalJSON() ([]byte, error)
func (*ModelConfig) MaxContextTokens ¶
func (c *ModelConfig) MaxContextTokens() (int, bool)
func (*ModelConfig) MaxInputTokens ¶
func (c *ModelConfig) MaxInputTokens() (int, bool)
func (*ModelConfig) MaxOutputTokens ¶
func (c *ModelConfig) MaxOutputTokens() (int, bool)
func (*ModelConfig) SupportFormats ¶
func (c *ModelConfig) SupportFormats() ([]string, bool)
func (*ModelConfig) SupportToolChoice ¶
func (c *ModelConfig) SupportToolChoice() (bool, bool)
func (*ModelConfig) SupportVision ¶
func (c *ModelConfig) SupportVision() (bool, bool)
func (*ModelConfig) SupportVoices ¶
func (c *ModelConfig) SupportVoices() ([]string, bool)
type ModelConfigCache ¶
type ModelConfigCache interface {
GetModelConfig(model string) (ModelConfig, bool)
}
type ModelConfigKey ¶
type ModelConfigKey string
const ( ModelConfigMaxContextTokensKey ModelConfigKey = "max_context_tokens" ModelConfigMaxInputTokensKey ModelConfigKey = "max_input_tokens" ModelConfigMaxOutputTokensKey ModelConfigKey = "max_output_tokens" ModelConfigVisionKey ModelConfigKey = "vision" ModelConfigToolChoiceKey ModelConfigKey = "tool_choice" ModelConfigSupportFormatsKey ModelConfigKey = "support_formats" ModelConfigSupportVoicesKey ModelConfigKey = "support_voices" ModelConfigImageSizes ModelConfigKey = "image_sizes" ModelConfigImageQualitys ModelConfigKey = "image_qualitys" )
type ModelConfigOption ¶
type ModelConfigOption func(config map[ModelConfigKey]any)
func WithModelConfigImageQualitys ¶
func WithModelConfigImageQualitys(qualitys ...string) ModelConfigOption
func WithModelConfigImageSizes ¶
func WithModelConfigImageSizes(sizes ...string) ModelConfigOption
func WithModelConfigMaxContextTokens ¶
func WithModelConfigMaxContextTokens(maxContextTokens int) ModelConfigOption
func WithModelConfigMaxInputTokens ¶
func WithModelConfigMaxInputTokens(maxInputTokens int) ModelConfigOption
func WithModelConfigMaxOutputTokens ¶
func WithModelConfigMaxOutputTokens(maxOutputTokens int) ModelConfigOption
func WithModelConfigSupportFormats ¶
func WithModelConfigSupportFormats(supportFormats []string) ModelConfigOption
func WithModelConfigSupportVoices ¶
func WithModelConfigSupportVoices(supportVoices []string) ModelConfigOption
func WithModelConfigToolChoice ¶
func WithModelConfigToolChoice(toolChoice bool) ModelConfigOption
func WithModelConfigVision ¶
func WithModelConfigVision(vision bool) ModelConfigOption
type ModelOwner ¶
type ModelOwner string
const ( ModelOwnerOpenAI ModelOwner = "openai" ModelOwnerAlibaba ModelOwner = "alibaba" ModelOwnerTencent ModelOwner = "tencent" ModelOwnerXunfei ModelOwner = "xunfei" ModelOwnerDeepSeek ModelOwner = "deepseek" ModelOwnerMoonshot ModelOwner = "moonshot" ModelOwnerMiniMax ModelOwner = "minimax" ModelOwnerBaidu ModelOwner = "baidu" ModelOwnerGoogle ModelOwner = "google" ModelOwnerBAAI ModelOwner = "baai" ModelOwnerFunAudioLLM ModelOwner = "funaudiollm" ModelOwnerDoubao ModelOwner = "doubao" ModelOwnerFishAudio ModelOwner = "fishaudio" ModelOwnerChatGLM ModelOwner = "chatglm" ModelOwnerStabilityAI ModelOwner = "stabilityai" ModelOwnerNetease ModelOwner = "netease" ModelOwnerAI360 ModelOwner = "ai360" ModelOwnerAnthropic ModelOwner = "anthropic" ModelOwnerMeta ModelOwner = "meta" ModelOwnerBaichuan ModelOwner = "baichuan" ModelOwnerMistral ModelOwner = "mistral" ModelOwnerOpenChat ModelOwner = "openchat" ModelOwnerMicrosoft ModelOwner = "microsoft" ModelOwnerDefog ModelOwner = "defog" ModelOwnerNexusFlow ModelOwner = "nexusflow" ModelOwnerCohere ModelOwner = "cohere" ModelOwnerHuggingFace ModelOwner = "huggingface" ModelOwnerLingyiWanwu ModelOwner = "lingyiwanwu" ModelOwnerStepFun ModelOwner = "stepfun" ModelOwnerXAI ModelOwner = "xai" ModelOwnerDoc2x ModelOwner = "doc2x" ModelOwnerJina ModelOwner = "jina" )
type Option ¶
func GetAllOption ¶
type Price ¶
type Price struct { PerRequestPrice ZeroNullFloat64 `json:"per_request_price,omitempty"` InputPrice ZeroNullFloat64 `json:"input_price,omitempty"` InputPriceUnit ZeroNullInt64 `json:"input_price_unit,omitempty"` ImageInputPrice ZeroNullFloat64 `json:"image_input_price,omitempty"` ImageInputPriceUnit ZeroNullInt64 `json:"image_input_price_unit,omitempty"` AudioInputPrice ZeroNullFloat64 `json:"audio_input_price,omitempty"` AudioInputPriceUnit ZeroNullInt64 `json:"audio_input_price_unit,omitempty"` OutputPrice ZeroNullFloat64 `json:"output_price,omitempty"` OutputPriceUnit ZeroNullInt64 `json:"output_price_unit,omitempty"` // when ThinkingModeOutputPrice and ReasoningTokens are not 0, OutputPrice and OutputPriceUnit // will be overwritten ThinkingModeOutputPrice ZeroNullFloat64 `json:"thinking_mode_output_price,omitempty"` ThinkingModeOutputPriceUnit ZeroNullInt64 `json:"thinking_mode_output_price_unit,omitempty"` CachedPrice ZeroNullFloat64 `json:"cached_price,omitempty"` CachedPriceUnit ZeroNullInt64 `json:"cached_price_unit,omitempty"` CacheCreationPrice ZeroNullFloat64 `json:"cache_creation_price,omitempty"` CacheCreationPriceUnit ZeroNullInt64 `json:"cache_creation_price_unit,omitempty"` WebSearchPrice ZeroNullFloat64 `json:"web_search_price,omitempty"` WebSearchPriceUnit ZeroNullInt64 `json:"web_search_price_unit,omitempty"` ConditionalPrices []ConditionalPrice `gorm:"serializer:fastjson;type:text" json:"conditional_prices,omitempty"` }
func (*Price) GetAudioInputPriceUnit ¶
func (*Price) GetCacheCreationPriceUnit ¶
func (*Price) GetCachedPriceUnit ¶
func (*Price) GetImageInputPriceUnit ¶
func (*Price) GetInputPriceUnit ¶
func (*Price) GetOutputPriceUnit ¶
func (*Price) GetWebSearchPriceUnit ¶
func (*Price) SelectConditionalPrice ¶
func (*Price) ValidateConditionalPrices ¶
type PriceCondition ¶
type ProxyParamType ¶
type ProxyParamType string
const ( ParamTypeURL ProxyParamType = "url" ParamTypeHeader ProxyParamType = "header" ParamTypeQuery ProxyParamType = "query" )
type PublicMCP ¶
type PublicMCP struct { ID string `gorm:"primaryKey" json:"id"` CreatedAt time.Time `gorm:"index,autoCreateTime" json:"created_at"` UpdateAt time.Time `gorm:"index,autoUpdateTime" json:"update_at"` PublicMCPReusingParams []PublicMCPReusingParam `gorm:"foreignKey:MCPID" json:"-"` Name string `json:"name"` NameCN string `json:"name_cn,omitempty"` Status PublicMCPStatus `json:"status" gorm:"index;default:1"` Type PublicMCPType `json:"type,omitempty" gorm:"index"` Description string `json:"description"` DescriptionCN string `json:"description_cn,omitempty"` GitHubURL string `json:"github_url"` Readme string `json:"readme,omitempty" gorm:"type:text"` ReadmeCN string `json:"readme_cn,omitempty" gorm:"type:text"` ReadmeURL string `json:"readme_url,omitempty"` ReadmeCNURL string `json:"readme_cn_url,omitempty"` Tags []string `json:"tags,omitempty" gorm:"serializer:fastjson;type:text"` LogoURL string `json:"logo_url,omitempty"` Price MCPPrice `json:"price" gorm:"embedded"` ProxyConfig *PublicMCPProxyConfig `gorm:"serializer:fastjson;type:text" json:"proxy_config,omitempty"` OpenAPIConfig *MCPOpenAPIConfig `gorm:"serializer:fastjson;type:text" json:"openapi_config,omitempty"` EmbedConfig *MCPEmbeddingConfig `gorm:"serializer:fastjson;type:text" json:"embed_config,omitempty"` // only used by list tools TestConfig *TestConfig `gorm:"serializer:fastjson;type:text" json:"test_config,omitempty"` }
func GetAllPublicMCPs ¶
func GetAllPublicMCPs(status PublicMCPStatus) ([]PublicMCP, error)
func GetPublicMCPByID ¶
GetPublicMCPByID retrieves an MCP by ID
func GetPublicMCPs ¶
func GetPublicMCPs( page, perPage int, id string, mcpType []PublicMCPType, keyword string, status PublicMCPStatus, ) (mcps []PublicMCP, total int64, err error)
GetPublicMCPs retrieves MCPs with pagination and filtering
func (*PublicMCP) ToPublicMCPCache ¶
func (p *PublicMCP) ToPublicMCPCache() *PublicMCPCache
type PublicMCPCache ¶
type PublicMCPCache struct { ID string `json:"id" redis:"i"` Status PublicMCPStatus `json:"status" redis:"s"` Type PublicMCPType `json:"type" redis:"t"` Price MCPPrice `json:"price" redis:"p"` ProxyConfig *PublicMCPProxyConfig `json:"proxy_config" redis:"pc"` OpenAPIConfig *MCPOpenAPIConfig `json:"openapi_config" redis:"oc"` EmbedConfig *MCPEmbeddingConfig `json:"embed_config" redis:"ec"` }
func CacheGetPublicMCP ¶
func CacheGetPublicMCP(mcpID string) (*PublicMCPCache, error)
type PublicMCPProxyConfig ¶
type PublicMCPProxyReusingParam ¶
type PublicMCPProxyReusingParam struct { ReusingParam Type ProxyParamType `json:"type"` }
type PublicMCPReusingParam ¶
type PublicMCPReusingParam struct { MCPID string `gorm:"primaryKey" json:"mcp_id"` GroupID string `gorm:"primaryKey" json:"group_id"` CreatedAt time.Time `gorm:"index" json:"created_at"` UpdateAt time.Time `gorm:"index" json:"update_at"` Group *Group `gorm:"foreignKey:GroupID" json:"-"` Params Params `gorm:"serializer:fastjson;type:text" json:"params"` }
func GetPublicMCPReusingParam ¶
func GetPublicMCPReusingParam(mcpID, groupID string) (PublicMCPReusingParam, error)
GetPublicMCPReusingParam retrieves a GroupMCPReusingParam by MCP ID and Group ID
func (*PublicMCPReusingParam) BeforeCreate ¶
func (p *PublicMCPReusingParam) BeforeCreate(_ *gorm.DB) (err error)
func (*PublicMCPReusingParam) MarshalJSON ¶
func (p *PublicMCPReusingParam) MarshalJSON() ([]byte, error)
func (*PublicMCPReusingParam) ToPublicMCPReusingParamCache ¶
func (p *PublicMCPReusingParam) ToPublicMCPReusingParamCache() PublicMCPReusingParamCache
type PublicMCPReusingParamCache ¶
type PublicMCPReusingParamCache struct { MCPID string `json:"mcp_id" redis:"m"` GroupID string `json:"group_id" redis:"g"` Params redisMap[string, string] `json:"params" redis:"p"` }
func CacheGetPublicMCPReusingParam ¶
func CacheGetPublicMCPReusingParam(mcpID, groupID string) (PublicMCPReusingParamCache, error)
type PublicMCPStatus ¶
type PublicMCPStatus int
const ( PublicMCPStatusEnabled PublicMCPStatus = iota + 1 PublicMCPStatusDisabled )
type PublicMCPType ¶
type PublicMCPType string
const ( PublicMCPTypeProxySSE PublicMCPType = "mcp_proxy_sse" PublicMCPTypeProxyStreamable PublicMCPType = "mcp_proxy_streamable" PublicMCPTypeDocs PublicMCPType = "mcp_docs" // read only PublicMCPTypeOpenAPI PublicMCPType = "mcp_openapi" PublicMCPTypeEmbed PublicMCPType = "mcp_embed" )
type RequestDetail ¶
type RequestDetail struct { CreatedAt time.Time `gorm:"autoCreateTime;index" json:"-"` RequestBody string `gorm:"type:text" json:"request_body,omitempty"` ResponseBody string `gorm:"type:text" json:"response_body,omitempty"` RequestBodyTruncated bool ` json:"request_body_truncated,omitempty"` ResponseBodyTruncated bool ` json:"response_body_truncated,omitempty"` ID int `gorm:"primaryKey" json:"id"` LogID int `gorm:"index" json:"log_id"` }
func GetGroupLogDetail ¶
func GetGroupLogDetail(logID int, group string) (*RequestDetail, error)
func GetLogDetail ¶
func GetLogDetail(logID int) (*RequestDetail, error)
func (*RequestDetail) BeforeSave ¶
func (d *RequestDetail) BeforeSave(_ *gorm.DB) (err error)
type RetryLog ¶
type RetryLog struct { RequestBody string `gorm:"type:text" json:"request_body,omitempty"` ResponseBody string `gorm:"type:text" json:"response_body,omitempty"` RequestBodyTruncated bool ` json:"request_body_truncated,omitempty"` ResponseBodyTruncated bool ` json:"response_body_truncated,omitempty"` RequestAt time.Time ` json:"request_at"` RetryAt time.Time ` json:"retry_at,omitempty"` TTFBMilliseconds ZeroNullInt64 ` json:"ttfb_milliseconds,omitempty"` CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"` Model string ` json:"model"` RequestID EmptyNullString `gorm:"index:,where:request_id is not null" json:"request_id"` ID int `gorm:"primaryKey" json:"id"` ChannelID int ` json:"channel,omitempty"` Code int `gorm:"index" json:"code,omitempty"` Mode int ` json:"mode,omitempty"` RetryTimes ZeroNullInt64 ` json:"retry_times,omitempty"` }
func (*RetryLog) MarshalJSON ¶
type ReusingParam ¶
type Store ¶
type Store struct { ID string `gorm:"primaryKey"` CreatedAt time.Time `gorm:"autoCreateTime"` ExpiresAt time.Time GroupID string TokenID int ChannelID int Model string }
Store represents channel-associated data storage for various purposes: - Video generation jobs and their results - File storage with associated metadata - Any other channel-specific data that needs persistence
func (*Store) ToStoreCache ¶
func (s *Store) ToStoreCache() *StoreCache
type StoreCache ¶
type StoreCache struct { ID string `json:"id" redis:"i"` GroupID string `json:"group_id" redis:"g"` TokenID int `json:"token_id" redis:"t"` ChannelID int `json:"channel_id" redis:"c"` Model string `json:"model" redis:"m"` ExpiresAt time.Time `json:"expires_at" redis:"e"` }
func CacheGetStore ¶
func CacheGetStore(id string) (*StoreCache, error)
type Summary ¶
type Summary struct { ID int `gorm:"primaryKey"` Unique SummaryUnique `gorm:"embedded"` Data SummaryData `gorm:"embedded"` }
only summary result only requests
type SummaryData ¶
type SummaryData struct { RequestCount int64 `json:"request_count"` UsedAmount float64 `json:"used_amount"` ExceptionCount int64 `json:"exception_count"` TotalTimeMilliseconds int64 `json:"total_time_milliseconds,omitempty"` TotalTTFBMilliseconds int64 `json:"total_ttfb_milliseconds,omitempty"` Usage Usage `json:"usage,omitempty" gorm:"embedded"` }
type SummaryDataV2 ¶
type SummaryDataV2 struct { Timestamp int64 `json:"timestamp,omitempty"` ChannelID int `json:"channel_id,omitempty"` Model string `json:"model"` RequestCount int64 `json:"request_count"` UsedAmount float64 `json:"used_amount"` ExceptionCount int64 `json:"exception_count"` TotalTimeMilliseconds int64 `json:"total_time_milliseconds,omitempty"` TotalTTFBMilliseconds int64 `json:"total_ttfb_milliseconds,omitempty"` InputTokens int64 `json:"input_tokens,omitempty"` ImageInputTokens int64 `json:"image_input_tokens,omitempty"` AudioInputTokens int64 `json:"audio_input_tokens,omitempty"` OutputTokens int64 `json:"output_tokens,omitempty"` CachedTokens int64 `json:"cached_tokens,omitempty"` CacheCreationTokens int64 `json:"cache_creation_tokens,omitempty"` TotalTokens int64 `json:"total_tokens,omitempty"` WebSearchCount int64 `json:"web_search_count,omitempty"` MaxRPM int64 `json:"max_rpm,omitempty"` MaxTPM int64 `json:"max_tpm,omitempty"` }
type SummaryMinute ¶
type SummaryMinute struct { ID int `gorm:"primaryKey"` Unique SummaryMinuteUnique `gorm:"embedded"` Data SummaryData `gorm:"embedded"` }
func (*SummaryMinute) BeforeCreate ¶
func (l *SummaryMinute) BeforeCreate(_ *gorm.DB) (err error)
type SummaryMinuteUnique ¶
type SummaryMinuteUpdate ¶
type SummaryMinuteUpdate struct { SummaryMinuteUnique SummaryData }
type SummaryUnique ¶
type SummaryUpdate ¶
type SummaryUpdate struct { SummaryUnique SummaryData }
type TestConfig ¶
type TimeSpanType ¶
type TimeSpanType string
const ( TimeSpanMinute TimeSpanType = "minute" TimeSpanDay TimeSpanType = "day" TimeSpanHour TimeSpanType = "hour" )
type TimeSummaryDataV2 ¶
type TimeSummaryDataV2 struct { Timestamp int64 `json:"timestamp"` Summary []*SummaryDataV2 `json:"summary"` }
func GetGroupTimeSeriesModelDataMinute ¶
func GetGroupTimeSeriesModelDataMinute( group string, tokenName string, modelName string, start, end time.Time, timeSpan TimeSpanType, timezone *time.Location, ) ([]*TimeSummaryDataV2, error)
func GetTimeSeriesModelDataMinute ¶
func GetTimeSeriesModelDataMinute( channelID int, modelName string, start, end time.Time, timeSpan TimeSpanType, timezone *time.Location, ) ([]*TimeSummaryDataV2, error)
type Token ¶
type Token struct { CreatedAt time.Time `json:"created_at"` ExpiredAt time.Time `json:"expired_at"` Group *Group `json:"-" gorm:"foreignKey:GroupID"` Key string `json:"key" gorm:"type:char(48);uniqueIndex"` Name EmptyNullString `json:"name" gorm:"index;uniqueIndex:idx_group_name;not null"` GroupID string `json:"group" gorm:"index;uniqueIndex:idx_group_name"` Subnets []string `json:"subnets" gorm:"serializer:fastjson;type:text"` Models []string `json:"models" gorm:"serializer:fastjson;type:text"` Status int `json:"status" gorm:"default:1;index"` ID int `json:"id" gorm:"primaryKey"` Quota float64 `json:"quota"` UsedAmount float64 `json:"used_amount" gorm:"index"` RequestCount int `json:"request_count" gorm:"index"` }
func GetTokenByID ¶
func GetTokenByKey ¶
func SearchGroupTokens ¶
func SearchTokens ¶
func (*Token) ToTokenCache ¶
func (t *Token) ToTokenCache() *TokenCache
type TokenCache ¶
type TokenCache struct { ExpiredAt redisTime `json:"expired_at" redis:"e"` Group string `json:"group" redis:"g"` Key string `json:"-" redis:"-"` Name string `json:"name" redis:"n"` Subnets redisStringSlice `json:"subnets" redis:"s"` Models redisStringSlice `json:"models" redis:"m"` ID int `json:"id" redis:"i"` Status int `json:"status" redis:"st"` Quota float64 `json:"quota" redis:"q"` UsedAmount float64 `json:"used_amount" redis:"u"` // contains filtered or unexported fields }
func CacheGetTokenByKey ¶
func CacheGetTokenByKey(key string) (*TokenCache, error)
func ValidateAndGetToken ¶
func ValidateAndGetToken(key string) (token *TokenCache, err error)
func (*TokenCache) ContainsModel ¶
func (t *TokenCache) ContainsModel(model string) bool
func (*TokenCache) Range ¶
func (t *TokenCache) Range(fn func(model string) bool)
func (*TokenCache) SetAvailableSets ¶
func (t *TokenCache) SetAvailableSets(availableSets []string)
func (*TokenCache) SetModelsBySet ¶
func (t *TokenCache) SetModelsBySet(modelsBySet map[string][]string)
type TokenUpdate ¶
type Usage ¶
type Usage struct { InputTokens ZeroNullInt64 `json:"input_tokens,omitempty"` ImageInputTokens ZeroNullInt64 `json:"image_input_tokens,omitempty"` AudioInputTokens ZeroNullInt64 `json:"audio_input_tokens,omitempty"` OutputTokens ZeroNullInt64 `json:"output_tokens,omitempty"` CachedTokens ZeroNullInt64 `json:"cached_tokens,omitempty"` CacheCreationTokens ZeroNullInt64 `json:"cache_creation_tokens,omitempty"` ReasoningTokens ZeroNullInt64 `json:"reasoning_tokens,omitempty"` TotalTokens ZeroNullInt64 `json:"total_tokens,omitempty"` WebSearchCount ZeroNullInt64 `json:"web_search_count,omitempty"` }
type ZeroNullFloat64 ¶
type ZeroNullFloat64 float64
func (*ZeroNullFloat64) Scan ¶
func (znf *ZeroNullFloat64) Scan(value any) error
type ZeroNullInt64 ¶
type ZeroNullInt64 int64
func (*ZeroNullInt64) Scan ¶
func (zni *ZeroNullInt64) Scan(value any) error