Documentation
¶
Index ¶
- Variables
- type AccountPool
- func (p *AccountPool) ListUsage() []*AccountUsage
- func (p *AccountPool) RecordUsage(accountID string, tokens int64)
- func (p *AccountPool) RegisterAccount(accountID string, weight float64)
- func (p *AccountPool) RegisterAccountWithInfo(accountID, poolID, providerID string, weight float64)
- func (p *AccountPool) RemoveAccount(accID string)
- func (p *AccountPool) SelectBestAccount(candidates []string) string
- func (p *AccountPool) SetAccountDisabled(accountID string, disabled bool)
- func (p *AccountPool) SetCooldown(accountID string, duration time.Duration)
- type AccountUsage
- type PoolManager
- func (m *PoolManager) GetOrCreatePool(poolID, mode string) *AccountPool
- func (m *PoolManager) ListAllPools() map[string][]*AccountUsage
- func (m *PoolManager) RecordUsage(poolID, accID string, tokens int64)
- func (m *PoolManager) RegisterAccount(poolID, provID, accID string, weight float64)
- func (m *PoolManager) RemoveAccount(poolID, accID string)
- func (m *PoolManager) SetAccountDisabled(accID string, disabled bool)
- func (m *PoolManager) SetCooldown(poolID, accID string, duration time.Duration)
Constants ¶
This section is empty.
Variables ¶
View Source
var GlobalPool = NewPoolManager()
Functions ¶
This section is empty.
Types ¶
type AccountPool ¶
type AccountPool struct {
// contains filtered or unexported fields
}
func (*AccountPool) ListUsage ¶
func (p *AccountPool) ListUsage() []*AccountUsage
func (*AccountPool) RecordUsage ¶
func (p *AccountPool) RecordUsage(accountID string, tokens int64)
func (*AccountPool) RegisterAccount ¶
func (p *AccountPool) RegisterAccount(accountID string, weight float64)
func (*AccountPool) RegisterAccountWithInfo ¶
func (p *AccountPool) RegisterAccountWithInfo(accountID, poolID, providerID string, weight float64)
func (*AccountPool) RemoveAccount ¶
func (p *AccountPool) RemoveAccount(accID string)
func (*AccountPool) SelectBestAccount ¶
func (p *AccountPool) SelectBestAccount(candidates []string) string
SelectBestAccount implements Fair-Share Token Balancing. It selects the account with the lowest normalized token usage (WindowTokens / Weight).
func (*AccountPool) SetAccountDisabled ¶
func (p *AccountPool) SetAccountDisabled(accountID string, disabled bool)
func (*AccountPool) SetCooldown ¶
func (p *AccountPool) SetCooldown(accountID string, duration time.Duration)
type AccountUsage ¶
type AccountUsage struct {
AccountID string `json:"account_id"`
PoolID string `json:"pool_id"`
ProviderID string `json:"provider_id"`
TotalTokens int64 `json:"total_tokens"`
TotalRequests int64 `json:"total_requests"`
WindowTokens int64 `json:"window_tokens"` // Tokens consumed in current rolling window
WindowStart time.Time `json:"window_start"`
Weight float64 `json:"weight"` // Relative quota weighting, default 1.0
Status string `json:"status"` // "active", "cooldown", "disabled"
CooldownUntil time.Time `json:"cooldown_until"`
}
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
func NewPoolManager ¶
func NewPoolManager() *PoolManager
func (*PoolManager) GetOrCreatePool ¶
func (m *PoolManager) GetOrCreatePool(poolID, mode string) *AccountPool
func (*PoolManager) ListAllPools ¶
func (m *PoolManager) ListAllPools() map[string][]*AccountUsage
func (*PoolManager) RecordUsage ¶
func (m *PoolManager) RecordUsage(poolID, accID string, tokens int64)
func (*PoolManager) RegisterAccount ¶
func (m *PoolManager) RegisterAccount(poolID, provID, accID string, weight float64)
func (*PoolManager) RemoveAccount ¶
func (m *PoolManager) RemoveAccount(poolID, accID string)
func (*PoolManager) SetAccountDisabled ¶
func (m *PoolManager) SetAccountDisabled(accID string, disabled bool)
func (*PoolManager) SetCooldown ¶
func (m *PoolManager) SetCooldown(poolID, accID string, duration time.Duration)
Click to show internal directories.
Click to hide internal directories.