Documentation
¶
Overview ¶
Package models provides model metadata, caching, and registry functionality for AI providers, including capability tracking and discovery.
Index ¶
- Variables
- func GetStaticFallback(providerType types.ProviderType) []types.Model
- type CacheInfo
- type CostInfo
- type ModelCache
- func (mc *ModelCache) Clear()
- func (mc *ModelCache) Get() []types.Model
- func (mc *ModelCache) GetModels(fetchFunc func() ([]types.Model, error), fallbackFunc func() []types.Model) ([]types.Model, error)
- func (mc *ModelCache) GetTTL() time.Duration
- func (mc *ModelCache) GetTimestamp() time.Time
- func (mc *ModelCache) IsStale() bool
- func (mc *ModelCache) SetTTL(ttl time.Duration)
- func (mc *ModelCache) Update(models []types.Model)
- type ModelCapabilities
- type ModelCapability
- type ModelMetadata
- type ModelMetadataRegistry
- func (r *ModelMetadataRegistry) Clear()
- func (r *ModelMetadataRegistry) EnrichModel(model *types.Model) *types.Model
- func (r *ModelMetadataRegistry) EnrichModels(models []types.Model) []types.Model
- func (r *ModelMetadataRegistry) GetAllModelIDs() []string
- func (r *ModelMetadataRegistry) GetMetadata(modelID string) *ModelMetadata
- func (r *ModelMetadataRegistry) RegisterBulkMetadata(entries map[string]*ModelMetadata)
- func (r *ModelMetadataRegistry) RegisterMetadata(modelID string, metadata *ModelMetadata)
- type ModelRegistry
- func (mr *ModelRegistry) CacheModels(providerType types.ProviderType, models []types.Model)
- func (mr *ModelRegistry) ClearCache(providerType *types.ProviderType)
- func (mr *ModelRegistry) GetCacheInfo() CacheInfo
- func (mr *ModelRegistry) GetCachedModels(providerType types.ProviderType) []types.Model
- func (mr *ModelRegistry) GetModelCapability(modelID string) *ModelCapability
- func (mr *ModelRegistry) GetModelsByProvider(providerType types.ProviderType) []types.Model
- func (mr *ModelRegistry) GetProviderCount() int
- func (mr *ModelRegistry) GetTotalModelCount() int
- func (mr *ModelRegistry) RegisterModel(modelID string, capability *ModelCapability)
- func (mr *ModelRegistry) SearchModels(criteria SearchCriteria) []types.Model
- type SearchCriteria
Constants ¶
This section is empty.
Variables ¶
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
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
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 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 ¶
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
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) EnrichModels ¶
func (r *ModelMetadataRegistry) EnrichModels(models []types.Model) []types.Model
EnrichModels enriches multiple models with metadata
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) 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 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