Documentation
¶
Overview ¶
Package model provides model routing and health checking. Model discovery, pricing, and catalog data are delegated to eyrie. Hawk does NOT carry a hardcoded model catalog.
Index ¶
- func AllProviders() []string
- func CheapestForProvider(provider, fallback string) string
- func DefaultModel(provider string) string
- func RegisterDynamic(info ModelInfo)
- type Capabilities
- type CascadeRouter
- type CircuitState
- type CodeHealth
- type HealthRouter
- type LatencyClass
- type ModelInfo
- type ModelRoles
- type ModelTier
- type ProviderHealth
- type Role
- type Router
- func (r *Router) HealthStatus() map[string]*ProviderHealth
- func (r *Router) RecordFailure(provider string, err error)
- func (r *Router) RecordSuccess(provider string, latency time.Duration)
- func (r *Router) Score(provider string) float64
- func (r *Router) SelectProvider(preferred string) (string, error)
- func (r *Router) SelectProviderForModel(modelName string) (string, ModelInfo, error)
- func (r *Router) SetFallbackChain(chain []string)
- type RoutingStrategy
- type TaskType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllProviders ¶
func AllProviders() []string
AllProviders returns all provider names from eyrie's catalog.
func CheapestForProvider ¶
CheapestForProvider queries eyrie's catalog at runtime and returns the cheapest model for the given provider. No hardcoded model names.
func DefaultModel ¶
DefaultModel returns the default model for a provider via eyrie.
func RegisterDynamic ¶
func RegisterDynamic(info ModelInfo)
RegisterDynamic adds a model entry at runtime (custom providers).
Types ¶
type Capabilities ¶
type Capabilities struct {
Streaming bool `json:"streaming"`
FunctionCalling bool `json:"function_calling"`
Vision bool `json:"vision"`
JSON bool `json:"json"`
Thinking bool `json:"thinking"`
}
Capabilities describes what a model supports.
type CascadeRouter ¶
type CascadeRouter struct {
// contains filtered or unexported fields
}
CascadeRouter selects models based on task classification. It uses heuristic keyword matching to avoid LLM calls for routing.
func NewCascadeRouter ¶
func NewCascadeRouter(roles ModelRoles) *CascadeRouter
NewCascadeRouter creates a cascade router with the given role assignments.
func (*CascadeRouter) ModelForTask ¶
func (cr *CascadeRouter) ModelForTask(task TaskType) string
ModelForTask returns the model assigned to the given task type.
type CircuitState ¶
type CircuitState int
CircuitState represents circuit breaker state.
const ( CircuitClosed CircuitState = iota // normal CircuitOpen // rejecting CircuitHalfOpen // testing )
type CodeHealth ¶
type CodeHealth struct {
Complexity float64 // cyclomatic complexity estimate
FileSize int // lines of code
Dependencies int // import count
TestCoverage float64 // if known (0-1)
Language string
}
CodeHealth captures complexity metrics for a source file, used to route tasks to the cheapest model that can handle the file's complexity.
type HealthRouter ¶
type HealthRouter struct {
// contains filtered or unexported fields
}
HealthRouter selects the cheapest appropriate model tier based on a file's code health metrics.
func NewHealthRouter ¶
func NewHealthRouter() *HealthRouter
NewHealthRouter creates a router with the default tier configuration.
func (*HealthRouter) ComputeHealth ¶
func (hr *HealthRouter) ComputeHealth(path string) CodeHealth
ComputeHealth estimates code health metrics for a file at the given path. It reads the file and analyses line count, nesting depth, and import count.
func (*HealthRouter) ModelForTask ¶
func (hr *HealthRouter) ModelForTask(path string, primaryModel string) string
ModelForTask returns the cheapest appropriate model for the file's health level. If the selected tier contains the primaryModel, it is returned. Otherwise, the first model in the selected tier is returned.
func (*HealthRouter) SelectTier ¶
func (hr *HealthRouter) SelectTier(health CodeHealth) string
SelectTier returns the tier name appropriate for the given code health.
- "light": simple files (<100 lines, low complexity)
- "standard": moderate files (100-500 lines)
- "heavy": complex files (>500 lines, high complexity, many deps)
type LatencyClass ¶
type LatencyClass string
LatencyClass categorizes model response speed.
const ( LatencyFast LatencyClass = "fast" LatencyMedium LatencyClass = "medium" LatencySlow LatencyClass = "slow" )
type ModelInfo ¶
type ModelInfo struct {
Name string `json:"name"`
Provider string `json:"provider"`
ContextSize int `json:"context_size"`
InputPrice float64 `json:"input_price_per_million"`
OutputPrice float64 `json:"output_price_per_million"`
Description string `json:"description,omitempty"`
Recommended bool `json:"recommended,omitempty"`
}
ModelInfo describes a known LLM model (hawk's internal representation).
func ByProvider ¶
ByProvider returns all models for a given provider from eyrie's catalog.
func Recommended ¶
Recommended returns the recommended model for a provider. Delegates to eyrie's GetProviderDefaultModel.
type ModelRoles ¶
type ModelRoles struct {
Planner string `json:"planner,omitempty"`
Coder string `json:"coder,omitempty"`
Reviewer string `json:"reviewer,omitempty"`
Commit string `json:"commit,omitempty"`
}
ModelRoles maps each role to a specific model name. Empty fields fall back to the primary (coder) model.
func DefaultRoles ¶
func DefaultRoles(primaryModel string) ModelRoles
DefaultRoles returns a ModelRoles where every role uses primaryModel except Commit, which defaults to the cheapest available model from the catalog.
func (ModelRoles) ModelForRole ¶
func (r ModelRoles) ModelForRole(role Role) string
ModelForRole returns the model name assigned to role, falling back to the Coder model (primary) if the role-specific field is empty.
type ModelTier ¶
type ModelTier struct {
Name string // "light", "standard", "heavy"
Models []string // model names in this tier
MaxComplexity float64 // max code health score for this tier
}
ModelTier groups models by the code complexity they can handle.
func DefaultTiers ¶
func DefaultTiers() []ModelTier
DefaultTiers returns the standard three-tier configuration.
type ProviderHealth ¶
type ProviderHealth struct {
Available bool `json:"available"`
LastCheck time.Time `json:"last_check"`
LastSuccess time.Time `json:"last_success"`
ConsecutiveFails int `json:"consecutive_fails"`
AvgLatencyMs float64 `json:"avg_latency_ms"`
}
ProviderHealth tracks the health state of a provider.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router provides health-aware provider routing with fallback.
func NewRouter ¶
func NewRouter(strategy RoutingStrategy) *Router
NewRouter creates a new provider router with a default fallback chain.
func (*Router) HealthStatus ¶
func (r *Router) HealthStatus() map[string]*ProviderHealth
HealthStatus returns health info for all tracked providers.
func (*Router) RecordFailure ¶
RecordFailure records a failed API call for a provider.
func (*Router) RecordSuccess ¶
RecordSuccess records a successful API call for a provider.
func (*Router) SelectProvider ¶
SelectProvider chooses the best available provider, falling back if needed.
func (*Router) SelectProviderForModel ¶
SelectProviderForModel chooses the best provider for a specific model.
func (*Router) SetFallbackChain ¶
SetFallbackChain sets the provider fallback order.
type RoutingStrategy ¶
type RoutingStrategy string
RoutingStrategy determines how the router selects providers.
const ( StrategyLatency RoutingStrategy = "latency" StrategyCost RoutingStrategy = "cost" StrategyBalanced RoutingStrategy = "balanced" )
type TaskType ¶
type TaskType string
TaskType classifies a user message for model routing.
func ClassifyTask ¶
ClassifyTask uses keyword heuristics to determine the task type from a message.