Documentation
¶
Overview ¶
Package arbitrage provides cost optimization for model selection. It scores task complexity and compares pricing across providers to suggest the most cost-effective model that meets the task's capability requirements.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShouldArbitrage ¶
ShouldArbitrage returns true when switching from the current model to the alternative would save more than the threshold proportion of the current cost.
Types ¶
type ArbitrageRecommendation ¶
type ArbitrageRecommendation struct {
RecommendedModel CostEstimate `json:"recommended_model"`
Alternatives []CostEstimate `json:"alternatives"`
Complexity ComplexityLevel `json:"complexity"`
Savings float64 `json:"savings"`
Reason string `json:"reason"`
}
ArbitrageRecommendation holds the recommended model and alternatives.
func Recommend ¶
func Recommend(models []types.ModelInfo, task types.Task, threshold float64) (*ArbitrageRecommendation, error)
Recommend scores a task, estimates tokens, compares models, and returns the best model recommendation. For complex tasks the cheapest model may be rejected if its context window is insufficient (<=64K). When the cheapest is rejected, the next model whose cost is within the threshold factor is selected.
type ComplexityLevel ¶
type ComplexityLevel string
ComplexityLevel represents the complexity classification of a task.
const ( ComplexitySimple ComplexityLevel = "simple" ComplexityModerate ComplexityLevel = "moderate" ComplexityComplex ComplexityLevel = "complex" )
type CostEstimate ¶
type CostEstimate struct {
ModelID string `json:"model_id"`
Provider string `json:"provider"`
InputCost float64 `json:"input_cost"`
OutputCost float64 `json:"output_cost"`
TotalCost float64 `json:"total_cost"`
Currency string `json:"currency"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
}
CostEstimate holds the cost estimate for a model given estimated token counts.
func CompareModels ¶
func CompareModels(models []types.ModelInfo, inputTokens, outputTokens int) []CostEstimate
CompareModels computes cost estimates for each model and returns them sorted ascending by TotalCost. Models where both Pricing fields are zero are skipped.
type Scorer ¶
Scorer evaluates task complexity and estimates token usage.
func NewScorer ¶
NewScorer creates a Scorer with the given thresholds. Values <= 0 are replaced with defaults (SimpleThreshold=2000, ComplexThreshold=8000).
func (*Scorer) EstimateTokens ¶
EstimateTokens returns estimated input and output tokens for a given complexity level and task. Per-file adjustments add 500 tokens each.