model

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package model defines model metadata and collections.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextLength

type ContextLength int

ContextLength represents a context window size.

func (ContextLength) PercentUsed

func (c ContextLength) PercentUsed(inputTokens int) float64

PercentUsed returns the percentage of context used by the given input token count.

func (ContextLength) String

func (c ContextLength) String() string

String returns a human-readable SI format (e.g., "8k", "128k").

type DisplayOptions

type DisplayOptions struct {
	Bullet       string
	ModelName    func(a ...any) string
	ParamsLabel  string
	ParamsValue  func(a ...any) string
	ContextLabel string
	ContextValue func(a ...any) string
	SizeLabel    string
	SizeValue    func(a ...any) string
	ThinkingIcon func(a ...any) string
	VisionIcon   func(a ...any) string
	NameWidth    int
	MaxParamsLen int
	MaxCtxLen    int
}

type Model

type Model struct {
	// Name is the model identifier.
	Name string
	// ParameterCount is the model's parameter count (e.g., 8B = 8_000_000_000).
	ParameterCount ParameterCount `json:"parameter_count,omitempty"`
	// ContextLength is the maximum context window size.
	ContextLength ContextLength `json:"context_length"`
	// Capabilities lists the model's supported features.
	Capabilities capabilities.Capabilities `json:",omitempty"`
	// Family is the model family name (e.g., "gpt", "llama").
	Family string `json:",omitempty"`
	// Size is the model size in bytes.
	Size uint64 `json:",omitempty"`
}

Model represents an LLM model with metadata.

func (Model) Context

func (m Model) Context(opts DisplayOptions) string

func (*Model) Deref

func (m *Model) Deref() Model

Deref safely dereferences a *Model pointer. Returns the Model value if non-nil, or a zero-value Model if nil. Safe to call on nil receivers.

func (Model) Display

func (m Model) Display(opts DisplayOptions) string

Display returns a formatted, colorized string for a single model.

func (Model) Matches

func (m Model) Matches(pattern string) bool

Matches returns true if the pattern matches this model's name.

func (Model) Params

func (m Model) Params(opts DisplayOptions) string

func (Model) String

func (m Model) String() string

String returns the model name.

type Models

type Models []Model

Models is a collection of model metadata.

func FromNames

func FromNames(names []string) Models

FromNames creates a Models collection from model names.

func (Models) ByContextLength

func (ms Models) ByContextLength() Models

ByContextLength returns models sorted by context length (descending), with name as fallback.

func (Models) ByName

func (ms Models) ByName() Models

ByName returns models sorted alphabetically by name.

func (Models) BySize

func (ms Models) BySize() Models

BySize returns models sorted by size (descending), with context length as fallback.

func (Models) Display

func (ms Models) Display(w io.Writer, sortBy SortBy) error

Display prints the models in a formatted, colorized output grouped by capability.

func (Models) Exclude

func (ms Models) Exclude(patterns ...string) Models

Exclude returns models that do not match any of the given wildcard patterns.

func (Models) Exists

func (ms Models) Exists(name string) bool

Exists returns true if a model with the given name exists.

func (Models) Get

func (ms Models) Get(name string) Model

Get returns the model with the given name, or zero value if not found.

func (Models) HasTools

func (ms Models) HasTools() Models

HasTools returns models with tool calling capability.

func (Models) Include

func (ms Models) Include(patterns ...string) Models

Include returns models matching any of the given wildcard patterns.

func (Models) IsEmbedding

func (ms Models) IsEmbedding() Models

IsEmbedding returns embedding models.

func (Models) IsGeneral

func (ms Models) IsGeneral() Models

IsGeneral returns general-purpose models (neither embedding nor tool-specific).

func (Models) LongestName

func (ms Models) LongestName() int

LongestName returns the display width of the longest model name.

func (Models) Names

func (ms Models) Names() []string

Names returns a slice of model names.

func (Models) Sort

func (ms Models) Sort(by SortBy) Models

Sort returns models sorted by the specified field.

func (Models) WithCapability

func (ms Models) WithCapability(cap capabilities.Capability) Models

WithCapability returns models that have the given capability.

type ParameterCount

type ParameterCount int64

ParameterCount represents a model's parameter count in absolute units. For example, an 8B model is stored as 8_000_000_000.

func ParseParameterName

func ParseParameterName(name string) ParameterCount

ParseParameterName extracts a parameter count from a model name string. Falls back to 0 if no pattern is found.

func ParseParameterSize

func ParseParameterSize(s string) ParameterCount

ParseParameterSize parses an explicit parameter size string (e.g., "8B", "70.6B", "567M"). This is the format returned by the Ollama API's Details.ParameterSize field. Returns 0 if the string doesn't match.

func (ParameterCount) Billions

func (p ParameterCount) Billions() float64

Billions returns the parameter count in billions as a float.

func (ParameterCount) String

func (p ParameterCount) String() string

String returns a human-readable parameter count (e.g., "8B", "70B", "1.5B", "567M"). Zero value returns an empty string.

type SortBy

type SortBy string

SortBy represents the field to sort models by.

const (
	SortByName    SortBy = "name"
	SortByContext SortBy = "context"
	SortBySize    SortBy = "size"
)

Jump to

Keyboard shortcuts

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