Documentation
¶
Index ¶
- Variables
- func ClampThinkingLevel(level string, available []string) string
- func CreateModel(prov, name, apiKey, baseURL string) (agentcore.ChatModel, error)
- func IsSupportedType(name string) bool
- func IsValidThinkingLevel(s string) bool
- func NewModelFactory(clientOpts ...litellm.ClientOption) func(prov, name, apiKey, baseURL string) (agentcore.ChatModel, error)
- func StartPricingRefresh(registry *ModelRegistry, cacheDir string)
- func SupportedTypeNames() []string
- func WrapStreamSafe(m agentcore.ChatModel) agentcore.ChatModel
- type ModelEntry
- type ModelRegistry
- func (r *ModelRegistry) AvailableThinkingLevels(modelID string) []string
- func (r *ModelRegistry) CostRates(modelID string) (inputPer1M, outputPer1M, cacheReadPer1M, cacheWritePer1M float64)
- func (r *ModelRegistry) FindByProvider(prov string) []ModelEntry
- func (r *ModelRegistry) List(filter string) []ModelEntry
- func (r *ModelRegistry) MergeModels(fetched []ModelEntry)
- func (r *ModelRegistry) Resolve(pattern string) (*ModelEntry, agentcore.ThinkingLevel, error)
Constants ¶
This section is empty.
Variables ¶
var ThinkingLevelOrder = []string{"off", "minimal", "low", "medium", "high", "xhigh"}
ThinkingLevelOrder defines the ordered progression of thinking levels.
Functions ¶
func ClampThinkingLevel ¶
ClampThinkingLevel adjusts level to the nearest valid level from available. It searches backward then forward in ThinkingLevelOrder for the closest match.
func CreateModel ¶
CreateModel creates a ChatModel for the given provider, model name, API key, and optional base URL.
func IsSupportedType ¶ added in v0.1.0
IsSupportedType reports whether the given provider type is registered in litellm (built-in or custom). The check is delegated to agentcore/litellm so codebot does not maintain a duplicate whitelist.
func IsValidThinkingLevel ¶ added in v0.0.2
IsValidThinkingLevel reports whether s is a recognized thinking level.
func NewModelFactory ¶ added in v0.2.0
func NewModelFactory(clientOpts ...litellm.ClientOption) func(prov, name, apiKey, baseURL string) (agentcore.ChatModel, error)
NewModelFactory returns a model factory that forwards the given litellm ClientOptions (e.g. litellm.WithHook for telemetry) into every model it builds. The return type structurally matches agent.ModelFactory without importing that package, avoiding an import cycle.
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 SupportedTypeNames ¶ added in v0.1.0
func SupportedTypeNames() []string
SupportedTypeNames returns all provider names known to litellm, sorted.
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