models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 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

This section is empty.

Variables

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.

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"`
	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"`
}

Info is a local cache listing row.

type Manager

type Manager struct {
	Dir       string
	MaxDiskMB int64
	Client    *http.Client
	Log       *slog.Logger
	// 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) 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.

func (*Manager) List

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

List returns cache contents sorted by id.

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.

Jump to

Keyboard shortcuts

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