Documentation
¶
Overview ¶
Package racing provides a virtual provider that races multiple providers concurrently. It returns the first successful response, with support for weighted and quality-based selection strategies, along with performance tracking to optimize provider selection over time.
Index ¶
- type Config
- type ConfigError
- type PerformanceTracker
- type ProviderReference
- type ProviderStats
- type RacingProvider
- func (r *RacingProvider) Authenticate(ctx context.Context, authConfig types.AuthConfig) error
- func (r *RacingProvider) Configure(config types.ProviderConfig) error
- func (r *RacingProvider) Description() string
- func (r *RacingProvider) GenerateChatCompletion(ctx context.Context, opts types.GenerateOptions) (types.ChatCompletionStream, error)
- func (r *RacingProvider) GetConfig() types.ProviderConfig
- func (r *RacingProvider) GetDefaultModel() string
- func (r *RacingProvider) GetMetrics() types.ProviderMetrics
- func (r *RacingProvider) GetModels(ctx context.Context) ([]types.Model, error)
- func (r *RacingProvider) GetPerformanceStats() map[string]*ProviderStats
- func (r *RacingProvider) GetToolFormat() types.ToolFormat
- func (r *RacingProvider) HealthCheck(ctx context.Context) error
- func (r *RacingProvider) InvokeServerTool(ctx context.Context, toolName string, params interface{}) (interface{}, error)
- func (r *RacingProvider) IsAuthenticated() bool
- func (r *RacingProvider) Logout(ctx context.Context) error
- func (r *RacingProvider) Name() string
- func (r *RacingProvider) SetMetricsCollector(collector types.MetricsCollector)
- func (r *RacingProvider) SetProviders(providers []types.Provider)
- func (r *RacingProvider) SupportsResponsesAPI() bool
- func (r *RacingProvider) SupportsStreaming() bool
- func (r *RacingProvider) SupportsToolCalling() bool
- func (r *RacingProvider) Type() types.ProviderType
- type Strategy
- type VirtualModelConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Default configuration for backwards compatibility
TimeoutMS int `yaml:"timeout_ms"`
GracePeriodMS int `yaml:"grace_period_ms"`
Strategy Strategy `yaml:"strategy"`
ProviderNames []string `yaml:"providers"`
// Virtual models configuration
VirtualModels map[string]VirtualModelConfig `yaml:"virtual_models"`
DefaultVirtualModel string `yaml:"default_virtual_model"`
PerformanceFile string `yaml:"performance_file,omitempty"`
}
Config represents configuration for the racing provider
func DefaultConfig ¶ added in v1.0.14
func DefaultConfig() *Config
DefaultConfig returns a default configuration with sensible defaults
func (*Config) GetEffectiveStrategy ¶ added in v1.0.14
GetEffectiveStrategy returns the effective strategy for a given virtual model Falls back to default config values if the virtual model doesn't exist
func (*Config) GetEffectiveTimeout ¶ added in v1.0.14
GetEffectiveTimeout returns the effective timeout for a given virtual model Falls back to default config values if the virtual model doesn't exist
func (*Config) GetVirtualModel ¶ added in v1.0.14
func (c *Config) GetVirtualModel(modelName string) *VirtualModelConfig
GetVirtualModel returns the virtual model configuration for the given model name
type ConfigError ¶ added in v1.0.14
ConfigError represents a configuration validation error
func (*ConfigError) Error ¶ added in v1.0.14
func (e *ConfigError) Error() string
type PerformanceTracker ¶
type PerformanceTracker struct {
// contains filtered or unexported fields
}
func NewPerformanceTracker ¶
func NewPerformanceTracker() *PerformanceTracker
func (*PerformanceTracker) GetAllStats ¶
func (pt *PerformanceTracker) GetAllStats() map[string]*ProviderStats
func (*PerformanceTracker) GetScore ¶
func (pt *PerformanceTracker) GetScore(provider string) float64
func (*PerformanceTracker) RecordLoss ¶
func (pt *PerformanceTracker) RecordLoss(provider string, latency time.Duration)
type ProviderReference ¶ added in v1.0.14
type ProviderReference struct {
Name string `yaml:"name"`
Model string `yaml:"model,omitempty"`
Priority int `yaml:"priority,omitempty"` // Higher numbers = higher priority
Config map[string]interface{} `yaml:"config,omitempty"`
}
ProviderReference represents a reference to a provider with optional configuration
type ProviderStats ¶
type RacingProvider ¶
type RacingProvider struct {
// contains filtered or unexported fields
}
RacingProvider races multiple providers and returns the first successful response
func NewRacingProvider ¶
func NewRacingProvider(name string, config *Config) *RacingProvider
func (*RacingProvider) Authenticate ¶
func (r *RacingProvider) Authenticate(ctx context.Context, authConfig types.AuthConfig) error
func (*RacingProvider) Configure ¶
func (r *RacingProvider) Configure(config types.ProviderConfig) error
func (*RacingProvider) Description ¶
func (r *RacingProvider) Description() string
func (*RacingProvider) GenerateChatCompletion ¶
func (r *RacingProvider) GenerateChatCompletion(ctx context.Context, opts types.GenerateOptions) (types.ChatCompletionStream, error)
func (*RacingProvider) GetConfig ¶
func (r *RacingProvider) GetConfig() types.ProviderConfig
func (*RacingProvider) GetDefaultModel ¶
func (r *RacingProvider) GetDefaultModel() string
func (*RacingProvider) GetMetrics ¶
func (r *RacingProvider) GetMetrics() types.ProviderMetrics
func (*RacingProvider) GetPerformanceStats ¶
func (r *RacingProvider) GetPerformanceStats() map[string]*ProviderStats
func (*RacingProvider) GetToolFormat ¶
func (r *RacingProvider) GetToolFormat() types.ToolFormat
func (*RacingProvider) HealthCheck ¶
func (r *RacingProvider) HealthCheck(ctx context.Context) error
func (*RacingProvider) InvokeServerTool ¶
func (r *RacingProvider) InvokeServerTool(ctx context.Context, toolName string, params interface{}) (interface{}, error)
func (*RacingProvider) IsAuthenticated ¶
func (r *RacingProvider) IsAuthenticated() bool
func (*RacingProvider) Name ¶
func (r *RacingProvider) Name() string
func (*RacingProvider) SetMetricsCollector ¶ added in v1.0.7
func (r *RacingProvider) SetMetricsCollector(collector types.MetricsCollector)
func (*RacingProvider) SetProviders ¶
func (r *RacingProvider) SetProviders(providers []types.Provider)
func (*RacingProvider) SupportsResponsesAPI ¶
func (r *RacingProvider) SupportsResponsesAPI() bool
func (*RacingProvider) SupportsStreaming ¶
func (r *RacingProvider) SupportsStreaming() bool
func (*RacingProvider) SupportsToolCalling ¶
func (r *RacingProvider) SupportsToolCalling() bool
func (*RacingProvider) Type ¶
func (r *RacingProvider) Type() types.ProviderType
type VirtualModelConfig ¶ added in v1.0.14
type VirtualModelConfig struct {
DisplayName string `yaml:"display_name"`
Description string `yaml:"description"`
Providers []ProviderReference `yaml:"providers"`
Strategy Strategy `yaml:"strategy"`
TimeoutMS int `yaml:"timeout_ms"`
}
VirtualModelConfig represents configuration for a single virtual model