model

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WellKnownModels = map[string][]string{
	"anthropic": {
		"claude-sonnet-4-6",
		"claude-opus-4",
		"claude-sonnet-4-5-20250929",
		"claude-haiku-3-5-20241022",
	},
	"openai": {
		"gpt-4o",
		"gpt-4o-mini",
		"o3",
		"o3-mini",
	},
}

WellKnownModels maps provider names to their commonly-used model IDs. Used to populate OpenClaw's model allowlist when a wildcard is configured and the LiteLLM pod is not reachable for a live /v1/models query.

Functions

func AddCustomEndpoint added in v0.6.0

func AddCustomEndpoint(cfg *config.Config, u *ui.UI, name, endpoint, modelName, apiKey string) error

AddCustomEndpoint adds a custom OpenAI-compatible endpoint to LiteLLM after validating it works.

func ConfigureLiteLLM added in v0.6.0

func ConfigureLiteLLM(cfg *config.Config, u *ui.UI, provider, apiKey string, models []string) error

ConfigureLiteLLM adds a provider to the LiteLLM gateway. For cloud providers, it patches the Secret with the API key and adds the model to config.yaml. For Ollama, it discovers local models and adds them.

func FormatBytes added in v0.5.0

func FormatBytes(b int64) string

FormatBytes formats a byte count as a human-readable string.

func GetConfiguredModels added in v0.6.0

func GetConfiguredModels(cfg *config.Config) ([]string, error)

GetConfiguredModels returns the model names available in LiteLLM. Wildcard entries (e.g. anthropic/*) are expanded: first by querying the running LiteLLM pod's /v1/models endpoint, falling back to the baked-in WellKnownModels list if the cluster is unreachable.

func GetMasterKey added in v0.6.0

func GetMasterKey(cfg *config.Config) (string, error)

GetMasterKey reads the LiteLLM master key from the cluster Secret.

func GetProviderStatus

func GetProviderStatus(cfg *config.Config) (map[string]ProviderStatus, error)

GetProviderStatus reads LiteLLM config and returns provider status.

func PullOllamaModel added in v0.5.0

func PullOllamaModel(name string) error

PullOllamaModel pulls a model from the Ollama registry. It streams progress to stdout, matching the UX of `ollama pull`.

func ValidateCustomEndpoint added in v0.6.0

func ValidateCustomEndpoint(endpoint, modelName, apiKey string) error

ValidateCustomEndpoint validates that a custom OpenAI-compatible endpoint works. It runs a 2-step validation: reachability check, then inference probe. The inference probe is the definitive test — some servers (e.g., mlx-lm) don't list the loaded model in /models but accept it for inference.

Types

type LiteLLMConfig added in v0.6.0

type LiteLLMConfig struct {
	ModelList       []ModelEntry   `yaml:"model_list"`
	GeneralSettings map[string]any `yaml:"general_settings,omitempty"`
	LiteLLMSettings map[string]any `yaml:"litellm_settings,omitempty"`
}

LiteLLMConfig represents the LiteLLM proxy config.yaml structure.

type LiteLLMParams added in v0.6.0

type LiteLLMParams struct {
	Model   string `yaml:"model"`
	APIBase string `yaml:"api_base,omitempty"`
	APIKey  string `yaml:"api_key,omitempty"`
}

LiteLLMParams holds the routing parameters for a model.

type ModelEntry added in v0.6.0

type ModelEntry struct {
	ModelName     string        `yaml:"model_name"`
	LiteLLMParams LiteLLMParams `yaml:"litellm_params"`
}

ModelEntry is a single entry in model_list.

type OllamaModel added in v0.5.0

type OllamaModel struct {
	Name       string `json:"name"`
	Size       int64  `json:"size"`
	ModifiedAt string `json:"modified_at"`
}

OllamaModel describes a model pulled in the local Ollama instance.

func ListOllamaModels added in v0.5.0

func ListOllamaModels() ([]OllamaModel, error)

ListOllamaModels queries the local Ollama server for pulled models. Returns nil and an error if Ollama is not reachable.

type ProviderInfo added in v0.3.1

type ProviderInfo struct {
	ID     string // provider id (e.g. "anthropic", "openai", "ollama")
	Name   string // display name
	EnvVar string // env var for API key (empty for Ollama)
}

ProviderInfo describes an LLM provider.

func GetAvailableProviders added in v0.3.1

func GetAvailableProviders(_ *config.Config) ([]ProviderInfo, error)

GetAvailableProviders returns the known provider list (static, no pod query needed).

type ProviderStatus

type ProviderStatus struct {
	Enabled   bool
	HasAPIKey bool
	EnvVar    string // environment variable name (e.g. ANTHROPIC_API_KEY)
	Models    []string
}

ProviderStatus captures effective global LiteLLM provider state.

Jump to

Keyboard shortcuts

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