models

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package models provides model metadata, caching, and registry functionality for AI providers, including capability tracking and discovery.

Index

Constants

This section is empty.

Variables

View Source
var AnthropicFallbackModels = []types.Model{

	{ID: "claude-opus-4-5-20251101", Name: "Claude Opus 4.5", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Opus 4.5 - Most powerful model for complex reasoning"},
	{ID: "claude-opus-4-5", Name: "Claude Opus 4.5", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Opus 4.5 - Most powerful model for complex reasoning"},

	{ID: "claude-opus-4-1-20250805", Name: "Claude Opus 4.1", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Opus 4.1 - Advanced reasoning model"},
	{ID: "claude-opus-4-1", Name: "Claude Opus 4.1", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Opus 4.1 - Advanced reasoning model"},

	{ID: "claude-sonnet-4-5-20250929", Name: "Claude Sonnet 4.5", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Sonnet 4.5 - Best balance of intelligence and speed"},
	{ID: "claude-sonnet-4-5", Name: "Claude Sonnet 4.5", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Sonnet 4.5 - Best balance of intelligence and speed"},

	{ID: "claude-sonnet-4-20250514", Name: "Claude Sonnet 4", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Sonnet 4 - Balanced performance model"},
	{ID: "claude-sonnet-4", Name: "Claude Sonnet 4", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Sonnet 4 - Balanced performance model"},

	{ID: "claude-haiku-4-5-20251001", Name: "Claude Haiku 4.5", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Haiku 4.5 - Fastest model for quick tasks"},
	{ID: "claude-haiku-4-5", Name: "Claude Haiku 4.5", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Claude Haiku 4.5 - Fastest model for quick tasks"},

	{ID: "claude-3-5-sonnet-20241022", Name: "Claude 3.5 Sonnet (Oct 2024)", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Anthropic's most capable Sonnet model, updated for October 2024"},
	{ID: "claude-3-5-haiku-20241022", Name: "Claude 3.5 Haiku (Oct 2024)", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Anthropic's fastest Haiku model, updated for October 2024"},
	{ID: "claude-3-opus-20240229", Name: "Claude 3 Opus", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Anthropic's most powerful model for complex tasks"},
	{ID: "claude-3-sonnet-20240229", Name: "Claude 3 Sonnet", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Anthropic's balanced model for workloads"},
	{ID: "claude-3-haiku-20240307", Name: "Claude 3 Haiku", Provider: types.ProviderTypeAnthropic, MaxTokens: 200000, SupportsStreaming: true, SupportsToolCalling: true, Description: "Anthropic's fastest and most compact model"},
}

AnthropicFallbackModels contains static fallback models for Anthropic

View Source
var GeminiFallbackModels = []types.Model{

	{ID: "gemini-3-pro-preview", Name: "Gemini 3 Pro (Preview)", Provider: types.ProviderTypeGemini, MaxTokens: 2097152, SupportsStreaming: true, SupportsToolCalling: true, Description: "Google's latest Gemini 3 Pro model with advanced capabilities"},
	{ID: "gemini-3-pro-image-preview", Name: "Gemini 3 Pro Image (Preview)", Provider: types.ProviderTypeGemini, MaxTokens: 2097152, SupportsStreaming: true, SupportsToolCalling: true, Description: "Gemini 3 Pro with enhanced image understanding"},

	{ID: "gemini-2.5-pro", Name: "Gemini 2.5 Pro", Provider: types.ProviderTypeGemini, MaxTokens: 2097152, SupportsStreaming: true, SupportsToolCalling: true, Description: "Stable Gemini 2.5 Pro model with 2M token context"},
	{ID: "gemini-2.5-flash", Name: "Gemini 2.5 Flash", Provider: types.ProviderTypeGemini, MaxTokens: 1048576, SupportsStreaming: true, SupportsToolCalling: true, Description: "Fast and efficient Gemini 2.5 Flash model"},
	{ID: "gemini-2.5-flash-image", Name: "Gemini 2.5 Flash Image", Provider: types.ProviderTypeGemini, MaxTokens: 1048576, SupportsStreaming: true, SupportsToolCalling: true, Description: "Gemini 2.5 Flash optimized for image tasks"},
	{ID: "gemini-2.5-flash-lite", Name: "Gemini 2.5 Flash Lite", Provider: types.ProviderTypeGemini, MaxTokens: 524288, SupportsStreaming: true, SupportsToolCalling: true, Description: "Lightweight version of Gemini 2.5 Flash"},

	{ID: "gemini-2.0-flash", Name: "Gemini 2.0 Flash", Provider: types.ProviderTypeGemini, MaxTokens: 1048576, SupportsStreaming: true, SupportsToolCalling: true, Description: "Stable Gemini 2.0 Flash model"},
	{ID: "gemini-2.0-flash-001", Name: "Gemini 2.0 Flash 001", Provider: types.ProviderTypeGemini, MaxTokens: 1048576, SupportsStreaming: true, SupportsToolCalling: true, Description: "Gemini 2.0 Flash version 001"},
	{ID: "gemini-2.0-flash-lite", Name: "Gemini 2.0 Flash Lite", Provider: types.ProviderTypeGemini, MaxTokens: 524288, SupportsStreaming: true, SupportsToolCalling: true, Description: "Lightweight Gemini 2.0 Flash model"},
	{ID: "gemini-2.0-flash-lite-001", Name: "Gemini 2.0 Flash Lite 001", Provider: types.ProviderTypeGemini, MaxTokens: 524288, SupportsStreaming: true, SupportsToolCalling: true, Description: "Gemini 2.0 Flash Lite version 001"},
}

GeminiFallbackModels contains static fallback models for Google Gemini

View Source
var OpenAIFallbackModels = []types.Model{
	{
		ID:                  "gpt-4o",
		Name:                "GPT-4o",
		Provider:            types.ProviderTypeOpenAI,
		MaxTokens:           128000,
		SupportsStreaming:   true,
		SupportsToolCalling: true,
		Description:         "OpenAI's latest high-intelligence flagship model",
	},
	{
		ID:                  "gpt-4o-mini",
		Name:                "GPT-4o Mini",
		Provider:            types.ProviderTypeOpenAI,
		MaxTokens:           128000,
		SupportsStreaming:   true,
		SupportsToolCalling: true,
		Description:         "OpenAI's efficient and affordable small model",
	},
	{
		ID:                  "gpt-4-turbo",
		Name:                "GPT-4 Turbo",
		Provider:            types.ProviderTypeOpenAI,
		MaxTokens:           128000,
		SupportsStreaming:   true,
		SupportsToolCalling: true,
		Description:         "OpenAI's balanced GPT-4 model",
	},
	{
		ID:                  "gpt-3.5-turbo",
		Name:                "GPT-3.5 Turbo",
		Provider:            types.ProviderTypeOpenAI,
		MaxTokens:           4096,
		SupportsStreaming:   true,
		SupportsToolCalling: true,
		Description:         "OpenAI's fast and capable model",
	},
}

OpenAIFallbackModels contains static fallback models for OpenAI

Functions

func GetStaticFallback

func GetStaticFallback(providerType types.ProviderType) []types.Model

GetStaticFallback returns fallback models for a provider This is used when the provider's API is unavailable or returns an error

Types

type CacheInfo

type CacheInfo struct {
	ProviderCount  int                  `json:"provider_count"`
	TotalModels    int                  `json:"total_models"`
	ProviderModels map[string]int       `json:"provider_models"`
	CacheTimes     map[string]time.Time `json:"cache_times"`
	OldestCache    time.Time            `json:"oldest_cache"`
	NewestCache    time.Time            `json:"newest_cache"`
}

CacheInfo contains information about the model cache

type CostInfo

type CostInfo struct {
	InputCostPerMToken  float64
	OutputCostPerMToken float64
}

CostInfo contains pricing information per million tokens

type DefaultsRegistry added in v1.0.37

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

DefaultsRegistry manages the models.dev defaults

func GetDefaultsRegistry added in v1.0.37

func GetDefaultsRegistry() *DefaultsRegistry

GetDefaultsRegistry returns the singleton defaults registry

func (*DefaultsRegistry) GetAllProviders added in v1.0.37

func (r *DefaultsRegistry) GetAllProviders() []string

GetAllProviders returns all provider IDs

func (*DefaultsRegistry) GetModelDefaults added in v1.0.37

func (r *DefaultsRegistry) GetModelDefaults(modelID string) *ModelMetadata

GetModelDefaults returns the default capabilities for a model ID It searches across all providers for a matching model

func (*DefaultsRegistry) GetProviderModels added in v1.0.37

func (r *DefaultsRegistry) GetProviderModels(providerID string) map[string]*ModelMetadata

GetProviderModels returns all models for a specific provider ID

type ModelCache

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

ModelCache stores cached model list with timestamp and thread-safe access

func NewModelCache

func NewModelCache(ttl time.Duration) *ModelCache

NewModelCache creates a new model cache with the specified TTL

func (*ModelCache) Clear

func (mc *ModelCache) Clear()

Clear empties the cache and resets the timestamp

func (*ModelCache) Get

func (mc *ModelCache) Get() []types.Model

Get returns cached models (thread-safe)

func (*ModelCache) GetModels

func (mc *ModelCache) GetModels(fetchFunc func() ([]types.Model, error), fallbackFunc func() []types.Model) ([]types.Model, error)

GetModels returns cached models if available and fresh, or calls the fetch function This is a convenience method that implements the common cache-check-fetch-update pattern

func (*ModelCache) GetTTL

func (mc *ModelCache) GetTTL() time.Duration

GetTTL returns the cache's time-to-live duration

func (*ModelCache) GetTimestamp

func (mc *ModelCache) GetTimestamp() time.Time

GetTimestamp returns when the cache was last updated

func (*ModelCache) IsStale

func (mc *ModelCache) IsStale() bool

IsStale checks if the cache is expired

func (*ModelCache) SetTTL

func (mc *ModelCache) SetTTL(ttl time.Duration)

SetTTL updates the cache's time-to-live duration

func (*ModelCache) Update

func (mc *ModelCache) Update(models []types.Model)

Update updates the cache with new models (thread-safe)

type ModelCapabilities

type ModelCapabilities struct {
	SupportsTools     bool
	SupportsStreaming bool
	SupportsVision    bool
}

ModelCapabilities defines what a model can do

type ModelCapability

type ModelCapability struct {
	MaxTokens         int                  `json:"max_tokens"`
	SupportsStreaming bool                 `json:"supports_streaming"`
	SupportsTools     bool                 `json:"supports_tools"`
	SupportsVision    bool                 `json:"supports_vision"`
	Providers         []types.ProviderType `json:"providers"`
	InputPrice        float64              `json:"input_price_per_1k"`  // Price per 1K input tokens
	OutputPrice       float64              `json:"output_price_per_1k"` // Price per 1K output tokens
	Categories        []string             `json:"categories"`          // e.g., "text", "code", "multimodal"
}

ModelCapability represents provider model capabilities

type ModelMetadata

type ModelMetadata struct {
	DisplayName   string
	MaxTokens     int
	Description   string
	Capabilities  ModelCapabilities
	CostPerMToken CostInfo
}

ModelMetadata contains comprehensive metadata for a model

func ApplyUserOverride added in v1.0.37

func ApplyUserOverride(metadata *ModelMetadata, override types.ModelCapabilityOverride) *ModelMetadata

ApplyUserOverride applies user-defined capability overrides to metadata

type ModelMetadataRegistry

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

ModelMetadataRegistry provides centralized model metadata management It stores and enriches model information with display names, descriptions, token limits, and capabilities for all providers.

func GetAnthropicMetadataRegistry

func GetAnthropicMetadataRegistry() *ModelMetadataRegistry

GetAnthropicMetadataRegistry returns a pre-populated registry for Anthropic models

func GetGeminiMetadataRegistry

func GetGeminiMetadataRegistry() *ModelMetadataRegistry

GetGeminiMetadataRegistry returns a pre-populated registry for Gemini models

func GetOpenAIMetadataRegistry

func GetOpenAIMetadataRegistry() *ModelMetadataRegistry

GetOpenAIMetadataRegistry returns a pre-populated registry for OpenAI models

func NewModelMetadataRegistry

func NewModelMetadataRegistry() *ModelMetadataRegistry

NewModelMetadataRegistry creates a new model metadata registry

func (*ModelMetadataRegistry) Clear

func (r *ModelMetadataRegistry) Clear()

Clear removes all registered metadata

func (*ModelMetadataRegistry) EnrichModel

func (r *ModelMetadataRegistry) EnrichModel(model *types.Model) *types.Model

EnrichModel enriches a model with metadata from the registry If metadata is not found, returns the model unchanged

func (*ModelMetadataRegistry) EnrichModelWithOverrides added in v1.0.37

func (r *ModelMetadataRegistry) EnrichModelWithOverrides(model *types.Model, overrides map[string]types.ModelCapabilityOverride) *types.Model

EnrichModelWithOverrides enriches a model with metadata and user overrides This method implements the full precedence hierarchy: 1. User overrides (highest priority) 2. Provider API response (if available in the model) 3. Embedded defaults (from models.dev) 4. Name inference (lowest priority)

func (*ModelMetadataRegistry) EnrichModels

func (r *ModelMetadataRegistry) EnrichModels(models []types.Model) []types.Model

EnrichModels enriches multiple models with metadata

func (*ModelMetadataRegistry) EnrichModelsWithOverrides added in v1.0.37

func (r *ModelMetadataRegistry) EnrichModelsWithOverrides(models []types.Model, overrides map[string]types.ModelCapabilityOverride) []types.Model

EnrichModelsWithOverrides enriches multiple models with metadata and user overrides

func (*ModelMetadataRegistry) GetAllModelIDs

func (r *ModelMetadataRegistry) GetAllModelIDs() []string

GetAllModelIDs returns all registered model IDs

func (*ModelMetadataRegistry) GetMetadata

func (r *ModelMetadataRegistry) GetMetadata(modelID string) *ModelMetadata

GetMetadata retrieves metadata for a model ID Returns nil if no metadata is registered for the model

func (*ModelMetadataRegistry) GetMetadataWithFallback added in v1.0.37

func (r *ModelMetadataRegistry) GetMetadataWithFallback(modelID string) *ModelMetadata

GetMetadataWithFallback retrieves metadata for a model ID with fallback to defaults Precedence order: 1. Provider-specific metadata (from registry) 2. Embedded defaults (from models.dev snapshot) 3. nil (no metadata available)

func (*ModelMetadataRegistry) GetMetadataWithOverrides added in v1.0.37

func (r *ModelMetadataRegistry) GetMetadataWithOverrides(modelID string, override *types.ModelCapabilityOverride) *ModelMetadata

GetMetadataWithOverrides retrieves metadata with user overrides applied Precedence order (highest to lowest): 1. User overrides (from ProviderConfig.ModelCapabilities) 2. Provider API response metadata (from registry) 3. Embedded defaults (from models.dev snapshot) 4. nil (no metadata available)

func (*ModelMetadataRegistry) RegisterBulkMetadata

func (r *ModelMetadataRegistry) RegisterBulkMetadata(entries map[string]*ModelMetadata)

RegisterBulkMetadata registers multiple model metadata entries at once

func (*ModelMetadataRegistry) RegisterMetadata

func (r *ModelMetadataRegistry) RegisterMetadata(modelID string, metadata *ModelMetadata)

RegisterMetadata registers metadata for a specific model ID

type ModelRegistry

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

ModelRegistry manages model information and caching

func NewModelRegistry

func NewModelRegistry(ttl time.Duration) *ModelRegistry

NewModelRegistry creates a new model registry

func (*ModelRegistry) CacheModels

func (mr *ModelRegistry) CacheModels(providerType types.ProviderType, models []types.Model)

CacheModels caches models for a provider

func (*ModelRegistry) ClearCache

func (mr *ModelRegistry) ClearCache(providerType *types.ProviderType)

ClearCache clears the cache for a specific provider or all providers

func (*ModelRegistry) GetCacheInfo

func (mr *ModelRegistry) GetCacheInfo() CacheInfo

GetCacheInfo returns information about the cache

func (*ModelRegistry) GetCachedModels

func (mr *ModelRegistry) GetCachedModels(providerType types.ProviderType) []types.Model

GetCachedModels returns cached models for a provider if not expired

func (*ModelRegistry) GetModelCapability

func (mr *ModelRegistry) GetModelCapability(modelID string) *ModelCapability

GetModelCapability returns the capabilities for a model

func (*ModelRegistry) GetModelsByProvider

func (mr *ModelRegistry) GetModelsByProvider(providerType types.ProviderType) []types.Model

GetModelsByProvider returns all models for a specific provider

func (*ModelRegistry) GetProviderCount

func (mr *ModelRegistry) GetProviderCount() int

GetProviderCount returns the number of providers with cached models

func (*ModelRegistry) GetTotalModelCount

func (mr *ModelRegistry) GetTotalModelCount() int

GetTotalModelCount returns the total number of cached models

func (*ModelRegistry) RegisterModel

func (mr *ModelRegistry) RegisterModel(modelID string, capability *ModelCapability)

RegisterModel registers a model with its capabilities

func (*ModelRegistry) SearchModels

func (mr *ModelRegistry) SearchModels(criteria SearchCriteria) []types.Model

SearchModels searches for models matching criteria

type ModelsDevCost added in v1.0.37

type ModelsDevCost struct {
	Input     float64 `json:"input"`
	Output    float64 `json:"output"`
	CacheRead float64 `json:"cache_read,omitempty"`
}

ModelsDevCost represents pricing information

type ModelsDevLimit added in v1.0.37

type ModelsDevLimit struct {
	Context int `json:"context"`
	Output  int `json:"output"`
}

ModelsDevLimit represents context and output limits

type ModelsDevModalities added in v1.0.37

type ModelsDevModalities struct {
	Input  []string `json:"input"`
	Output []string `json:"output"`
}

ModelsDevModalities represents input/output modalities

type ModelsDevModel added in v1.0.37

type ModelsDevModel struct {
	ID          string              `json:"id"`
	Name        string              `json:"name"`
	Attachment  bool                `json:"attachment"`
	Reasoning   bool                `json:"reasoning"`
	ToolCall    bool                `json:"tool_call"`
	Temperature bool                `json:"temperature"`
	Knowledge   string              `json:"knowledge"`
	ReleaseDate string              `json:"release_date"`
	LastUpdated string              `json:"last_updated"`
	Modalities  ModelsDevModalities `json:"modalities"`
	OpenWeights bool                `json:"open_weights"`
	Cost        *ModelsDevCost      `json:"cost,omitempty"`
	Limit       ModelsDevLimit      `json:"limit"`
}

ModelsDevModel represents a model in the models.dev dataset

type ModelsDevProvider added in v1.0.37

type ModelsDevProvider struct {
	ID     string                    `json:"id"`
	Name   string                    `json:"name"`
	API    string                    `json:"api"`
	Models map[string]ModelsDevModel `json:"models"`
}

ModelsDevProvider represents a provider in the models.dev dataset

type SearchCriteria

type SearchCriteria struct {
	Provider          *types.ProviderType `json:"provider,omitempty"`
	MinTokens         *int                `json:"min_tokens,omitempty"`
	MaxTokens         *int                `json:"max_tokens,omitempty"`
	SupportsStreaming *bool               `json:"supports_streaming,omitempty"`
	SupportsTools     *bool               `json:"supports_tools,omitempty"`
	Categories        []string            `json:"categories,omitempty"`
	NameContains      string              `json:"name_contains,omitempty"`
}

SearchCriteria defines search criteria for models

Jump to

Keyboard shortcuts

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