router

package
v0.0.0-...-b714798 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFallbackChain

func BuildFallbackChain(primary types.Model, allModels []types.Model, maxFallbacks int) []types.Model

BuildFallbackChain builds a fallback chain based on model characteristics

func FallbackWithRetry

func FallbackWithRetry(
	ctx context.Context,
	models []types.Model,
	retryConfig RetryConfig,
	fn func(model types.Model) error,
) error

FallbackWithRetry combines fallback and retry strategies

func FallbackWithRetryAndResult

func FallbackWithRetryAndResult(
	ctx context.Context,
	models []types.Model,
	retryConfig RetryConfig,
	fn func(model types.Model) (interface{}, error),
) (interface{}, error)

FallbackWithRetryAndResult combines fallback and retry with result

func InitGlobalRouter

func InitGlobalRouter(config *RoutingConfig)

InitGlobalRouter initializes the global router

func RetryableFunc

func RetryableFunc(ctx context.Context, config RetryConfig, fn func() error) error

RetryableFunc wraps a function with retry logic

func RetryableFuncWithResult

func RetryableFuncWithResult(ctx context.Context, config RetryConfig, fn func() (interface{}, error)) (interface{}, error)

RetryableFuncWithResult wraps a function with retry logic and returns result

func ShouldRetry

func ShouldRetry(err error) bool

ShouldRetry determines if an error is retryable

func SmartFallbackChain

func SmartFallbackChain(primary types.Model, allModels []types.Model) []types.Model

SmartFallbackChain builds a smart fallback chain based on model tier

func ValidateConfig

func ValidateConfig(config *RoutingConfig) error

ValidateConfig validates the routing configuration

Types

type AggregationFunc

type AggregationFunc func(results []ChainStepResult) string

AggregationFunc combines multiple results

type AverageStrategy

type AverageStrategy struct{}

AverageStrategy averages numeric outputs

func (*AverageStrategy) Compose

func (s *AverageStrategy) Compose(results []ModelResult) (string, error)

func (*AverageStrategy) Name

func (s *AverageStrategy) Name() string

type BestQualityAlgorithm

type BestQualityAlgorithm struct {
	// contains filtered or unexported fields
}

BestQualityAlgorithm selects the highest quality available model

func NewBestQualityAlgorithm

func NewBestQualityAlgorithm() *BestQualityAlgorithm

NewBestQualityAlgorithm creates a new best-quality algorithm

func (*BestQualityAlgorithm) SelectModel

func (bq *BestQualityAlgorithm) SelectModel(models []types.Model, analysis *PromptAnalysis) (*types.Model, error)

SelectModel selects the model with highest quality

type BestScoreStrategy

type BestScoreStrategy struct{}

BestScoreStrategy returns the result with the highest score

func (*BestScoreStrategy) Compose

func (s *BestScoreStrategy) Compose(results []ModelResult) (string, error)

func (*BestScoreStrategy) Name

func (s *BestScoreStrategy) Name() string

type ChainExecutionResult

type ChainExecutionResult struct {
	ChainName   string
	Input       string
	Output      string
	StepResults []ChainStepResult
	Success     bool
	Error       error
	Duration    time.Duration
}

ChainExecutionResult represents the result of executing a chain

type ChainExecutor

type ChainExecutor interface {
	ExecuteModel(ctx context.Context, modelID string, prompt string) (string, error)
}

ChainExecutor interface for executing models

type ChainStats

type ChainStats struct {
	TotalExecutions  int64
	SuccessfulChains int64
	FailedChains     int64
	AvgExecutionTime time.Duration
	StepStats        map[string]*StepStats
}

ChainStats tracks chain execution statistics

type ChainStep

type ChainStep struct {
	Name        string
	ModelID     string
	Type        StepType
	Transform   TransformFunc
	Condition   ConditionFunc
	Aggregation AggregationFunc
	Timeout     time.Duration
	Optional    bool // If true, failure doesn't break the chain
}

ChainStep represents a single step in the chain

type ChainStepResult

type ChainStepResult struct {
	StepName  string
	ModelID   string
	Input     string
	Output    string
	Error     error
	Duration  time.Duration
	Timestamp time.Time
	Skipped   bool
}

ChainStepResult represents the result of a chain step

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker protects against cascading failures

func NewCircuitBreaker

func NewCircuitBreaker(name string, config CircuitBreakerConfig) *CircuitBreaker

NewCircuitBreaker creates a new circuit breaker

func (*CircuitBreaker) Call

func (cb *CircuitBreaker) Call(fn func() error) error

Call executes a function with circuit breaker protection

func (*CircuitBreaker) GetState

func (cb *CircuitBreaker) GetState() CircuitState

GetState returns the current state

func (*CircuitBreaker) GetStats

func (cb *CircuitBreaker) GetStats() map[string]interface{}

GetStats returns circuit breaker statistics

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

Reset resets the circuit breaker to closed state

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	FailureThreshold int           // Failures before opening
	SuccessThreshold int           // Successes before closing from half-open
	Timeout          time.Duration // Time before attempting recovery
}

CircuitBreakerConfig holds circuit breaker configuration

type CircuitBreakerManager

type CircuitBreakerManager struct {
	// contains filtered or unexported fields
}

CircuitBreakerManager manages multiple circuit breakers

func NewCircuitBreakerManager

func NewCircuitBreakerManager(config CircuitBreakerConfig) *CircuitBreakerManager

NewCircuitBreakerManager creates a new manager

func (*CircuitBreakerManager) GetAllBreakers

func (cbm *CircuitBreakerManager) GetAllBreakers() map[string]*CircuitBreaker

GetAllBreakers returns all circuit breakers

func (*CircuitBreakerManager) GetAllStats

func (cbm *CircuitBreakerManager) GetAllStats() []map[string]interface{}

GetAllStats returns statistics for all circuit breakers

func (*CircuitBreakerManager) GetBreaker

func (cbm *CircuitBreakerManager) GetBreaker(modelName string) *CircuitBreaker

GetBreaker gets or creates a circuit breaker for a model

func (*CircuitBreakerManager) ResetAll

func (cbm *CircuitBreakerManager) ResetAll()

ResetAll resets all circuit breakers

type CircuitState

type CircuitState string

CircuitState represents the state of a circuit breaker

const (
	StateClosed   CircuitState = "closed"    // Normal operation
	StateOpen     CircuitState = "open"      // Blocking requests
	StateHalfOpen CircuitState = "half-open" // Testing recovery
)

type ComplexityAnalyzer

type ComplexityAnalyzer struct {
	// contains filtered or unexported fields
}

ComplexityAnalyzer analyzes prompt complexity

func NewComplexityAnalyzer

func NewComplexityAnalyzer() *ComplexityAnalyzer

NewComplexityAnalyzer creates a new complexity analyzer

func (*ComplexityAnalyzer) Analyze

func (ca *ComplexityAnalyzer) Analyze(prompt string) *PromptAnalysis

Analyze analyzes a prompt and returns complexity information

func (*ComplexityAnalyzer) GetRecommendedModelType

func (ca *ComplexityAnalyzer) GetRecommendedModelType(analysis *PromptAnalysis) string

GetRecommendedModelType returns recommended model type based on complexity

type ComplexityLevel

type ComplexityLevel string

ComplexityLevel represents the difficulty of a prompt

const (
	ComplexityLow    ComplexityLevel = "low"
	ComplexityMedium ComplexityLevel = "medium"
	ComplexityHigh   ComplexityLevel = "high"
)

type CompositionStats

type CompositionStats struct {
	TotalCompositions int64
	ByStrategy        map[string]int64
	AvgDuration       time.Duration
	Failures          int64
}

CompositionStats tracks composition statistics

type CompositionStrategy

type CompositionStrategy interface {
	Compose(results []ModelResult) (string, error)
	Name() string
}

CompositionStrategy defines how to combine model outputs

type ConcatenateStrategy

type ConcatenateStrategy struct{}

ConcatenateStrategy concatenates all outputs

func (*ConcatenateStrategy) Compose

func (s *ConcatenateStrategy) Compose(results []ModelResult) (string, error)

func (*ConcatenateStrategy) Name

func (s *ConcatenateStrategy) Name() string

type ConditionFunc

type ConditionFunc func(input string, previousResults []ChainStepResult) bool

ConditionFunc determines if a step should execute

func AlwaysExecuteCondition

func AlwaysExecuteCondition() ConditionFunc

AlwaysExecuteCondition always returns true

func OnlyIfContainsCondition

func OnlyIfContainsCondition(substring string) ConditionFunc

OnlyIfContainsCondition executes only if input contains a substring

func OnlyIfPreviousSucceededCondition

func OnlyIfPreviousSucceededCondition() ConditionFunc

OnlyIfPreviousSucceededCondition executes only if previous step succeeded

type FallbackChain

type FallbackChain struct {
	// contains filtered or unexported fields
}

FallbackChain represents a chain of fallback models

func NewFallbackChain

func NewFallbackChain(models []types.Model) *FallbackChain

NewFallbackChain creates a new fallback chain

func (*FallbackChain) Execute

func (fc *FallbackChain) Execute(ctx context.Context, fn func(model types.Model) error) error

Execute tries each model in the chain until one succeeds

func (*FallbackChain) ExecuteWithResult

func (fc *FallbackChain) ExecuteWithResult(ctx context.Context, fn func(model types.Model) (interface{}, error)) (interface{}, error)

ExecuteWithResult tries each model until one succeeds and returns result

type FallbackStrategy

type FallbackStrategy struct {
	// contains filtered or unexported fields
}

FallbackStrategy manages fallback configurations

func NewFallbackStrategy

func NewFallbackStrategy(primary types.Model, fallbacks []types.Model) *FallbackStrategy

NewFallbackStrategy creates a new fallback strategy

func (*FallbackStrategy) Execute

func (fs *FallbackStrategy) Execute(ctx context.Context, fn func(model types.Model) error) error

Execute executes with fallback strategy

func (*FallbackStrategy) ExecuteWithResult

func (fs *FallbackStrategy) ExecuteWithResult(ctx context.Context, fn func(model types.Model) (interface{}, error)) (interface{}, error)

ExecuteWithResult executes with fallback strategy and returns result

func (*FallbackStrategy) GetChain

func (fs *FallbackStrategy) GetChain() []types.Model

GetChain returns the complete fallback chain

type FirstSuccessfulStrategy

type FirstSuccessfulStrategy struct{}

FirstSuccessfulStrategy returns the first successful result

func (*FirstSuccessfulStrategy) Compose

func (s *FirstSuccessfulStrategy) Compose(results []ModelResult) (string, error)

func (*FirstSuccessfulStrategy) Name

func (s *FirstSuccessfulStrategy) Name() string

type HealthCheckConfig

type HealthCheckConfig struct {
	CheckInterval    time.Duration // How often to check
	FailureThreshold int           // Failures before marking unavailable
	SuccessThreshold int           // Successes before marking available
	Enabled          bool
}

HealthCheckConfig holds health check configuration

func DefaultHealthCheckConfig

func DefaultHealthCheckConfig() HealthCheckConfig

DefaultHealthCheckConfig returns default health check configuration

type HealthChecker

type HealthChecker struct {
	// contains filtered or unexported fields
}

HealthChecker monitors model health

func NewHealthChecker

func NewHealthChecker(config HealthCheckConfig) *HealthChecker

NewHealthChecker creates a new health checker

func (*HealthChecker) GetAllHealth

func (hc *HealthChecker) GetAllHealth() map[string]*ModelHealth

GetAllHealth returns health status for all models

func (*HealthChecker) GetHealth

func (hc *HealthChecker) GetHealth(modelName string) *ModelHealth

GetHealth returns health status for a model

func (*HealthChecker) GetHealthStats

func (hc *HealthChecker) GetHealthStats() map[string]interface{}

GetHealthStats returns aggregated health statistics

func (*HealthChecker) IsHealthy

func (hc *HealthChecker) IsHealthy(modelName string) bool

IsHealthy returns true if a model is healthy

func (*HealthChecker) Start

func (hc *HealthChecker) Start()

Start begins health checking

func (*HealthChecker) Stop

func (hc *HealthChecker) Stop()

Stop stops health checking

type LeastCostAlgorithm

type LeastCostAlgorithm struct {
	// contains filtered or unexported fields
}

LeastCostAlgorithm selects the cheapest available model

func NewLeastCostAlgorithm

func NewLeastCostAlgorithm() *LeastCostAlgorithm

NewLeastCostAlgorithm creates a new least-cost algorithm

func (*LeastCostAlgorithm) SelectModel

func (lc *LeastCostAlgorithm) SelectModel(models []types.Model, analysis *PromptAnalysis) (*types.Model, error)

SelectModel selects the model with lowest cost

type LeastLatencyAlgorithm

type LeastLatencyAlgorithm struct {
	// contains filtered or unexported fields
}

LeastLatencyAlgorithm selects the fastest available model

func NewLeastLatencyAlgorithm

func NewLeastLatencyAlgorithm() *LeastLatencyAlgorithm

NewLeastLatencyAlgorithm creates a new least-latency algorithm

func (*LeastLatencyAlgorithm) SelectModel

func (ll *LeastLatencyAlgorithm) SelectModel(models []types.Model, analysis *PromptAnalysis) (*types.Model, error)

SelectModel selects the model with lowest latency

type MajorityVoteStrategy

type MajorityVoteStrategy struct{}

MajorityVoteStrategy returns the most common output

func (*MajorityVoteStrategy) Compose

func (s *MajorityVoteStrategy) Compose(results []ModelResult) (string, error)

func (*MajorityVoteStrategy) Name

func (s *MajorityVoteStrategy) Name() string

type ModelChain

type ModelChain struct {
	Name  string
	Steps []ChainStep
	Stats *ChainStats
}

ModelChain represents a sequence of model operations

func NewModelChain

func NewModelChain(name string) *ModelChain

NewModelChain creates a new model chain

func (*ModelChain) AddStep

func (mc *ModelChain) AddStep(step ChainStep) *ModelChain

AddStep adds a step to the chain

func (*ModelChain) Execute

func (mc *ModelChain) Execute(ctx context.Context, input string, executor ChainExecutor) (*ChainExecutionResult, error)

Execute runs the model chain

func (*ModelChain) GetStats

func (mc *ModelChain) GetStats() *ChainStats

GetStats returns chain statistics

type ModelComposer

type ModelComposer struct {
	// contains filtered or unexported fields
}

ModelComposer handles composition of multiple model outputs

func NewModelComposer

func NewModelComposer() *ModelComposer

NewModelComposer creates a new model composer

func (*ModelComposer) Compose

func (mc *ModelComposer) Compose(ctx context.Context, results []ModelResult, strategyName string) (string, error)

Compose combines multiple model results using the specified strategy

func (*ModelComposer) ExecuteParallel

func (mc *ModelComposer) ExecuteParallel(ctx context.Context, modelIDs []string, input string, executor ChainExecutor) []ModelResult

ExecuteParallel executes multiple models in parallel

func (*ModelComposer) GetStats

func (mc *ModelComposer) GetStats() *CompositionStats

GetStats returns composition statistics

func (*ModelComposer) RegisterStrategy

func (mc *ModelComposer) RegisterStrategy(strategy CompositionStrategy)

RegisterStrategy registers a composition strategy

type ModelExecutor

type ModelExecutor struct {
	// contains filtered or unexported fields
}

ModelExecutor executes model requests

func NewModelExecutor

func NewModelExecutor() *ModelExecutor

NewModelExecutor creates a new model executor

func (*ModelExecutor) ClearCache

func (me *ModelExecutor) ClearCache()

ClearCache clears the execution cache

func (*ModelExecutor) ExecuteModel

func (me *ModelExecutor) ExecuteModel(ctx context.Context, modelID string, prompt string) (string, error)

ExecuteModel executes a model request (implements ChainExecutor interface)

func (*ModelExecutor) GetCallCount

func (me *ModelExecutor) GetCallCount() int64

GetCallCount returns the number of model calls made

type ModelHealth

type ModelHealth struct {
	ModelName            string
	Available            bool
	LastCheckTime        time.Time
	LastSuccessTime      time.Time
	LastFailureTime      time.Time
	ConsecutiveFailures  int
	ConsecutiveSuccesses int
	TotalChecks          int
	SuccessfulChecks     int
	FailedChecks         int
	AvgResponseTime      time.Duration
}

ModelHealth represents the health status of a model

type ModelResult

type ModelResult struct {
	ModelID  string
	Input    string
	Output   string
	Error    error
	Duration time.Duration
	Score    float64 // Quality/confidence score
}

ModelResult represents a result from a single model

type ModelScore

type ModelScore struct {
	Model types.Model
	Score float64
}

ModelScore represents a model with its calculated score

type ModelScorer

type ModelScorer struct {
	// contains filtered or unexported fields
}

ModelScorer scores models based on various criteria

func CostOptimizedScorer

func CostOptimizedScorer() *ModelScorer

CostOptimizedScorer prioritizes low cost

func DefaultScorer

func DefaultScorer() *ModelScorer

DefaultScorer returns a scorer with balanced weights

func NewModelScorer

func NewModelScorer(weights ScoreWeights) *ModelScorer

NewModelScorer creates a new model scorer

func QualityOptimizedScorer

func QualityOptimizedScorer() *ModelScorer

QualityOptimizedScorer prioritizes high quality

func SpeedOptimizedScorer

func SpeedOptimizedScorer() *ModelScorer

SpeedOptimizedScorer prioritizes low latency

func (*ModelScorer) ScoreModel

func (ms *ModelScorer) ScoreModel(model types.Model, estimatedTokens int) float64

ScoreModel scores a single model based on weights

func (*ModelScorer) ScoreModels

func (ms *ModelScorer) ScoreModels(models []types.Model, estimatedTokens int) []ModelScore

ScoreModels scores all models and returns sorted by score

type OrchestrationStats

type OrchestrationStats struct {
	TotalRequests      int64
	ChainExecutions    int64
	CompositionCount   int64
	ParallelExecutions int64
	AvgExecutionTime   time.Duration
	Failures           int64
}

OrchestrationStats tracks orchestration statistics

type Orchestrator

type Orchestrator struct {
	// contains filtered or unexported fields
}

Orchestrator manages multi-model orchestration (Day 8)

func NewOrchestrator

func NewOrchestrator(router *Router) *Orchestrator

NewOrchestrator creates a new orchestrator

func (*Orchestrator) ConditionalRoute

func (o *Orchestrator) ConditionalRoute(ctx context.Context, input string, conditions []RouteCondition) (string, error)

ConditionalRoute routes based on custom conditions

func (*Orchestrator) ExecuteChain

func (o *Orchestrator) ExecuteChain(ctx context.Context, chainName string, input string) (*ChainExecutionResult, error)

ExecuteChain executes a registered chain

func (*Orchestrator) ExecuteParallelComposition

func (o *Orchestrator) ExecuteParallelComposition(ctx context.Context, modelIDs []string, input string, strategy string) (string, error)

ExecuteParallelComposition executes multiple models in parallel and composes results

func (*Orchestrator) GetStats

func (o *Orchestrator) GetStats() *OrchestrationStats

GetStats returns orchestration statistics

func (*Orchestrator) RegisterChain

func (o *Orchestrator) RegisterChain(chain *ModelChain)

RegisterChain registers a model chain

type PromptAnalysis

type PromptAnalysis struct {
	TokenCount       int
	Complexity       ComplexityLevel
	HasCode          bool
	HasTechnical     bool
	EstimatedCost    float64
	RecommendedModel string
}

PromptAnalysis contains analysis results of a prompt

type RetryConfig

type RetryConfig struct {
	MaxAttempts  int           // Maximum number of attempts (including first try)
	InitialDelay time.Duration // Initial delay before first retry
	MaxDelay     time.Duration // Maximum delay between retries
	Multiplier   float64       // Backoff multiplier
	Jitter       bool          // Add randomness to delay
}

RetryConfig holds retry configuration

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns default retry configuration

type RetryStrategy

type RetryStrategy struct {
	// contains filtered or unexported fields
}

RetryStrategy executes a function with retry logic

func NewRetryStrategy

func NewRetryStrategy(config RetryConfig) *RetryStrategy

NewRetryStrategy creates a new retry strategy

func (*RetryStrategy) Execute

func (rs *RetryStrategy) Execute(ctx context.Context, fn func() error) error

Execute executes a function with retry logic

func (*RetryStrategy) ExecuteWithResult

func (rs *RetryStrategy) ExecuteWithResult(ctx context.Context, fn func() (interface{}, error)) (interface{}, error)

ExecuteWithResult executes a function that returns a result

type RoundRobinAlgorithm

type RoundRobinAlgorithm struct {
	// contains filtered or unexported fields
}

RoundRobinAlgorithm distributes requests evenly across models

func NewRoundRobinAlgorithm

func NewRoundRobinAlgorithm() *RoundRobinAlgorithm

NewRoundRobinAlgorithm creates a new round-robin algorithm

func (*RoundRobinAlgorithm) SelectModel

func (rr *RoundRobinAlgorithm) SelectModel(models []types.Model, analysis *PromptAnalysis) (*types.Model, error)

SelectModel selects the next model in round-robin fashion

type RouteCondition

type RouteCondition struct {
	Name     string
	ModelID  string
	Evaluate func(input string) bool
}

RouteCondition represents a routing condition

func ComplexityBasedCondition

func ComplexityBasedCondition(name string, minComplexity int, modelID string) RouteCondition

ComplexityBasedCondition routes based on complexity (simple heuristic)

func KeywordBasedCondition

func KeywordBasedCondition(name string, keywords []string, modelID string) RouteCondition

KeywordBasedCondition routes if input contains specific keywords

func LengthBasedCondition

func LengthBasedCondition(name string, minLen, maxLen int, modelID string) RouteCondition

LengthBasedCondition routes based on input length

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router handles intelligent routing of requests to models

func GetGlobalRouter

func GetGlobalRouter() *Router

GetGlobalRouter returns the global router instance

func NewRouter

func NewRouter(config *RoutingConfig) *Router

NewRouter creates a new router instance

func (*Router) AnalyzePrompt

func (r *Router) AnalyzePrompt(prompt string) *PromptAnalysis

AnalyzePrompt analyzes a prompt without routing

func (*Router) GetAvailableModels

func (r *Router) GetAvailableModels() ([]types.Model, error)

GetAvailableModels returns all available models

func (*Router) GetCircuitBreakerStats

func (r *Router) GetCircuitBreakerStats() []map[string]interface{}

GetCircuitBreakerStats returns circuit breaker statistics

func (*Router) GetConfig

func (r *Router) GetConfig() *RoutingConfig

GetConfig returns the current configuration

func (*Router) GetHealthStats

func (r *Router) GetHealthStats() map[string]interface{}

GetHealthStats returns health check statistics

func (*Router) GetModelHealth

func (r *Router) GetModelHealth() map[string]*ModelHealth

GetModelHealth returns health status for all models

func (*Router) GetStats

func (r *Router) GetStats() *RouterStats

GetStats returns routing statistics

func (*Router) GetStrategy

func (r *Router) GetStrategy() RoutingStrategy

GetStrategy returns the current routing strategy

func (*Router) ResetStats

func (r *Router) ResetStats()

ResetStats resets routing statistics

func (*Router) Route

func (r *Router) Route(ctx context.Context, prompt string) (*RoutingDecision, error)

Route selects the best model for a request

func (*Router) RouteWithFallback

func (r *Router) RouteWithFallback(ctx context.Context, prompt string, fn func(model types.Model) error) error

RouteWithFallback routes with automatic fallback on failure

func (*Router) RouteWithModel

func (r *Router) RouteWithModel(ctx context.Context, modelName string) (*RoutingDecision, error)

RouteWithModel routes to a specific model (bypass algorithm)

func (*Router) SetStrategy

func (r *Router) SetStrategy(strategy RoutingStrategy)

SetStrategy changes the routing strategy

func (*Router) Shutdown

func (r *Router) Shutdown()

Shutdown gracefully shuts down the router

type RouterStats

type RouterStats struct {
	TotalRequests       int64
	RequestsByStrategy  map[RoutingStrategy]int64
	RequestsByModel     map[string]int64
	AvgRoutingTime      time.Duration
	FailedRequests      int64
	FallbackUsed        int64
	CircuitBreakerTrips int64
}

RouterStats tracks routing statistics

type RoutingAlgorithm

type RoutingAlgorithm interface {
	SelectModel(models []types.Model, analysis *PromptAnalysis) (*types.Model, error)
}

RoutingAlgorithm interface for different routing strategies

func GetAlgorithm

func GetAlgorithm(strategy RoutingStrategy) RoutingAlgorithm

GetAlgorithm returns the appropriate algorithm for a strategy

type RoutingConfig

type RoutingConfig struct {
	Strategy            RoutingStrategy
	EnableFallback      bool
	EnableCircuitBreak  bool
	MaxRetries          int
	RetryDelay          time.Duration
	HealthCheckEnabled  bool
	HealthCheckInterval time.Duration
}

RoutingConfig holds configuration for the router

func DefaultConfig

func DefaultConfig() *RoutingConfig

DefaultConfig returns default routing configuration

type RoutingDecision

type RoutingDecision struct {
	SelectedModel types.Model
	Strategy      RoutingStrategy
	Complexity    ComplexityLevel
	Score         float64
	Reason        string
	Timestamp     time.Time
}

RoutingDecision contains information about routing decision

type RoutingStrategy

type RoutingStrategy string

RoutingStrategy defines how to select a model

const (
	StrategyRoundRobin   RoutingStrategy = "round-robin"
	StrategyLeastCost    RoutingStrategy = "least-cost"
	StrategyLeastLatency RoutingStrategy = "least-latency"
	StrategyBestQuality  RoutingStrategy = "best-quality"
	StrategySmart        RoutingStrategy = "smart"
)

type ScoreWeights

type ScoreWeights struct {
	Cost    float64 // Weight for cost (0-1)
	Latency float64 // Weight for latency (0-1)
	Quality float64 // Weight for quality (0-1)
}

ScoreWeights defines weights for different scoring factors

type SmartAlgorithm

type SmartAlgorithm struct {
	// contains filtered or unexported fields
}

SmartAlgorithm selects model based on prompt complexity

func NewSmartAlgorithm

func NewSmartAlgorithm() *SmartAlgorithm

NewSmartAlgorithm creates a new smart algorithm

func (*SmartAlgorithm) SelectModel

func (sa *SmartAlgorithm) SelectModel(models []types.Model, analysis *PromptAnalysis) (*types.Model, error)

SelectModel selects model based on complexity analysis

type StepStats

type StepStats struct {
	Executions  int64
	Successes   int64
	Failures    int64
	Skipped     int64
	AvgDuration time.Duration
}

StepStats tracks statistics for individual steps

type StepType

type StepType string

StepType defines the type of chain step

const (
	StepTypeSequential  StepType = "sequential"  // Execute one after another
	StepTypeParallel    StepType = "parallel"    // Execute concurrently
	StepTypeConditional StepType = "conditional" // Execute based on condition
	StepTypeAggregate   StepType = "aggregate"   // Combine multiple results
)

type TransformFunc

type TransformFunc func(input string, previousResult string) string

TransformFunc transforms input before sending to next step

func ChainPreviousResultTransform

func ChainPreviousResultTransform() TransformFunc

ChainPreviousResultTransform uses previous step's output as input

func PrefixTransform

func PrefixTransform(prefix string) TransformFunc

PrefixTransform adds a prefix to the input

func SuffixTransform

func SuffixTransform(suffix string) TransformFunc

SuffixTransform adds a suffix to the input

func TemplateTransform

func TemplateTransform(template string) TransformFunc

TemplateTransform applies a template with placeholders

type WeightedAverageStrategy

type WeightedAverageStrategy struct{}

WeightedAverageStrategy uses scores as weights

func (*WeightedAverageStrategy) Compose

func (s *WeightedAverageStrategy) Compose(results []ModelResult) (string, error)

func (*WeightedAverageStrategy) Name

func (s *WeightedAverageStrategy) Name() string

type WeightedRoundRobinAlgorithm

type WeightedRoundRobinAlgorithm struct {
	// contains filtered or unexported fields
}

WeightedRoundRobinAlgorithm distributes based on model weights

func NewWeightedRoundRobinAlgorithm

func NewWeightedRoundRobinAlgorithm(weights map[string]int) *WeightedRoundRobinAlgorithm

NewWeightedRoundRobinAlgorithm creates a weighted round-robin algorithm

func (*WeightedRoundRobinAlgorithm) SelectModel

func (wrr *WeightedRoundRobinAlgorithm) SelectModel(models []types.Model, analysis *PromptAnalysis) (*types.Model, error)

SelectModel selects model based on weighted distribution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL