Documentation
¶
Index ¶
- type ActivationRule
- type ConditionEvaluator
- type ContextInjector
- func (i *ContextInjector) ApplyProviderSettings(metadata map[string]interface{}, settings map[string]any) map[string]interface{}
- func (i *ContextInjector) FormatContextInjection(template string, ctx *RoutingContext) string
- func (i *ContextInjector) InjectSystemPrompt(messages []map[string]string, prompt string) []map[string]string
- type RoutePreferences
- type RoutingContext
- type SteeringEngine
- func (e *SteeringEngine) ApplySteering(ctx *RoutingContext, messages []map[string]string, ...) (string, []map[string]string, map[string]interface{})
- func (e *SteeringEngine) FindMatchingRules(ctx *RoutingContext) ([]*SteeringRule, error)
- func (e *SteeringEngine) GetRules() []*SteeringRule
- func (e *SteeringEngine) LoadRules() error
- func (e *SteeringEngine) StartWatcher() error
- func (e *SteeringEngine) StopWatcher()
- type SteeringRule
- type TimeBasedRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivationRule ¶
type ActivationRule struct {
Condition string `yaml:"condition" json:"condition"` // Expression: "intent == 'coding'"
Priority int `yaml:"priority" json:"priority"` // Higher = more important
}
ActivationRule defines when a rule should be triggered.
type ConditionEvaluator ¶
type ConditionEvaluator struct {
// contains filtered or unexported fields
}
ConditionEvaluator handles the evaluation of activation conditions.
func NewConditionEvaluator ¶
func NewConditionEvaluator() *ConditionEvaluator
NewConditionEvaluator creates a new condition evaluator.
func (*ConditionEvaluator) CheckTimeRule ¶
func (e *ConditionEvaluator) CheckTimeRule(rule TimeBasedRule, now time.Time) bool
CheckTimeRule checks if the current time matches a time-based rule.
func (*ConditionEvaluator) Evaluate ¶
func (e *ConditionEvaluator) Evaluate(condition string, ctx *RoutingContext) (bool, error)
Evaluate evaluates a condition string against the provided routing context.
type ContextInjector ¶
type ContextInjector struct{}
ContextInjector handles modifications to RoutingRequests based on steering rules.
func NewContextInjector ¶
func NewContextInjector() *ContextInjector
NewContextInjector creates a new context injector.
func (*ContextInjector) ApplyProviderSettings ¶
func (i *ContextInjector) ApplyProviderSettings(metadata map[string]interface{}, settings map[string]any) map[string]interface{}
ApplyProviderSettings applies specialized settings for the selected provider. This is used slightly later in the pipeline when the model is already selected, or it can be used to prepare a template of settings.
func (*ContextInjector) FormatContextInjection ¶
func (i *ContextInjector) FormatContextInjection(template string, ctx *RoutingContext) string
FormatContextInjection templates the injection string if it contains variables.
func (*ContextInjector) InjectSystemPrompt ¶
func (i *ContextInjector) InjectSystemPrompt(messages []map[string]string, prompt string) []map[string]string
InjectSystemPrompt adds a system message to the beginning of the messages slice.
type RoutePreferences ¶
type RoutePreferences struct {
PrimaryModel string `yaml:"primary_model,omitempty" json:"primary_model,omitempty"`
FallbackModels []string `yaml:"fallback_models,omitempty" json:"fallback_models,omitempty"`
OverrideRouter bool `yaml:"override_router" json:"override_router"`
ContextInjection string `yaml:"context_injection,omitempty" json:"context_injection,omitempty"`
ProviderSettings map[string]any `yaml:"provider_settings,omitempty" json:"provider_settings,omitempty"`
TimeBasedRules []TimeBasedRule `yaml:"time_based_rules,omitempty" json:"time_based_rules,omitempty"`
}
RoutePreferences defines the routing overrides and modifications.
type RoutingContext ¶
type RoutingContext struct {
Intent string `json:"intent"`
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
APIKeyHash string `json:"api_key_hash,omitempty"`
ContentLength int `json:"content_length"`
Hour int `json:"hour"`
DayOfWeek string `json:"day_of_week"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
RoutingContext provides the environment for condition evaluation.
type SteeringEngine ¶
type SteeringEngine struct {
// contains filtered or unexported fields
}
SteeringEngine manages the lifecycle and matching of steering rules.
func NewSteeringEngine ¶
func NewSteeringEngine(steeringDir string) (*SteeringEngine, error)
NewSteeringEngine creates a new steering engine.
func (*SteeringEngine) ApplySteering ¶
func (e *SteeringEngine) ApplySteering(ctx *RoutingContext, messages []map[string]string, metadata map[string]interface{}, rules []*SteeringRule) (string, []map[string]string, map[string]interface{})
ApplySteering applies the matched rules to a request context. It modifies the primary model, fallbacks, and injects context as specified by the rules.
func (*SteeringEngine) FindMatchingRules ¶
func (e *SteeringEngine) FindMatchingRules(ctx *RoutingContext) ([]*SteeringRule, error)
FindMatchingRules finds all rules that activate for the given context.
func (*SteeringEngine) GetRules ¶
func (e *SteeringEngine) GetRules() []*SteeringRule
GetRules returns the currently loaded rules.
func (*SteeringEngine) LoadRules ¶
func (e *SteeringEngine) LoadRules() error
LoadRules loads all steering rules from the steering directory.
func (*SteeringEngine) StartWatcher ¶
func (e *SteeringEngine) StartWatcher() error
StartWatcher starts a background fsnotify watcher for hot-reloading rules.
func (*SteeringEngine) StopWatcher ¶
func (e *SteeringEngine) StopWatcher()
StopWatcher stops the file watcher.
type SteeringRule ¶
type SteeringRule struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description" json:"description"`
Activation ActivationRule `yaml:"activation" json:"activation"`
Preferences RoutePreferences `yaml:"preferences" json:"preferences"`
Metadata map[string]string `yaml:"metadata,omitempty" json:"metadata,omitempty"`
// FilePath is the source file of the rule (not in YAML)
FilePath string `yaml:"-" json:"-"`
}
SteeringRule represents a single routing steering rule.
type TimeBasedRule ¶
type TimeBasedRule struct {
Hours string `yaml:"hours,omitempty" json:"hours,omitempty"` // "9-11" or "9:00-11:00"
Days string `yaml:"days,omitempty" json:"days,omitempty"` // "Mon-Fri" or "1,2,3,4,5"
PreferModel string `yaml:"prefer_model,omitempty" json:"prefer_model,omitempty"`
Reason string `yaml:"reason,omitempty" json:"reason,omitempty"`
}
TimeBasedRule enables time-specific overrides.