models

package
v0.31.4 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClaudeCodePrompt is the required system prompt for OAuth authentication.
	// This prompt must be included as the first system message when using OAuth-based
	// authentication with Anthropic's API to properly identify the application.
	ClaudeCodePrompt = "You are Claude Code, Anthropic's official CLI for Claude."
)

Variables

This section is empty.

Functions

func GetModelsData added in v0.14.0

func GetModelsData() map[string]ProviderInfo

GetModelsData returns the static models data from models.dev. This data is automatically generated from the models.dev API and provides comprehensive information about all supported LLM providers and their models.

The data includes:

  • Provider information (ID, name, environment variables)
  • Model capabilities (reasoning, attachments, temperature support)
  • Pricing information (input/output costs, cache costs)
  • Token limits (context window, max output tokens)

Returns:

  • map[string]ProviderInfo: A map of provider IDs to their information

Types

type Cost added in v0.14.0

type Cost struct {
	// Input is the cost per million input tokens
	Input float64

	// Output is the cost per million output tokens
	Output float64

	// CacheRead is the cost per million cached read tokens (optional)
	// Only applicable for models that support prompt caching
	CacheRead *float64

	// CacheWrite is the cost per million cached write tokens (optional)
	// Only applicable for models that support prompt caching
	CacheWrite *float64
}

Cost represents the pricing information for a model. Prices are typically in USD per million tokens.

type Limit added in v0.14.0

type Limit struct {
	// Context is the maximum number of input tokens (context window size)
	Context int

	// Output is the maximum number of output tokens that can be generated
	Output int
}

Limit represents the context and output limits for a model. These define the maximum number of tokens the model can process and generate in a single interaction.

type ModelInfo added in v0.14.0

type ModelInfo struct {
	// ID is the unique identifier for the model
	// Example: "claude-3-sonnet-20240620" or "gpt-4"
	ID string

	// Name is the human-readable name of the model
	// Example: "Claude 3 Sonnet" or "GPT-4"
	Name string

	// Attachment indicates whether the model supports file attachments
	Attachment bool

	// Reasoning indicates whether this is a reasoning/chain-of-thought model
	// Example: OpenAI's o1 models have this set to true
	Reasoning bool

	// Temperature indicates whether the model supports temperature parameter
	Temperature bool

	// Cost contains the pricing information for input/output tokens
	Cost Cost

	// Limit contains the context window and output token limits
	Limit Limit
}

ModelInfo represents information about a specific model. It contains comprehensive metadata about a model's capabilities, pricing, and limitations sourced from models.dev.

type ModelsRegistry added in v0.14.0

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 is generated from models.dev and provides a single source of truth for model validation and discovery.

func GetGlobalRegistry added in v0.14.0

func GetGlobalRegistry() *ModelsRegistry

GetGlobalRegistry returns the global models registry instance. This provides a singleton registry that can be accessed throughout the application for model validation and information retrieval. The registry is initialized once with data from models.dev.

Returns:

  • *ModelsRegistry: The global registry instance

func NewModelsRegistry added in v0.14.0

func NewModelsRegistry() *ModelsRegistry

NewModelsRegistry creates a new models registry with static data. The registry is populated with model information generated from models.dev, providing comprehensive metadata about available models across all supported providers.

Returns:

  • *ModelsRegistry: A new registry instance populated with current model data

func (*ModelsRegistry) GetModelsForProvider added in v0.14.0

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

GetModelsForProvider returns all models for a specific provider. This is useful for listing available models when a user wants to see all options for a particular provider.

Parameters:

  • provider: The provider ID to get models for

Returns:

  • map[string]ModelInfo: A map of model IDs to their detailed information
  • error: Returns an error if the provider is unsupported

func (*ModelsRegistry) GetRequiredEnvVars added in v0.14.0

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

GetRequiredEnvVars returns the required environment variables for a provider. These are the environment variable names that should contain API keys or other authentication credentials for the specified provider.

Parameters:

  • provider: The provider ID (e.g., "anthropic", "openai", "google")

Returns:

  • []string: List of environment variable names the provider checks for credentials
  • error: Returns an error if the provider is unsupported

Example:

For "anthropic", returns ["ANTHROPIC_API_KEY"]
For "google", returns ["GOOGLE_API_KEY", "GEMINI_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"]

func (*ModelsRegistry) GetSupportedProviders added in v0.14.0

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

GetSupportedProviders returns a list of all supported providers. This includes all providers that have models registered in the system, such as "anthropic", "openai", "google", "alibaba", etc.

Returns:

  • []string: A list of all provider IDs available in the registry

func (*ModelsRegistry) SuggestModels added in v0.14.0

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

SuggestModels returns similar model names when an invalid model is provided. It helps users discover the correct model ID by finding models that partially match the provided input, useful for correcting typos or finding alternatives.

Parameters:

  • provider: The provider ID to search within
  • invalidModel: The invalid or misspelled model name to find suggestions for

Returns:

  • []string: A list of up to 5 suggested model IDs that partially match the input

func (*ModelsRegistry) ValidateEnvironment added in v0.14.0

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

ValidateEnvironment checks if required environment variables are set. It verifies that at least one of the provider's required environment variables contains an API key, unless an API key is explicitly provided via configuration.

Parameters:

  • provider: The provider ID to validate environment for
  • apiKey: An API key provided via configuration (if empty, checks environment variables)

Returns:

  • error: Returns nil if validation passes, or an error describing missing credentials

func (*ModelsRegistry) ValidateModel added in v0.14.0

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

ValidateModel validates if a model exists and returns detailed information. It checks whether a specific model is available for a given provider and returns comprehensive information about the model's capabilities and limits.

Parameters:

  • provider: The provider ID (e.g., "anthropic", "openai", "google")
  • modelID: The specific model ID (e.g., "claude-3-sonnet-20240620", "gpt-4")

Returns:

  • *ModelInfo: Detailed information about the model including pricing, limits, and capabilities
  • error: Returns an error if the provider is unsupported or model is not found

type OllamaLoadingResult added in v0.18.0

type OllamaLoadingResult struct {
	// Options contains the actual Ollama options used for loading
	// May differ from requested options if fallback occurred (e.g., CPU instead of GPU)
	Options *api.Options

	// Message describes the loading result
	// Example: "Model loaded successfully on GPU" or
	// "Insufficient GPU memory, falling back to CPU inference"
	Message string
}

OllamaLoadingResult contains the result of model loading with actual settings used. It provides information about how the model was loaded, including any fallback behavior that occurred during initialization.

type ProviderConfig

type ProviderConfig struct {
	// ModelString specifies the model in the format "provider:model"
	// Example: "anthropic:claude-3-sonnet-20240620" or "openai:gpt-4"
	ModelString string

	// SystemPrompt sets the system message/instructions for the model
	SystemPrompt string

	// ProviderAPIKey is the API key for authentication with the provider
	// Used for OpenAI, Anthropic, Google, and Azure providers
	ProviderAPIKey string

	// ProviderURL is the base URL for the provider's API endpoint
	// Can be used to specify custom endpoints for OpenAI, Anthropic, Ollama, or Azure
	ProviderURL string

	// MaxTokens limits the maximum number of tokens in the response
	MaxTokens int

	// Temperature controls randomness in generation (0.0 to 1.0)
	// Lower values make output more focused and deterministic
	Temperature *float32

	// TopP implements nucleus sampling, controlling diversity
	// Value between 0.0 and 1.0, where 1.0 considers all tokens
	TopP *float32

	// TopK limits the number of tokens to sample from
	// Used by Anthropic and Google providers
	TopK *int32

	// StopSequences is a list of sequences that will stop generation
	StopSequences []string

	// NumGPU specifies the number of GPUs to use for inference
	NumGPU *int32

	// MainGPU specifies which GPU to use as the primary device
	MainGPU *int32

	// TLSSkipVerify skips TLS certificate verification (insecure)
	// Should only be used for development or with self-signed certificates
	TLSSkipVerify bool
}

ProviderConfig holds configuration for creating LLM providers. It contains all necessary settings to initialize and configure various LLM providers including API keys, model parameters, and provider-specific settings.

type ProviderInfo added in v0.14.0

type ProviderInfo struct {
	// ID is the unique identifier for the provider
	// Example: "anthropic", "openai", "google"
	ID string

	// Env lists the environment variables checked for API credentials
	// Example: ["ANTHROPIC_API_KEY"] or ["OPENAI_API_KEY"]
	Env []string

	// NPM is the NPM package name used by the provider (for reference)
	NPM string

	// Name is the human-readable name of the provider
	// Example: "Anthropic", "OpenAI", "Google"
	Name string

	// Models maps model IDs to their detailed information
	Models map[string]ModelInfo
}

ProviderInfo represents information about a model provider. It contains metadata about the provider and all models it offers.

type ProviderResult added in v0.18.0

type ProviderResult struct {
	// Model is the created LLM provider instance that implements
	// the ToolCallingChatModel interface for tool-enabled conversations
	Model model.ToolCallingChatModel

	// Message contains optional feedback for the user
	// Example: "Insufficient GPU memory, falling back to CPU inference"
	Message string
}

ProviderResult contains the result of provider creation. It includes both the created model instance and any informational messages that should be displayed to the user.

func CreateProvider

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

CreateProvider creates an eino ToolCallingChatModel based on the provider configuration. It validates the model, checks required environment variables, and initializes the appropriate provider (Anthropic, OpenAI, Google, Ollama, or Azure).

Parameters:

  • ctx: Context for the operation, used for cancellation and deadlines
  • config: Provider configuration containing model details and parameters

Returns:

  • *ProviderResult: Contains the created model and any informational messages
  • error: Returns an error if provider creation fails, model validation fails, or required credentials are missing

Supported providers:

  • anthropic: Claude models with API key or OAuth authentication
  • openai: GPT models including reasoning models like o1
  • google: Gemini models
  • ollama: Local models with automatic GPU/CPU fallback
  • azure: Azure OpenAI Service deployments

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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