provider

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ThinkingLevelOrder = []string{"off", "minimal", "low", "medium", "high", "xhigh"}

ThinkingLevelOrder defines the ordered progression of thinking levels.

Functions

func ClampThinkingLevel

func ClampThinkingLevel(level string, available []string) string

ClampThinkingLevel adjusts level to the nearest valid level from available. It searches backward then forward in ThinkingLevelOrder for the closest match.

func CreateModel

func CreateModel(prov, name, apiKey, baseURL string) (agentcore.ChatModel, error)

CreateModel creates a ChatModel for the given provider, model name, API key, and optional base URL.

func IsValidThinkingLevel added in v0.0.2

func IsValidThinkingLevel(s string) bool

IsValidThinkingLevel reports whether s is a recognized thinking level.

func StartPricingRefresh

func StartPricingRefresh(registry *ModelRegistry, cacheDir string)

StartPricingRefresh launches a background goroutine that refreshes model data from the OpenRouter API. Disk cache (cacheDir/models-cache.json) is checked first with a 24h TTL. Fresh data is merged into the registry, overlaying the compiled-in baseline from models_generated.go.

func WrapStreamSafe

func WrapStreamSafe(m agentcore.ChatModel) agentcore.ChatModel

WrapStreamSafe normalizes streaming behavior: when GenerateStream fails, it falls back to Generate and emits a synthetic done event.

Types

type ModelEntry

type ModelEntry struct {
	Provider            string  `json:"provider"`
	ID                  string  `json:"id"`
	Name                string  `json:"name"`
	ContextWindow       int     `json:"context_window"`
	MaxTokens           int     `json:"max_tokens"`
	Reasoning           bool    `json:"reasoning"`
	InputCostPer1M      float64 `json:"input_cost_per_1m"`
	OutputCostPer1M     float64 `json:"output_cost_per_1m"`
	CacheReadCostPer1M  float64 `json:"cache_read_cost_per_1m"`
	CacheWriteCostPer1M float64 `json:"cache_write_cost_per_1m"`
}

ModelEntry describes a known LLM model.

type ModelRegistry

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

ModelRegistry holds known models and provides resolution/cycling.

func NewModelRegistry

func NewModelRegistry() *ModelRegistry

NewModelRegistry creates a registry loaded from generated model data.

func (*ModelRegistry) AvailableThinkingLevels

func (r *ModelRegistry) AvailableThinkingLevels(modelID string) []string

AvailableThinkingLevels returns valid thinking levels for a model. Non-reasoning models only support "off"; reasoning models support all levels.

func (*ModelRegistry) CostRates

func (r *ModelRegistry) CostRates(modelID string) (inputPer1M, outputPer1M, cacheReadPer1M, cacheWritePer1M float64)

CostRates returns the per-1M-token cost rates for a model. Uses Resolve for matching, so partial names like "sonnet" work.

func (*ModelRegistry) FindByProvider

func (r *ModelRegistry) FindByProvider(prov string) []ModelEntry

FindByProvider returns all models for a given provider.

func (*ModelRegistry) List

func (r *ModelRegistry) List(filter string) []ModelEntry

List returns models matching the filter (empty filter = all).

func (*ModelRegistry) MergeModels

func (r *ModelRegistry) MergeModels(fetched []ModelEntry)

MergeModels updates existing models and adds new ones from fetched data. Matching by Provider+ID (case-insensitive). Updates cost/context/name fields.

func (*ModelRegistry) Resolve

func (r *ModelRegistry) Resolve(pattern string) (*ModelEntry, agentcore.ThinkingLevel, error)

Resolve parses a model pattern and returns the matched entry and optional thinking level. Pattern formats:

  • "claude-sonnet-4-5" → exact/partial match
  • "anthropic/claude-sonnet-4-5" → provider/model
  • "claude-sonnet-4-5:high" → model + thinking level
  • "sonnet" → partial match

Jump to

Keyboard shortcuts

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