models

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package models manages the local model cache: catalog manifests (teraflock/models format), resumable GGUF downloads with SHA256 verification, and LRU eviction under the operator's disk budget.

Index

Constants

View Source
const (
	OriginOperator = "operator"
	OriginMesh     = "mesh"
)

Origins for cache entries.

Variables

View Source
var ErrInvalidID = errors.New("models: invalid model id")

ErrInvalidID rejects a model id that is unsafe to use as a path component.

View Source
var ErrOverBudget = errors.New("models: cannot fit")

ErrOverBudget means a model cannot fit inside max_disk_mb even after evicting everything eviction is allowed to touch.

View Source
var ErrSHAMismatch = errors.New("models: sha256 mismatch")

ErrSHAMismatch means a downloaded artifact failed verification. The daemon refuses to serve hash-mismatched files (SPEC §6).

Functions

func LocalArtifactPath

func LocalArtifactPath(artifactURL string) (string, bool)

LocalArtifactPath reports whether an artifact_url points at a file already on this machine, and returns its filesystem path. Both `file:///abs/path` and a bare absolute path are accepted — operators writing a local catalog by hand reach for the latter.

This is how a node serves an existing GGUF collection (LM Studio, ollama, hand-built quants) without re-downloading gigabytes it already has.

func ValidateID added in v0.2.0

func ValidateID(id string) error

ValidateID rejects ids that must never reach filepath.Join. Catalog entries arrive over the network (models.manifest_url is a remote default), so an id such as "../../etc/cron.d/evil" would otherwise escape Dir and let a compromised catalog write anywhere the daemon can.

Types

type Catalog

type Catalog struct {
	Models []CatalogModel `yaml:"models" json:"models"`
}

Catalog is the manifest format of the teraflock/models repo (catalog/*.yaml). JSON is accepted too.

func LoadCatalog

func LoadCatalog(ctx context.Context, path, url string, client *http.Client) (*Catalog, error)

LoadCatalog reads a catalog from a local path or URL (one must be set; path wins).

func ParseCatalog

func ParseCatalog(raw []byte) (*Catalog, error)

ParseCatalog decodes YAML or JSON manifest bytes.

func (*Catalog) Find

func (c *Catalog) Find(id string) (CatalogModel, bool)

Find returns the entry with the given id.

type CatalogModel

type CatalogModel struct {
	ID string `yaml:"id" json:"id"`
	// DisplayName is the human-readable name (incl. quant) UIs show —
	// ids are ambiguous now that model lines carry point versions
	// (qwen3-8b vs qwen3.8-27b). Empty in pre-field catalogs.
	DisplayName   string  `yaml:"display_name" json:"display_name"`
	Family        string  `yaml:"family" json:"family"`
	ParamsB       float64 `yaml:"params_b" json:"params_b"`
	Quant         string  `yaml:"quant" json:"quant"`
	SHA256        string  `yaml:"sha256" json:"sha256"`
	MinVRAMMB     uint64  `yaml:"min_vram_mb" json:"min_vram_mb"`
	MinRAMMB      uint64  `yaml:"min_ram_mb" json:"min_ram_mb"`
	License       string  `yaml:"license" json:"license"`
	ArtifactURL   string  `yaml:"artifact_url" json:"artifact_url"`
	SizeBytes     uint64  `yaml:"size_bytes" json:"size_bytes"`
	PayoutClass   string  `yaml:"payout_class" json:"payout_class"`
	ContextLength uint32  `yaml:"context_length" json:"context_length"`
	Embeddings    bool    `yaml:"embeddings" json:"embeddings"`
}

CatalogModel is one curated model entry.

func (CatalogModel) Spec

func (m CatalogModel) Spec() *typesv1.ModelSpec

Spec converts a catalog entry to the proto ModelSpec.

type Info

type Info struct {
	ID        string    `json:"id"`
	SizeBytes int64     `json:"size_bytes"`
	Pinned    bool      `json:"pinned"`
	LastUsed  time.Time `json:"last_used"`
	State     string    `json:"state"`
	// Origin is "operator" or "mesh" (who installed it).
	Origin string `json:"origin"`
	// ReceivedBytes is live progress, present only while downloading.
	ReceivedBytes int64 `json:"received_bytes,omitempty"`
}

Info is a local cache listing row.

type Manager

type Manager struct {
	Dir       string
	MaxDiskMB int64
	Client    *http.Client
	Log       *slog.Logger

	// OnProgress, when set, receives byte progress during downloads
	// (throttled). total is 0 when the server sent no length and the
	// catalog carries no size.
	OnProgress func(id string, received, total int64)
	// contains filtered or unexported fields
}

Manager owns <data_dir>/models: downloads, verification, pins and LRU eviction under the disk budget.

func NewManager

func NewManager(dir string, maxDiskMB int64, log *slog.Logger) (*Manager, error)

NewManager loads (or initializes) the cache state.

func (*Manager) DownloadProgress added in v0.3.0

func (m *Manager) DownloadProgress(id string) (Progress, bool)

DownloadProgress reports live byte progress for an in-flight download.

func (*Manager) Ensure

func (m *Manager) Ensure(ctx context.Context, spec *typesv1.ModelSpec) (string, error)

Ensure makes the model available locally: verified cache hit, resumed partial download, or full download. Returns the local path. The entry is operator-owned; see EnsureOrigin.

func (*Manager) EnsureOrigin added in v0.3.0

func (m *Manager) EnsureOrigin(ctx context.Context, spec *typesv1.ModelSpec, origin string) (string, error)

EnsureOrigin is Ensure with ownership: a mesh-origin fetch may only evict other mesh-origin models to make room (the operator's models are off limits to the coordinator), and a model the operator already has is never re-labelled as the mesh's.

func (*Manager) List

func (m *Manager) List() []Info

List returns cache contents sorted by id.

func (*Manager) Origin added in v0.3.0

func (m *Manager) Origin(id string) string

Origin reports who owns a cached model ("" when not cached).

func (*Manager) Path

func (m *Manager) Path(id string) string

Path returns where a model artifact lives locally.

func (*Manager) Pin

func (m *Manager) Pin(id string, pinned bool) error

Pin marks a model exempt from eviction; unpin re-allows it.

func (*Manager) Remove

func (m *Manager) Remove(id string) error

Remove deletes a model from the cache.

func (*Manager) Touch

func (m *Manager) Touch(id string)

Touch refreshes LRU recency (called when a model serves a request).

func (*Manager) Verify

func (m *Manager) Verify(id string) error

Verify re-hashes a cached artifact against its recorded SHA. Serving paths call this before loading a model into the runtime.

type Progress added in v0.3.0

type Progress struct {
	ReceivedBytes int64 `json:"received_bytes"`
	TotalBytes    int64 `json:"total_bytes"`
}

Progress is live byte progress for an in-flight download.

Jump to

Keyboard shortcuts

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