models

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClaudeCodePrompt is the required system prompt for OAuth authentication.
	ClaudeCodePrompt = "You are Claude Code, Anthropic's official CLI for Claude."
)

Variables

This section is empty.

Functions

func LoadCachedProviders

func LoadCachedProviders() (map[string]modelsDBProvider, string)

LoadCachedProviders reads the cached provider data from disk. Returns nil, "" if no cache exists or the cache is unreadable.

func ParseModelString

func ParseModelString(modelString string) (provider, model string, err error)

ParseModelString parses a model string in "provider/model" format (e.g. "anthropic/claude-sonnet-4-5"). It splits on the first "/" to extract the provider and model name. For backward compatibility, the legacy "provider:model" format is also accepted with a deprecation warning printed to stderr. Returns the provider name, model name, and any error.

func ReloadGlobalRegistry

func ReloadGlobalRegistry()

ReloadGlobalRegistry rebuilds the global registry from the current data sources (cache → embedded). Call after updating the cache.

func RemoveCachedProviders

func RemoveCachedProviders() error

RemoveCachedProviders deletes the cache file, causing the registry to fall back to the embedded model database on next load.

func StoreCachedProviders

func StoreCachedProviders(providers map[string]modelsDBProvider, etag string) error

StoreCachedProviders writes provider data to the cache file on disk.

Types

type Cost

type Cost struct {
	Input      float64
	Output     float64
	CacheRead  *float64
	CacheWrite *float64
}

Cost represents the pricing information for a model.

type Limit

type Limit struct {
	Context int
	Output  int
}

Limit represents the context and output limits for a model.

type ModelInfo

type ModelInfo struct {
	ID          string
	Name        string
	Attachment  bool
	Reasoning   bool
	Temperature bool
	Cost        Cost
	Limit       Limit
}

ModelInfo represents information about a specific model.

type ModelsDBProviders

type ModelsDBProviders = map[string]modelsDBProvider

ModelsDBProviders is the top-level type for models.dev/api.json data: a map of provider ID → provider object.

type ModelsRegistry

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

ModelsRegistry provides validation and information about models. It maintains a registry of all supported LLM providers and their models, including capabilities, pricing, and configuration requirements. The registry data comes from models.dev.

func GetGlobalRegistry

func GetGlobalRegistry() *ModelsRegistry

GetGlobalRegistry returns the global models registry instance.

func NewModelsRegistry

func NewModelsRegistry() *ModelsRegistry

NewModelsRegistry creates a new models registry populated from models.dev data.

func (*ModelsRegistry) GetFantasyProviders

func (r *ModelsRegistry) GetFantasyProviders() []string

GetFantasyProviders returns provider IDs that can be used with fantasy, either through a native provider or via openaicompat auto-routing.

func (*ModelsRegistry) GetModelsForProvider

func (r *ModelsRegistry) GetModelsForProvider(provider string) (map[string]ModelInfo, error)

GetModelsForProvider returns all models for a specific provider.

func (*ModelsRegistry) GetProviderInfo

func (r *ModelsRegistry) GetProviderInfo(provider string) *ProviderInfo

GetProviderInfo returns the full provider info, or nil if not found.

func (*ModelsRegistry) GetRequiredEnvVars

func (r *ModelsRegistry) GetRequiredEnvVars(provider string) ([]string, error)

GetRequiredEnvVars returns the required environment variables for a provider.

func (*ModelsRegistry) GetSupportedProviders

func (r *ModelsRegistry) GetSupportedProviders() []string

GetSupportedProviders returns a list of all provider IDs in the registry.

func (*ModelsRegistry) LookupModel

func (r *ModelsRegistry) LookupModel(provider, modelID string) *ModelInfo

LookupModel returns model metadata from the database if available. Returns nil when the model or provider is not in the database — this is expected for new models, custom fine-tunes, or providers the database doesn't track yet. Callers should treat a nil return as "unknown model" and continue with sensible defaults.

func (*ModelsRegistry) SuggestModels

func (r *ModelsRegistry) SuggestModels(provider, invalidModel string) []string

SuggestModels returns similar model names when an invalid model is provided.

func (*ModelsRegistry) ValidateEnvironment

func (r *ModelsRegistry) ValidateEnvironment(provider string, apiKey string) error

ValidateEnvironment checks if required environment variables are set. Returns nil for providers not in the registry (unknown providers are assumed to handle auth themselves or via --provider-api-key).

func (*ModelsRegistry) ValidateModel

func (r *ModelsRegistry) ValidateModel(provider, modelID string) (*ModelInfo, error)

ValidateModel validates if a model exists and returns detailed information. Deprecated: Use LookupModel instead — it returns nil for unknown models rather than an error, letting the provider API be the authority.

type OllamaLoadingResult

type OllamaLoadingResult struct {
	Message string
}

OllamaLoadingResult contains the result of model loading with actual settings used.

type ProviderConfig

type ProviderConfig struct {
	ModelString    string
	SystemPrompt   string
	ProviderAPIKey string
	ProviderURL    string
	MaxTokens      int
	Temperature    *float32
	TopP           *float32
	TopK           *int32
	StopSequences  []string
	NumGPU         *int32
	MainGPU        *int32
	TLSSkipVerify  bool
}

ProviderConfig holds configuration for creating LLM providers.

type ProviderInfo

type ProviderInfo struct {
	ID     string
	Env    []string
	NPM    string // npm package identifier from models.dev (e.g. "@ai-sdk/openai-compatible")
	API    string // base API URL for openai-compatible providers
	Name   string
	Models map[string]ModelInfo
}

ProviderInfo represents information about a model provider.

type ProviderResult

type ProviderResult struct {
	// Model is the created fantasy LanguageModel
	Model fantasy.LanguageModel
	// Message contains optional feedback for the user
	Message string
	// Closer is an optional cleanup function for providers that hold
	// resources (e.g. kronk's loaded models). May be nil.
	Closer io.Closer
}

ProviderResult contains the result of provider creation.

func CreateProvider

func CreateProvider(ctx context.Context, config *ProviderConfig) (*ProviderResult, error)

CreateProvider creates a fantasy LanguageModel based on the provider configuration. Model metadata is looked up from the models.dev database for cost tracking and capability detection, but unknown models are passed through to the provider API — the database is advisory, not a gatekeeper.

Native providers: anthropic, openai, google, ollama, azure, google-vertex-anthropic, openrouter, bedrock, vercel. Any provider in models.dev with an api URL or openai-compatible npm package is auto-routed through fantasy's openaicompat provider.

Jump to

Keyboard shortcuts

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