models

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package models manages AI model resources: an inference engine (Ollama, vLLM, llama.cpp) running as a container on a GPU node, with an OpenAI-compatible endpoint fronted by an API-key gateway.

Index

Constants

View Source
const (
	TierLight   = "light"
	TierDefault = "default"
	TierPlus    = "plus"

	KindChat      = "chat"
	KindEmbedding = "embedding"
)

Tiers of the curated local model list.

View Source
const (
	ComputeGPU = store.ComputeGPU
	ComputeCPU = store.ComputeCPU
)

Compute kinds of a model resource.

View Source
const (
	CPUFitComfortable = "fits_comfortably"
	CPUFitTight       = "tight"
	CPUFitWontFit     = "wont_fit"
	CPUFitUnknown     = "unknown"
)

CPU fit verdicts.

View Source
const (
	DLGated          = "gated"
	DLNotFound       = "not_found"
	DLDiskFull       = "disk_full"
	DLInterrupted    = "interrupted"
	DLChecksum       = "checksum_mismatch"
	DLHostNotAllowed = "host_not_allowed"
	DLTooLarge       = "too_large"
	DLUnavailable    = "unavailable"
	DLInvalid        = "invalid"
)

Download failure codes, shown in the resource status.

View Source
const (
	DLPending     = "pending"
	DLDownloading = "downloading"
	DLVerifying   = "verifying"
	DLDone        = "done"
	DLFailed      = "failed"
)

Download phases.

View Source
const (
	ComputeExternal = store.ComputeExternal
	EngineExternal  = "external"
)

Compute kind and engine name of a model served by an external endpoint.

View Source
const (
	DiagRefused         = "connection_refused"
	DiagTimeout         = "timeout"
	DiagDNS             = "dns"
	DiagBlocked         = "address_blocked"
	DiagPrivateDisabled = "private_not_enabled"
	DiagAuth            = "auth_failed"
	DiagWrongPort       = "wrong_port"
	DiagNotFound        = "route_not_found"
	DiagBadResponse     = "bad_response"
	DiagTLS             = "tls"
	DiagNoModels        = "no_models"
	DiagUpstream        = "upstream_error"
)

Diagnosis codes a probe can return; the dashboard maps each to a typed fix.

View Source
const (
	MetricEngineKVCachePercent = "engine_kv_cache_percent"
	MetricEngineRunning        = "engine_requests_running"
	MetricEngineWaiting        = "engine_requests_waiting"
	MetricEnginePrefixHitPct   = "engine_prefix_cache_hit_percent"
	MetricEngineGenRate        = "engine_tokens_per_second"
	MetricEngineTTFTSeconds    = "engine_ttft_seconds"
	MetricEngineVRAMBytes      = "engine_vram_bytes"
	MetricEngineOffloadPercent = "engine_offload_percent"
)

Sample metric names written for a model's engine under resource "model:<name>".

View Source
const (
	EngineHealthOK      = "ok"
	EngineHealthWarn    = "warn"
	EngineHealthUnknown = "unknown"
)

Engine health states.

View Source
const (
	EngineOllama   = "ollama"
	EngineVLLM     = "vllm"
	EngineLlamaCpp = "llamacpp"
)

Supported engines.

View Source
const (
	WeightsExact     = "exact"
	WeightsEstimated = "estimated"
	WeightsUnknown   = "unknown"
)

Source of the weight size behind a fit result.

View Source
const (
	HFStatusOK          = "ok"
	HFStatusNotFound    = "not_found"
	HFStatusGated       = "gated"
	HFStatusRateLimited = "rate_limited"
	HFStatusUnavailable = "unavailable"
	HFStatusUnsupported = "unsupported"
)

Hub statuses reported by Preflight.

View Source
const (
	FitFits    = "fits"
	FitTight   = "tight"
	FitWontFit = "wont_fit"
	FitUnknown = "unknown"
)

Fit verdicts. FitUnknown means the node facts needed to judge are missing.

View Source
const CPUFitNote = "Memory and speed are estimates, not measurements: weights come from the file size, the KV cache is approximated from the " +
	"parameter count and context, and speed assumes memory bandwidth scales with the CPUs you allow. Run the benchmark on the running model for real numbers."

CPUFitNote states what the CPU preflight can and cannot promise.

View Source
const CPUImageDefault = "ghcr.io/ggml-org/llama.cpp:server"

CPUImageDefault is the official llama.cpp CPU server image, used for CPU models. APP_MODEL_IMAGE_LLAMACPP_CPU overrides it.

View Source
const CacheNote = "Each model keeps its weights in its own Docker volume, so the cache is listed per volume, not per file. " +
	"Last used comes from gateway traffic when a model has any, else from the model's last change. " +
	"Only the control plane's own host is inspected; remote nodes are not listed yet."

CacheNote states what the cache listing can and cannot see.

View Source
const EndpointAllowPrivateEnv = "APP_MODEL_ENDPOINT_ALLOW_PRIVATE_NETWORKS"

EndpointAllowPrivateEnv lets external inference endpoints sit on private addresses (a Mac on the mesh or LAN). netguard.AllowPrivateEnv enables it too.

View Source
const FitNote = "Fit figures are estimates: weights plus a flat overhead for the KV cache and compute buffers. " +
	"Real usage depends on context length, batch size, engine and driver."

FitNote states the limits of every fit number.

View Source
const FitNoteVRAM = "This is an estimate, not a guarantee: weights are sized from the model name and quantization (exact when the Hugging Face file sizes are known), " +
	"the KV cache is approximated from the parameter count and context length, and engine overhead is a flat allowance. " +
	"Real usage depends on the engine version, batch size and driver."

FitNoteVRAM states the limits of the per-node VRAM check.

View Source
const ImageKeyLlamaCppCPU = EngineLlamaCpp + "-cpu"

ImageKeyLlamaCppCPU is the images map key of the CPU llama.cpp image.

View Source
const LocalNodeName = "local"

LocalNodeName labels the control plane's own host in GPU listings.

View Source
const UsageNote = "Tokens are counted only for responses that carry a usage object: non-streaming responses, and streams " +
	"opened with stream_options.include_usage. Other requests are counted as requests only, and nothing is estimated. " +
	"Figures lag the gateway by up to one flush interval."

UsageNote explains the limits of the token counts.

Variables

View Source
var (
	ErrBenchDisabled  = errors.New("models: benchmark is not enabled on this control plane")
	ErrBenchBusy      = errors.New("models: a benchmark is already running for this model")
	ErrBenchNotReady  = errors.New("models: the model is not running; wake it first, a benchmark never starts a model")
	ErrBenchEmbedding = errors.New("models: the benchmark measures chat generation and does not apply to an embedding model")
)

Benchmark errors, distinguishable by callers to pick an HTTP status.

View Source
var (
	ErrEndpointBlocked = errors.New("models: endpoint address is never allowed (link-local, metadata or unspecified)")
	ErrEndpointPrivate = errors.New("models: endpoint address is private and internal destinations are not enabled")
)

Endpoint URL refusals.

View Source
var (
	ErrInvalid            = errors.New("models: invalid request")
	ErrSecretsUnavailable = errors.New("models: no secrets master key is configured")
	ErrNodeNotFound       = errors.New("models: node not found")
)

Errors returned by Service, distinguishable by callers to pick an HTTP status.

View Source
var ErrKeyExists = errors.New("models: a key with this name already exists")

ErrKeyExists is returned when a live key of the model already has the name.

View Source
var ErrKeyNotFound = errors.New("models: key not found")

ErrKeyNotFound is returned when a model has no such key.

View Source
var ErrLicenseAck = errors.New("models: non-curated repository needs a licence acknowledgement")

ErrLicenseAck is returned when a non-curated repository is requested without the explicit licence acknowledgement.

Functions

func AllowedRoutes

func AllowedRoutes(engine string) []string

AllowedRoutes lists the "METHOD path" pairs the gateway forwards for an engine; a trailing slash marks a prefix.

func CPUCommand

func CPUCommand(m Spec, l CPULimits, p CPUPolicy, localFile string, weightsBytes int64, embedding bool) []string

CPUCommand builds the llama.cpp server command line of a CPU model. localFile is the weights path inside the container, empty to let the engine pull the repository itself (remote nodes).

func CacheUnusedDays

func CacheUnusedDays() int

CacheUnusedDays is APP_MODEL_CACHE_UNUSED_DAYS (default 30).

func Command

func Command(m Spec, gpus int) []string

Command returns the engine container's command line. gpus is the resolved number of GPUs the container will see.

func ContainerPrefix

func ContainerPrefix(prefix, name string) string

ContainerPrefix is the name prefix shared by every container of model name, across config revisions.

func ControllerName

func ControllerName(name string) string

ControllerName is the reconcile_status name for model name.

func DefaultIdleTTL

func DefaultIdleTTL() time.Duration

DefaultIdleTTL reads APP_MODEL_IDLE_TTL.

func EndpointHealthInterval

func EndpointHealthInterval() time.Duration

EndpointHealthInterval is the time between background health probes.

func EndpointPrivateAllowed

func EndpointPrivateAllowed() bool

EndpointPrivateAllowed reports whether the operator enabled internal destinations.

func EndpointSlowThreshold

func EndpointSlowThreshold() time.Duration

EndpointSlowThreshold is the list-models latency above which an endpoint is "slow".

func EngineMetricsInterval

func EngineMetricsInterval() time.Duration

EngineMetricsInterval reads APP_MODEL_ENGINE_METRICS_INTERVAL.

func EngineNames

func EngineNames() []string

EngineNames lists supported engines in stable order.

func Env

func Env(m Spec, hfToken string) map[string]string

Env returns the engine container's environment. hfToken may be empty.

func EstimateWeightBytes

func EstimateWeightBytes(engine, ref, quant string) (int64, bool)

EstimateWeightBytes sizes a model's weights from its name and quantization alone.

func HashAPIKey

func HashAPIKey(plaintext string) string

HashAPIKey returns the SHA-256 hex digest stored for a key.

func IdleTTL

func IdleTTL(m store.Model) time.Duration

IdleTTL is how long an on-demand model may go unused before its engine stops: its own setting, else the platform default.

func KeyMatches

func KeyMatches(plaintext, storedHash string) bool

KeyMatches reports whether plaintext hashes to storedHash, in constant time.

func KeyRotationGrace

func KeyRotationGrace() time.Duration

KeyRotationGrace returns the grace window used when a rotation names none.

func LicenseNotice

func LicenseNotice(repoLicense string) string

LicenseNotice is the text shown for a repository that is not curated.

func MaxUsageWindow

func MaxUsageWindow() time.Duration

MaxUsageWindow is the longest window Usage serves: the retention, or a year when retention is unlimited.

func ModelClaim

func ModelClaim(m store.Model) gpu.Claim

ModelClaim is the GPU reservation of a model.

func ModelClaimName

func ModelClaimName(name string) string

ModelClaimName is the reservation label of a model.

func NewAPIKey

func NewAPIKey() (plaintext, hash, prefix string, err error)

NewAPIKey returns a fresh plaintext key, its SHA-256 hex hash, and a short non-secret prefix for display. The plaintext is shown once.

func NewKeyID

func NewKeyID() (string, error)

NewKeyID returns a random identifier for a virtual key.

func NormalizeEndpointURL

func NormalizeEndpointURL(ctx context.Context, raw string, lookup HostLookup) (string, error)

NormalizeEndpointURL validates an endpoint base URL and returns it without a trailing slash or /v1 suffix. A hostname that does not resolve is accepted, since the dial check decides at request time.

func ParseHFRepo

func ParseHFRepo(in string) (repo, quant string, ok bool)

ParseHFRepo splits a repo reference into "owner/name" and an optional quant, accepting huggingface.co and hf.co URL prefixes.

func ParseParamsBillions

func ParseParamsBillions(ref string) (float64, bool)

ParseParamsBillions extracts the parameter count (in billions) from a model reference such as "llama3.1:8b" or "org/Mixtral-8x7B-GGUF". MoE references count every expert, since all of them stay resident.

func QuantName

func QuantName(path string) string

QuantName extracts the quantization label from a GGUF file path, or "" when there is none or the file is not a weight file.

func ResidencyActive

func ResidencyActive(m store.Model, now time.Time) bool

ResidencyActive reports whether an on-demand model should have its engine running at now: it was used or woken within its idle TTL.

func ServiceClaim

func ServiceClaim(svc store.DesiredService) (gpu.Claim, bool)

ServiceClaim is the GPU reservation of an app, ok false when it asks for none.

func ServiceClaimName

func ServiceClaimName(name string) string

ServiceClaimName is the reservation label of an app.

func ShmBytes

func ShmBytes(engine string) int64

ShmBytes is the /dev/shm size the engine needs (vLLM tensor parallelism exchanges tensors through shared memory). 0 keeps Docker's default.

func ValidateAllowPaths

func ValidateAllowPaths(engine string, paths []string) (string, bool)

ValidateAllowPaths reports the first entry that is not a path the engine's gateway allowlist forwards.

func VolumeName

func VolumeName(prefix, name string) string

VolumeName is the persistent model-cache volume of model name.

Types

type BenchConfig

type BenchConfig struct {
	// Timeout is the hard cap for the whole run.
	Timeout     time.Duration
	MinInterval time.Duration
	MaxTokens   int
	SampleEvery time.Duration
}

BenchConfig tunes the benchmark. Zero fields take the defaults.

func LoadBenchConfig

func LoadBenchConfig() BenchConfig

LoadBenchConfig reads APP_MODEL_BENCH_TIMEOUT, APP_MODEL_BENCH_MIN_INTERVAL and APP_MODEL_BENCH_MAX_TOKENS.

type BenchPrompt

type BenchPrompt struct {
	Name             string  `json:"name"`
	PromptTokens     int     `json:"prompt_tokens"`
	CompletionTokens int     `json:"completion_tokens"`
	TTFTMillis       int64   `json:"ttft_ms"`
	PromptTPS        float64 `json:"prompt_tokens_per_sec"`
	GenTPS           float64 `json:"gen_tokens_per_sec"`
}

BenchPrompt is the measurement of one fixed prompt.

type BenchRateLimitError

type BenchRateLimitError struct{ RetryAfter time.Duration }

BenchRateLimitError reports when the next benchmark may run.

func (*BenchRateLimitError) Error

func (e *BenchRateLimitError) Error() string

type BenchResult

type BenchResult struct {
	Model            string        `json:"model"`
	RanAt            time.Time     `json:"ran_at"`
	DurationMillis   int64         `json:"duration_ms"`
	Prompts          []BenchPrompt `json:"prompts"`
	PromptTPS        float64       `json:"prompt_tokens_per_sec"`
	GenTPS           float64       `json:"gen_tokens_per_sec"`
	TTFTMillis       int64         `json:"ttft_ms"`
	PeakMemoryBytes  uint64        `json:"peak_memory_bytes"`
	MemoryLimitBytes uint64        `json:"memory_limit_bytes"`
	Truncated        bool          `json:"truncated"`
	Note             string        `json:"note"`
}

BenchResult is the stored outcome of one benchmark.

func ParseBenchmark

func ParseBenchmark(raw string) *BenchResult

ParseBenchmark decodes a stored benchmark, nil when none ran.

type BenchStatsFunc

type BenchStatsFunc func(ctx context.Context, m store.Model) (used, limit uint64, ok bool)

BenchStatsFunc reads a running model container's memory use. ok is false when it cannot be read.

type CPUBounds

type CPUBounds struct {
	DefaultCPUMilli  int   `json:"default_cpu_milli"`
	DefaultMemoryMiB int   `json:"default_memory_mib"`
	MaxCPUMilli      int   `json:"max_cpu_milli"`
	MaxMemoryMiB     int   `json:"max_memory_mib"`
	FreeRAMFloorMiB  int64 `json:"free_ram_floor_mib"`
}

CPUBounds are the defaults and ceilings a deploy form offers for a node.

type CPUFit

type CPUFit struct {
	Verdict        string   `json:"verdict"`
	Reason         string   `json:"reason"`
	Suggestion     string   `json:"suggestion,omitempty"`
	SuggestedID    string   `json:"suggested_id,omitempty"`
	CPUMilli       int      `json:"cpu_milli"`
	MemoryMiB      int      `json:"memory_mib"`
	ContextTokens  int      `json:"context_tokens"`
	WeightsBytes   int64    `json:"weights_bytes"`
	WeightsSource  string   `json:"weights_source"`
	KVBytes        int64    `json:"kv_bytes"`
	OverheadBytes  int64    `json:"overhead_bytes"`
	NeedBytes      int64    `json:"need_bytes"`
	CapBytes       int64    `json:"cap_bytes"`
	DiskBytes      int64    `json:"disk_bytes"`
	DiskOK         *bool    `json:"disk_ok"`
	TokensPerSecLo float64  `json:"tokens_per_sec_low"`
	TokensPerSecHi float64  `json:"tokens_per_sec_high"`
	Estimate       bool     `json:"estimate"`
	Arithmetic     string   `json:"arithmetic"`
	Warnings       []string `json:"warnings"`
	Note           string   `json:"note"`
}

CPUFit is the preflight answer for CPU mode.

type CPUFitInput

type CPUFitInput struct {
	ModelRef      string
	Quantization  string
	ContextTokens int
	// WeightsBytes is the exact file size, 0 to estimate from the name.
	WeightsBytes int64
	// ParamsB overrides the count parsed from the name when positive.
	ParamsB float64
	// EntryID is the catalog id, used to avoid suggesting the same model.
	EntryID string
	Host    HostFacts
	// CPUMilli and MemoryMiB are the requested caps, 0 for defaults.
	CPUMilli  int
	MemoryMiB int
	// DiskFreeBytes is -1 when unknown.
	DiskFreeBytes int64
}

CPUFitInput describes a CPU model against a node and its caps.

type CPUFitReport

type CPUFitReport struct {
	CPUFit
	NodeID         string        `json:"node_id"`
	HostKnown      bool          `json:"host_known"`
	HostCPUs       int           `json:"host_cpus"`
	HostMemBytes   int64         `json:"host_memory_bytes"`
	HostMemFree    int64         `json:"host_memory_available_bytes"`
	DiskFreeBytes  *int64        `json:"disk_free_bytes"`
	Entry          *CatalogEntry `json:"entry,omitempty"`
	LicenseCurated bool          `json:"license_curated"`
	LicenseNotice  string        `json:"license_notice,omitempty"`
}

CPUFitReport is the CPU preflight with the node figures behind it.

type CPUFitRequest

type CPUFitRequest struct {
	CatalogID     string
	ModelRef      string
	Quantization  string
	ContextLength int
	WeightsBytes  int64
	NodeID        string
	CPUMilli      int
	MemoryMiB     int
}

CPUFitRequest asks whether a model fits a node in CPU mode.

type CPULimits

type CPULimits struct {
	CPUMilli  int
	MemoryMiB int
	Context   int
}

CPULimits are the resolved hard caps of one CPU model.

func (CPULimits) Threads

func (l CPULimits) Threads() int

Threads is the llama.cpp thread count: the whole CPUs of the cap.

type CPUPolicy

type CPUPolicy struct {
	// DefaultCPUs is used when a request sets no cpu cap; 0 means min(2, half the node).
	DefaultCPUs float64
	// DefaultMemoryPercent is the default memory cap as a share of node RAM.
	DefaultMemoryPercent float64
	// MaxCPUPercent and MaxMemoryPercent bound what a request may ask for.
	MaxCPUPercent    float64
	MaxMemoryPercent float64
	// FreeRAMFloorMiB is the RAM that must stay free for other workloads
	// after the memory cap is taken.
	FreeRAMFloorMiB int64
	CPUShares       int64
	OomScoreAdj     int
	PidsLimit       int64
	// DefaultContext is the context size when the request sets none.
	DefaultContext int
	// CachePercent and CacheMaxMiB bound llama.cpp's prompt cache (-cram).
	CachePercent float64
	CacheMaxMiB  int
	// MmapHeadroomMiB is the memory left beyond the weights below which
	// weights are loaded with --no-mmap; MmapMode forces "on" or "off".
	MmapHeadroomMiB int64
	MmapMode        string
	// OverheadMiB is the engine's fixed allowance in the fit estimate.
	OverheadMiB int64
	// ComfortPercent is the share of the cap a model may use to count as comfortable.
	ComfortPercent float64
	// BandwidthPerCPUGBs and BandwidthMaxGBs drive the tokens per second estimate.
	BandwidthPerCPUGBs float64
	BandwidthMaxGBs    float64
}

CPUPolicy holds every CPU-mode guardrail. All values are environment driven so no threshold is hardcoded.

func LoadCPUPolicy

func LoadCPUPolicy() CPUPolicy

LoadCPUPolicy reads the APP_MODEL_CPU_* variables.

func (CPUPolicy) Bounds

func (p CPUPolicy) Bounds(h HostFacts) CPUBounds

Bounds reports the defaults and ceilings for h; zeros when h is unknown.

func (CPUPolicy) CacheMiB

func (p CPUPolicy) CacheMiB(memoryMiB int) int

CacheMiB is the bounded prompt cache for the memory cap.

func (CPUPolicy) Check

func (p CPUPolicy) Check(cat Catalog, fp FitParams, in CPUFitInput) CPUFit

Check rates a CPU model. It never guesses a size it cannot read.

func (CPUPolicy) ResolveCPULimits

func (p CPUPolicy) ResolveCPULimits(h HostFacts, reqCPUMilli, reqMemoryMiB, reqContext int) (CPULimits, error)

ResolveCPULimits turns a request (zeros mean default) into hard caps and refuses caps the node cannot honour.

type CacheBackend

type CacheBackend interface {
	ListVolumesByPrefix(ctx context.Context, prefix string) ([]docker.NamedVolume, error)
	RemoveVolume(ctx context.Context, name string) error
}

CacheBackend is the Docker surface the cache manager needs.

type CacheEntry

type CacheEntry struct {
	Volume         string     `json:"volume"`
	Model          string     `json:"model,omitempty"`
	Engine         string     `json:"engine,omitempty"`
	ModelRef       string     `json:"model_ref,omitempty"`
	SizeBytes      *int64     `json:"size_bytes"`
	LastUsedAt     *time.Time `json:"last_used_at"`
	LastUsedSource string     `json:"last_used_source"`
	UnusedDays     int        `json:"unused_days"`
	Unused         bool       `json:"unused"`
	InUse          bool       `json:"in_use"`
	Configured     bool       `json:"configured"`
	// DuplicateOf names the volume holding the same weights that is
	// counted in UniqueBytes instead of this one.
	DuplicateOf string `json:"duplicate_of,omitempty"`
	Prunable    bool   `json:"prunable"`
	KeepReason  string `json:"keep_reason,omitempty"`
}

CacheEntry is one cached weights volume.

type CacheNode

type CacheNode struct {
	NodeID           string       `json:"node_id"`
	Name             string       `json:"name"`
	IsLocal          bool         `json:"is_local"`
	Supported        bool         `json:"supported"`
	Message          string       `json:"message,omitempty"`
	Entries          []CacheEntry `json:"entries"`
	TotalBytes       int64        `json:"total_bytes"`
	UniqueBytes      int64        `json:"unique_bytes"`
	ReclaimableBytes int64        `json:"reclaimable_bytes"`
	DiskFreeBytes    *int64       `json:"disk_free_bytes"`
}

CacheNode is one node's cache.

type CachePruneResult

type CachePruneResult struct {
	DryRun         bool         `json:"dry_run"`
	Candidates     []CacheEntry `json:"candidates"`
	Removed        []string     `json:"removed"`
	Skipped        []CacheSkip  `json:"skipped"`
	ReclaimedBytes int64        `json:"reclaimed_bytes"`
}

CachePruneResult reports a prune. With DryRun set nothing was removed and Candidates is what a real run would remove.

type CacheReport

type CacheReport struct {
	UnusedDays int         `json:"unused_days"`
	Nodes      []CacheNode `json:"nodes"`
	Note       string      `json:"note"`
}

CacheReport lists every node's model cache.

type CacheSkip

type CacheSkip struct {
	Volume string `json:"volume"`
	Reason string `json:"reason"`
}

CacheSkip is a volume a prune left alone.

type Catalog

type Catalog struct {
	Version    int            `json:"version"`
	VerifiedOn string         `json:"verified_on"`
	Note       string         `json:"note"`
	Models     []CatalogEntry `json:"models"`
}

Catalog is the curated list with its provenance.

func LocalCatalog

func LocalCatalog() (Catalog, error)

LocalCatalog returns the embedded curated list.

func ParseCatalog

func ParseCatalog(data []byte) (Catalog, error)

ParseCatalog validates and returns a curated list from JSON.

func (Catalog) Find

func (c Catalog) Find(id string) (CatalogEntry, bool)

Find returns the entry with id.

func (Catalog) FindRepo

func (c Catalog) FindRepo(repo, quant string) (CatalogEntry, bool)

FindRepo returns the entry for repo and an optional quant suffix.

func (Catalog) FindWeights

func (c Catalog) FindWeights(repo, file string) (CatalogEntry, bool)

FindWeights returns the entry serving repo and file.

func (Catalog) Sorted

func (c Catalog) Sorted() []CatalogEntry

Sorted returns the entries ordered by tier then size.

type CatalogCard

type CatalogCard struct {
	CatalogEntry
	Fit CPUFit `json:"fit"`
}

CatalogCard is a curated entry with its estimate on a node.

type CatalogEntry

type CatalogEntry struct {
	ID            string  `json:"id"`
	Label         string  `json:"label"`
	Vendor        string  `json:"vendor"`
	Repo          string  `json:"repo"`
	File          string  `json:"file"`
	ParamsB       float64 `json:"params_b"`
	Quant         string  `json:"quant"`
	DownloadBytes int64   `json:"download_bytes"`
	SHA256        string  `json:"sha256"`
	MinRAMMiB     int     `json:"min_ram_mib"`
	ContextLength int     `json:"context_length"`
	License       string  `json:"license"`
	Tier          string  `json:"tier"`
	Kind          string  `json:"kind"`
	ToolCalling   bool    `json:"tool_calling"`
	Notes         string  `json:"notes"`
}

CatalogEntry is one curated local model. Weights are never shipped by Levelrail: the user's server downloads them from Hugging Face on the user's action.

func (CatalogEntry) Ref

func (e CatalogEntry) Ref() string

Ref is the model reference stored on a resource for this entry.

type CatalogView

type CatalogView struct {
	Version    int           `json:"version"`
	VerifiedOn string        `json:"verified_on"`
	Note       string        `json:"note"`
	NodeID     string        `json:"node_id"`
	HostKnown  bool          `json:"host_known"`
	HostCPUs   int           `json:"host_cpus"`
	HostMemory int64         `json:"host_memory_bytes"`
	Bounds     CPUBounds     `json:"bounds"`
	Models     []CatalogCard `json:"models"`
}

CatalogView is the curated list rated for a node.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller converges one model row to a running engine container.

func New

func New(name string, st Store, nodes Nodes, rt docker.Runtime, prober Prober, opts ...Option) *Controller

New builds the Controller for model name.

func (*Controller) Name

func (c *Controller) Name() string

Name implements reconcile.Controller.

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context) (reconcile.Result, error)

Reconcile implements reconcile.Controller.

type CreateInput

type CreateInput struct {
	Spec    Spec
	NodeID  string
	Domain  string
	HFToken string
	// Residency is "always" (default) or "on_demand". IdleTTL 0 uses the
	// platform default.
	Residency string
	IdleTTL   time.Duration
	// SwapGroup is empty (no group) or a name shared by other models on
	// the same node/GPU; see store.Model.SwapGroup.
	SwapGroup string
	// Compute is "" or ComputeGPU (default) or ComputeCPU. CatalogID picks a
	// curated local model and implies ComputeCPU.
	Compute   string
	CatalogID string
	// CPUMilli and MemoryMiB are the CPU model caps, 0 for the defaults.
	CPUMilli  int
	MemoryMiB int
	// WeightsFile names the GGUF file of a custom repository.
	WeightsFile string
	// LicenseAck acknowledges the licence notice of a non-curated repository.
	LicenseAck bool
	// External registers a server Levelrail does not run; Spec.Name is the
	// only other field read.
	External *ExternalInput
}

CreateInput is a request to deploy a model.

type CreateKeyInput

type CreateKeyInput struct {
	Name      string
	CreatedBy string
	ExpiresAt *time.Time
	Limits    KeyLimits
}

CreateKeyInput is a request for a new virtual key.

type Created

type Created struct {
	Model  store.Model
	APIKey string
}

Created is the result of Create; APIKey is the plaintext, shown once.

type CreatedKey

type CreatedKey struct {
	KeyView
	Plaintext string
}

CreatedKey is a new key; Plaintext is shown once and never stored.

type CredentialReader

type CredentialReader interface {
	Resolve(ctx context.Context, serviceName, envKey string) (string, error)
}

CredentialReader resolves an endpoint credential from the secrets manager.

type CredentialStore

type CredentialStore interface {
	SetValue(ctx context.Context, serviceName, envKey, plaintext string) error
	Resolve(ctx context.Context, serviceName, envKey string) (string, error)
	DeleteAll(ctx context.Context, serviceName string) error
}

CredentialStore reads and writes an endpoint credential in the secrets manager.

type DiskFactsFunc

type DiskFactsFunc func(ctx context.Context, nodeID string) (free, total int64, ok bool)

DiskFactsFunc reports free and total bytes of the disk holding a node's model cache. nodeID is "" for the control plane host. ok is false when the disk cannot be measured.

type DownloadConfig

type DownloadConfig struct {
	Root     string
	BaseURL  string
	MaxBytes int64
	// HeadroomPercent is free disk required beyond the remaining bytes.
	HeadroomPercent int
	RetryAfter      time.Duration
	// BlockedRetryAfter spaces retries of failures a retry will not fix soon.
	BlockedRetryAfter time.Duration
	// HostAllowed overrides the Hugging Face host policy (tests).
	HostAllowed func(host string) bool
	Client      *http.Client
	DiskFree    func(path string) (int64, error)
	Now         func() time.Time
}

DownloadConfig tunes the downloader. Zero fields take the defaults.

func LoadDownloadConfig

func LoadDownloadConfig() DownloadConfig

LoadDownloadConfig reads APP_MODEL_WEIGHTS_DIR, APP_MODEL_DOWNLOAD_MAX_BYTES, APP_MODEL_DOWNLOAD_RETRY_SECONDS and reuses APP_HF_BASE_URL and APP_DATA_DIR.

type DownloadError

type DownloadError struct {
	Code      string
	Message   string
	Retryable bool
}

DownloadError is a classified download failure.

func (*DownloadError) Error

func (e *DownloadError) Error() string

type DownloadState

type DownloadState struct {
	Phase string
	Done  int64
	Total int64
	Err   *DownloadError
}

DownloadState is the observable state of one weights download.

type Downloader

type Downloader struct {
	// contains filtered or unexported fields
}

Downloader fetches GGUF weights from Hugging Face into per-model directories, in the background, with resume and checksum verification.

func NewDownloader

func NewDownloader(cfg DownloadConfig, logger *slog.Logger, progress func(name string, done, total int64)) *Downloader

NewDownloader builds a Downloader. progress may be nil; it is called with throttled byte counts.

func (*Downloader) Dir

func (d *Downloader) Dir(name string) string

Dir is the host directory holding name's weights.

func (*Downloader) Ensure

func (d *Downloader) Ensure(spec WeightsSpec) DownloadState

Ensure returns the download state for spec, starting or restarting the background job when needed. It never blocks on the network.

func (*Downloader) Forget

func (d *Downloader) Forget(name string)

Forget cancels name's job and drops its state. Files are kept.

type EndpointChecker

type EndpointChecker interface {
	Probe(ctx context.Context, baseURL, apiType, credential string) EndpointProbe
}

EndpointChecker calls an endpoint's list-models route.

type EndpointPlumbing

type EndpointPlumbing struct {
	Store       EndpointStore
	Credentials CredentialStore
	Checker     EndpointChecker
	Lookup      HostLookup
}

EndpointPlumbing wires external endpoint support into a Service.

type EndpointProbe

type EndpointProbe struct {
	State   string
	Latency time.Duration
	Models  []string
	// Code is empty on success; Message is operator-safe text without secrets.
	Code    string
	Message string
	Status  int
}

EndpointProbe is the outcome of one list-models call against an endpoint.

func (EndpointProbe) ToHealth

func (r EndpointProbe) ToHealth(at time.Time) store.EndpointHealth

ToHealth converts a probe into the stored health record.

type EndpointProber

type EndpointProber struct {
	// contains filtered or unexported fields
}

EndpointProber is the production EndpointChecker, built on the guarded transport.

func NewEndpointProber

func NewEndpointProber(slow time.Duration) *EndpointProber

NewEndpointProber builds a prober; slow is the latency above which a working endpoint is reported as slow.

func (*EndpointProber) Probe

func (p *EndpointProber) Probe(ctx context.Context, baseURL, apiType, credential string) EndpointProbe

Probe implements EndpointChecker.

type EndpointStore

type EndpointStore interface {
	SaveInferenceEndpoint(ctx context.Context, m store.Model, e store.InferenceEndpoint) error
	GetInferenceEndpoint(ctx context.Context, name string) (*store.InferenceEndpoint, error)
	ListInferenceEndpoints(ctx context.Context) ([]store.InferenceEndpoint, error)
	SetInferenceEndpointRouting(ctx context.Context, name, fallback, fallbackRef string, budget time.Duration) error
	SetInferenceEndpointCredential(ctx context.Context, name string, set bool) error
	RecordInferenceEndpointHealth(ctx context.Context, name string, h store.EndpointHealth) error
	DeleteModel(ctx context.Context, name string) error
}

EndpointStore is the store surface external endpoints need. *store.DB satisfies it.

type EndpointView

type EndpointView struct {
	store.InferenceEndpoint
	Ready bool
}

EndpointView is an external endpoint as the API reports it.

type Engine

type Engine struct {
	Name         string
	DefaultImage string
	Port         int
	// CachePath is where the engine keeps downloaded weights inside the
	// container; it is backed by a persistent volume.
	CachePath string
	// RefHelp explains the model reference format for error messages.
	RefHelp string
	// contains filtered or unexported fields
}

Engine describes how one inference engine runs as a container.

func EngineFor

func EngineFor(name string) (Engine, bool)

EngineFor returns the named engine.

type EngineHealth

type EngineHealth struct {
	State   string   `json:"state"`
	Summary string   `json:"summary"`
	Reasons []string `json:"reasons"`
}

EngineHealth is a one-line reading of the latest samples.

type EngineMetricPoint

type EngineMetricPoint struct {
	T time.Time `json:"t"`
	V float64   `json:"v"`
}

EngineMetricPoint is one stored reading.

type EngineMetricSeries

type EngineMetricSeries struct {
	ID        string              `json:"id"`
	Label     string              `json:"label"`
	Unit      string              `json:"unit"`
	Supported bool                `json:"supported"`
	Latest    *float64            `json:"latest"`
	Points    []EngineMetricPoint `json:"points"`
}

EngineMetricSeries is one metric over the window. Supported is false when the model's engine cannot expose it.

type EngineMetricsCollector

type EngineMetricsCollector struct {
	// contains filtered or unexported fields
}

EngineMetricsCollector scrapes each running engine's metrics endpoint and writes the readings to the telemetry store. It reaches engines the same way the readiness prober does.

func NewEngineMetricsCollector

func NewEngineMetricsCollector(st EngineMetricsStore, sink SampleWriter, client *http.Client, logger *slog.Logger) *EngineMetricsCollector

NewEngineMetricsCollector builds a collector. client may be nil.

func (*EngineMetricsCollector) Collect

func (c *EngineMetricsCollector) Collect(ctx context.Context, now time.Time)

Collect scrapes every model once and writes the resulting samples.

func (*EngineMetricsCollector) Run

func (c *EngineMetricsCollector) Run(ctx context.Context, interval time.Duration)

Run collects every interval until ctx ends.

type EngineMetricsReader

type EngineMetricsReader interface {
	Query(ctx context.Context, resourceID, metric string, from, to time.Time) ([]telemetry.Sample, error)
}

EngineMetricsReader reads stored samples. *telemetry.DB satisfies it.

type EngineMetricsReport

type EngineMetricsReport struct {
	Model      string               `json:"model"`
	Engine     string               `json:"engine"`
	From       time.Time            `json:"from"`
	To         time.Time            `json:"to"`
	Collecting bool                 `json:"collecting"`
	Note       string               `json:"note"`
	Health     EngineHealth         `json:"health"`
	Series     []EngineMetricSeries `json:"series"`
}

EngineMetricsReport is a model's engine metrics over a window.

type EngineMetricsStore

type EngineMetricsStore interface {
	ListModels(ctx context.Context) ([]store.Model, error)
}

EngineMetricsStore is the model listing the collector needs.

type ExternalInput

type ExternalInput struct {
	BaseURL    string
	APIType    string
	Credential string
	// FallbackModel is empty to leave the routing policy off.
	FallbackModel string
	FallbackRef   string
	LatencyBudget time.Duration
}

ExternalInput registers an external endpoint through Create.

type ExternalSource

type ExternalSource interface {
	ListInferenceEndpoints(ctx context.Context) ([]store.InferenceEndpoint, error)
	AddInferenceEndpointFallback(ctx context.Context, name string) error
}

ExternalSource is the store surface the gateway needs for external endpoints.

type FitConfig

type FitConfig struct {
	// OverheadPercent is added to weight bytes for KV cache and buffers.
	OverheadPercent float64
	// FitPercent is the share of free VRAM a model may use to count as
	// "fits"; above it (up to 100%) it is "tight".
	FitPercent float64
	// DiskHeadroomPercent is extra free disk required beyond the download.
	DiskHeadroomPercent float64
}

FitConfig holds the estimation knobs.

func LoadFitConfig

func LoadFitConfig() FitConfig

LoadFitConfig reads APP_MODEL_FIT_OVERHEAD_PERCENT, APP_MODEL_FIT_PERCENT and APP_MODEL_DISK_HEADROOM_PERCENT.

func (FitConfig) Check

func (c FitConfig) Check(p FitParams, in FitInput) FitDetail

Check estimates whether in fits in its GPUs' free VRAM.

func (FitConfig) DiskOK

func (c FitConfig) DiskOK(bytes, freeDisk int64) bool

DiskOK reports whether downloading bytes leaves the configured headroom. freeDisk < 0 means unknown, which counts as OK (the caller reports it).

func (FitConfig) FitVerdict

func (c FitConfig) FitVerdict(weightBytes, freeVRAMBytes int64) string

FitVerdict judges weightBytes against free VRAM. freeVRAMBytes < 0 means unknown.

func (FitConfig) MarkFits

func (c FitConfig) MarkFits(quants []Quant, freeVRAMBytes, freeDiskBytes int64) (name, reason string)

MarkFits sets Fit on every quant and Recommended on the best one, and returns the recommended name with a one-line reason. It picks the largest quantized variant that fits VRAM and disk, then the largest that is tight. With no VRAM facts it falls back to the conventional default.

type FitDetail

type FitDetail struct {
	Verdict        string   `json:"verdict"`
	WeightsSource  string   `json:"weights_source"`
	WeightsBytes   int64    `json:"weights_bytes"`
	KVBytes        int64    `json:"kv_bytes"`
	OverheadBytes  int64    `json:"overhead_bytes"`
	NeedBytes      int64    `json:"need_bytes"`
	FreeBytes      int64    `json:"free_bytes"`
	ContextTokens  int      `json:"context_tokens"`
	ContextAssumed bool     `json:"context_assumed"`
	Arithmetic     string   `json:"arithmetic"`
	Reason         string   `json:"reason,omitempty"`
	Suggestions    []string `json:"suggestions"`
}

FitDetail is the arithmetic behind a verdict.

type FitInput

type FitInput struct {
	Engine        string
	ModelRef      string
	Quantization  string
	ContextLength int
	// WeightsBytes is the exact download size when known; 0 means estimate.
	WeightsBytes int64
	// GPUs is how many GPUs the model spreads over.
	GPUs int
	// FreeBytes is the total free VRAM across those GPUs; MinFreeBytes and
	// MinTotalBytes describe the tightest single GPU.
	FreeBytes     int64
	MinFreeBytes  int64
	MinTotalBytes int64
}

FitInput describes one model against one set of GPUs.

type FitParams

type FitParams struct {
	// GPUOverheadMiB is reserved per GPU for the CUDA context and buffers.
	GPUOverheadMiB int64
	// VLLMExtraMiB is added per GPU for vLLM's CUDA graphs and torch context.
	VLLMExtraMiB int64
	// DefaultContext is assumed when a model sets no context length.
	DefaultContext int
	// VLLMUtilization is the share of each GPU vLLM pre-allocates.
	VLLMUtilization float64
	// KVKiBPerToken overrides the parameter-count heuristic when positive.
	KVKiBPerToken float64
}

FitParams are the VRAM estimation knobs, all environment driven.

func LoadFitParams

func LoadFitParams() FitParams

LoadFitParams reads APP_MODEL_FIT_GPU_OVERHEAD_MIB, APP_MODEL_FIT_VLLM_EXTRA_MIB, APP_MODEL_FIT_DEFAULT_CONTEXT, APP_MODEL_VLLM_GPU_UTILIZATION and APP_MODEL_FIT_KV_KIB_PER_TOKEN.

type FitReport

type FitReport struct {
	Model string    `json:"model,omitempty"`
	Nodes []NodeFit `json:"nodes"`
	Note  string    `json:"note"`
}

FitReport ranks nodes for a model, best first.

type FitRequest

type FitRequest struct {
	Engine        string
	ModelRef      string
	Quantization  string
	ContextLength int
	GPUCount      int
	GPUDeviceIDs  []string
	// WeightsBytes is the exact size from a preflight, 0 to estimate.
	WeightsBytes int64
	// NodeID limits the check to one node; nil checks every GPU node.
	NodeID *string
}

FitRequest asks whether a model fits on GPU nodes.

type GPUNode

type GPUNode struct {
	NodeID     string
	Name       string
	IsLocal    bool
	Info       gpu.Info
	UpdatedAt  time.Time
	ModelCount int
	// PlacementID is the node ID as services and models record it: "" for
	// the control plane's own host.
	PlacementID string
	Schedulable bool
	Online      bool
	Claims      []gpu.Claim
}

GPUNode is one node's GPU snapshot plus the models placed on it.

func (GPUNode) Eligible

func (n GPUNode) Eligible() bool

Eligible reports whether new workloads may be placed on the node.

func (GPUNode) Ledger

func (n GPUNode) Ledger(exclude string) gpu.Ledger

Ledger returns the node's reservations, leaving out the claim named exclude so a workload can be re-checked against its own node.

type Gateway

type Gateway struct {
	// contains filtered or unexported fields
}

Gateway authenticates OpenAI-compatible requests addressed to a model's host with one of the model's virtual API keys and reverse proxies them to the engine, enforcing the key's limits and metering its usage. Only an allowlist of inference and listing routes is forwarded, so engine admin APIs (Ollama pull and delete, vLLM LoRA loading) are never exposed. Request size, generation length, concurrency and upstream timeouts are bounded by GatewayLimits.

func NewGateway

func NewGateway(st GatewayStore, hosts *HostResolver, logger *slog.Logger) *Gateway

NewGateway builds a Gateway. hosts maps a model to the hostnames it is served on.

func (*Gateway) Handle

func (g *Gateway) Handle(w http.ResponseWriter, r *http.Request) bool

Handle serves r when its Host belongs to a model, returning true. It returns false without touching w for every other host.

func (*Gateway) InFlight

func (g *Gateway) InFlight() map[string]int

InFlight returns the running request count per key id.

func (*Gateway) Invalidate

func (g *Gateway) Invalidate()

Invalidate makes the next request reload models and keys, so a revoked key stops working at once instead of after the cache TTL.

func (*Gateway) Middleware

func (g *Gateway) Middleware(next http.Handler) http.Handler

Middleware wraps next so requests for model hosts are handled by the gateway.

func (*Gateway) SetCredentialReader

func (g *Gateway) SetCredentialReader(r CredentialReader)

SetCredentialReader lets the gateway attach endpoint credentials upstream.

func (*Gateway) SetLimits

func (g *Gateway) SetLimits(l GatewayLimits)

SetLimits replaces the request limits. Call it before serving.

func (*Gateway) SetWakeHook

func (g *Gateway) SetWakeHook(fn func())

SetWakeHook registers a function called (repeatedly, cheaply) while a request waits for a model to wake, typically the reconciler's Nudge.

func (*Gateway) StartMetering

func (g *Gateway) StartMetering(ctx context.Context, st UsageStore)

StartMetering flushes usage to st every flush interval until ctx ends.

type GatewayLimits

type GatewayLimits struct {
	MaxBodyBytes  int64
	MaxN          int
	MaxTokens     int
	MaxInflight   int
	RetryAfter    time.Duration
	DialTimeout   time.Duration
	HeaderTimeout time.Duration
	IdleTimeout   time.Duration
	// WakeWait bounds how long a request to a sleeping on-demand model is
	// held while its engine loads; zero fails fast with Retry-After.
	WakeWait       time.Duration
	WakeRetryAfter time.Duration
	// TouchInterval throttles how often gateway activity is written.
	TouchInterval time.Duration
}

GatewayLimits bounds what one request may cost the engine. The limits are global: they apply to every model.

func DefaultGatewayLimits

func DefaultGatewayLimits() GatewayLimits

DefaultGatewayLimits are the limits used when no environment override is set.

func LoadGatewayLimits

func LoadGatewayLimits() GatewayLimits

LoadGatewayLimits reads the limits from the environment, falling back to the defaults for unset or unparsable values.

func (GatewayLimits) Summary

func (l GatewayLimits) Summary() GatewayLimitsSummary

Summary returns the limits as shown to operators.

type GatewayLimitsSummary

type GatewayLimitsSummary struct {
	MaxBodyBytes           int64 `json:"max_body_bytes"`
	MaxN                   int   `json:"max_n"`
	MaxTokens              int   `json:"max_tokens"`
	MaxInflight            int   `json:"max_inflight_requests"`
	ResponseHeaderTimeoutS int   `json:"response_header_timeout_seconds"`
	StreamIdleTimeoutS     int   `json:"stream_idle_timeout_seconds"`
}

GatewayLimitsSummary is the read-only view of the limits shown on the model resource. A zero value means the limit is disabled.

type GatewayStore

type GatewayStore interface {
	ListModels(ctx context.Context) ([]store.Model, error)
	ListActiveModelKeys(ctx context.Context) ([]store.ModelKey, error)
}

GatewayStore is the store surface the gateway reads.

type HFClient

type HFClient struct {
	// contains filtered or unexported fields
}

HFClient queries the Hub's public metadata API. It refuses internal addresses and never logs or returns the token it is given.

func NewHFClient

func NewHFClient(cfg HFConfig, httpClient *http.Client, logger *slog.Logger) *HFClient

NewHFClient builds a client. httpClient nil uses the SSRF-guarded client.

func (*HFClient) CacheTTL

func (c *HFClient) CacheTTL() time.Duration

CacheTTL is how long Repo answers are reused.

func (*HFClient) Repo

func (c *HFClient) Repo(ctx context.Context, repo, token string) (r *HFRepo, cached bool, err error)

Repo returns the repository's metadata. Errors are *HFError. cached is true when the answer came from the short-lived cache.

type HFConfig

type HFConfig struct {
	BaseURL          string
	Timeout          time.Duration
	CacheTTL         time.Duration
	MaxResponseBytes int64
	CacheEntries     int
}

HFConfig tunes the Hugging Face Hub client.

func LoadHFConfig

func LoadHFConfig() HFConfig

LoadHFConfig reads APP_HF_BASE_URL, APP_HF_TIMEOUT, APP_HF_CACHE_TTL and APP_HF_MAX_RESPONSE_BYTES, falling back to defaults on missing or bad values.

type HFError

type HFError struct {
	Status     string
	Message    string
	RetryAfter time.Duration
}

HFError carries a non-success Hub outcome.

func (*HFError) Error

func (e *HFError) Error() string

type HFFile

type HFFile struct {
	Name  string `json:"name"`
	Bytes int64  `json:"bytes"`
}

HFFile is one file of a Hub repository.

type HFRepo

type HFRepo struct {
	ID      string
	Gated   string
	Private bool
	License string
	Files   []HFFile
	// Access is "granted", "denied" or "unknown" for a gated repo, and
	// "not_required" otherwise.
	Access string
}

HFRepo is the Hub metadata Preflight needs.

type HTTPProber

type HTTPProber struct {
	// contains filtered or unexported fields
}

HTTPProber probes engines over their HTTP API and drives Ollama model pulls in the background so a reconcile pass never blocks on a download.

func NewHTTPProber

func NewHTTPProber() *HTTPProber

NewHTTPProber builds an HTTPProber.

func (*HTTPProber) Probe

func (p *HTTPProber) Probe(ctx context.Context, engine, dial, modelRef string) Status

Probe implements Prober.

type HostFacts

type HostFacts struct {
	CPUs          int
	MemTotalBytes int64
	// MemAvailBytes is currently available memory, 0 when unknown.
	MemAvailBytes int64
}

HostFacts are the node figures CPU limits are derived from. Zero CPUs or MemTotalBytes means the node has not reported them.

func (HostFacts) Known

func (h HostFacts) Known() bool

Known reports whether the node figures are usable.

type HostFactsFunc

type HostFactsFunc func(ctx context.Context, nodeID string) (HostFacts, bool)

HostFactsFunc reports a node's CPUs and memory. ok is false when the node has not reported them. nodeID "" is the control plane host.

type HostLister

type HostLister struct {
	Store GatewayStore
	Hosts *HostResolver
}

HostLister is what the ingress controller needs to route model hosts.

func (HostLister) ModelHosts

func (l HostLister) ModelHosts(ctx context.Context) ([]string, error)

ModelHosts returns every hostname of every live model.

type HostLookup

type HostLookup func(ctx context.Context, host string) ([]netip.Addr, error)

HostLookup resolves a hostname for URL validation; swappable in tests.

type HostResolver

type HostResolver struct {
	// contains filtered or unexported fields
}

HostResolver computes the hostnames a model is served on: its configured domain, or the zero-config fallback derived from the control plane's public host.

func NewHostResolver

func NewHostResolver(publicHost string, fallback func(publicHost, label string) (string, bool)) *HostResolver

NewHostResolver builds a HostResolver. fallback may be nil (no fallback hostnames).

func (*HostResolver) BaseURL

func (h *HostResolver) BaseURL(m store.Model) string

BaseURL returns the OpenAI-compatible base URL for m, or empty when it has no reachable hostname.

func (*HostResolver) Hosts

func (h *HostResolver) Hosts(m store.Model) []string

Hosts returns the hostnames serving m.

type KeyLimits

type KeyLimits struct {
	RPM         int
	TPM         int
	TPD         int
	MaxParallel int
	AllowPaths  []string
	AllowModels []string
}

KeyLimits are the optional per-key limits. Zero means unlimited and empty allow lists mean anything the engine allowlist forwards.

type KeyStatus

type KeyStatus string

KeyStatus describes where a key is in its life.

const (
	KeyActive   KeyStatus = "active"
	KeyRotating KeyStatus = "rotating"
	KeyExpired  KeyStatus = "expired"
	KeyRevoked  KeyStatus = "revoked"
)

Key statuses.

type KeyUsage

type KeyUsage struct {
	KeyID     string `json:"key_id"`
	Name      string `json:"name"`
	KeyPrefix string `json:"key_prefix"`
	Status    string `json:"status"`
	InFlight  int    `json:"in_flight"`
	UsageTotals
}

KeyUsage is one key's share of the window.

type KeyView

type KeyView struct {
	store.ModelKey
	Status   KeyStatus
	InFlight int
}

KeyView is a key without its hash, with its derived status.

type MeterConfig

type MeterConfig struct {
	FlushInterval time.Duration
	BatchSize     int
	MaxBuffered   int
	Retention     time.Duration
	ScanBytes     int
}

MeterConfig bounds usage metering. A non-positive Retention keeps rows forever; a non-positive ScanBytes turns off token parsing.

func DefaultMeterConfig

func DefaultMeterConfig() MeterConfig

DefaultMeterConfig returns the metering defaults.

func LoadMeterConfig

func LoadMeterConfig() MeterConfig

LoadMeterConfig reads the metering config from the environment.

type NodeFit

type NodeFit struct {
	NodeID   string `json:"node_id"`
	Name     string `json:"name"`
	IsLocal  bool   `json:"is_local"`
	Eligible bool   `json:"eligible"`
	// Current marks the node a deployed model already runs on.
	Current    bool  `json:"current"`
	GPUs       int   `json:"gpus"`
	TotalBytes int64 `json:"total_bytes"`
	// ReservedBytes is VRAM estimated for other models placed here that are
	// not loaded yet, already subtracted from free.
	ReservedBytes int64 `json:"reserved_bytes"`
	FitDetail
}

NodeFit is the verdict for one node.

type NodeInfo

type NodeInfo struct {
	GPU gpu.Info
	// BindIP is the address the engine's port is published on.
	BindIP string
	// DialHost is the address the control plane reaches BindIP at. Empty
	// means the node is remote and not on the mesh.
	DialHost string
	// Local is true for the control plane's own host, the only node whose
	// filesystem the control plane can download weights onto.
	Local bool
}

NodeInfo is what the controller needs to know about a model's node.

type Nodes

type Nodes interface {
	NodeInfo(ctx context.Context, nodeID string) (NodeInfo, error)
}

Nodes resolves a model's node. nodeID "" is the local node.

type Option

type Option func(*Controller)

Option configures a Controller.

func WithCPUPolicy

func WithCPUPolicy(p CPUPolicy) Option

WithCPUPolicy overrides the CPU guardrails read from the environment.

func WithClock

func WithClock(now func() time.Time) Option

WithClock overrides the clock used for idle decisions.

func WithContainerPrefix

func WithContainerPrefix(p string) Option

WithContainerPrefix sets the container and volume name prefix (typically brand.ShortName).

func WithImages

func WithImages(images map[string]string) Option

WithImages overrides engine images by engine name.

func WithSecrets

func WithSecrets(s Secrets) Option

WithSecrets enables resolving the model's HuggingFace token and deleting its secrets on teardown. Without it, a model with a token set stays blocked.

func WithWeights

func WithWeights(w Weights) Option

WithWeights enables control plane managed weights downloads for local CPU models. Without it, CPU models let the engine pull the weights.

type Phase

type Phase string

Phase is how far a model engine has got.

const (
	PhaseUnreachable Phase = "unreachable"
	PhaseDownloading Phase = "downloading"
	PhaseLoading     Phase = "loading"
	PhaseReady       Phase = "ready"
	PhaseFailed      Phase = "failed"
)

Model engine phases.

type PreflightDisk

type PreflightDisk struct {
	Status        string `json:"status"`
	RequiredBytes int64  `json:"required_bytes"`
	FreeBytes     *int64 `json:"free_bytes"`
	Message       string `json:"message"`
}

PreflightDisk is the disk check for the selected download.

type PreflightFile

type PreflightFile struct {
	Name  string `json:"name"`
	Bytes int64  `json:"bytes"`
}

PreflightFile is one repository file.

type PreflightInput

type PreflightInput struct {
	// Repo is "owner/name", optionally ":quant", or a huggingface.co URL.
	Repo   string
	Engine string
	File   string
	Quant  string
	NodeID string
	// GPUCount is how many GPUs the model will use; 0 or less means all.
	GPUCount int
	// Token is used for this request only and never stored or logged.
	Token string
}

PreflightInput is a request to check a repository before deploying.

type PreflightNode

type PreflightNode struct {
	NodeID         string `json:"node_id"`
	GPUPresent     bool   `json:"gpu_present"`
	VRAMTotalBytes *int64 `json:"vram_total_bytes"`
	VRAMFreeBytes  *int64 `json:"vram_free_bytes"`
	DiskFreeBytes  *int64 `json:"disk_free_bytes"`
	DiskTotalBytes *int64 `json:"disk_total_bytes"`
}

PreflightNode is the target node's facts. Nil numbers are unknown.

type PreflightResult

type PreflightResult struct {
	Repo               string              `json:"repo"`
	Status             string              `json:"status"`
	Exists             bool                `json:"exists"`
	Message            string              `json:"message"`
	NextStep           string              `json:"next_step,omitempty"`
	RetryAfterSeconds  int                 `json:"retry_after_seconds,omitempty"`
	Gated              string              `json:"gated,omitempty"`
	Access             string              `json:"access,omitempty"`
	Private            bool                `json:"private"`
	License            string              `json:"license,omitempty"`
	TotalBytes         int64               `json:"total_bytes"`
	FileCount          int                 `json:"file_count"`
	Files              []PreflightFile     `json:"files"`
	FilesTruncated     bool                `json:"files_truncated"`
	HasGGUF            bool                `json:"has_gguf"`
	HasSafetensors     bool                `json:"has_safetensors"`
	CompatibleEngines  []string            `json:"compatible_engines"`
	EngineHint         string              `json:"engine_hint"`
	Quants             []Quant             `json:"quants"`
	RecommendedQuant   string              `json:"recommended_quant,omitempty"`
	RecommendationNote string              `json:"recommendation_note,omitempty"`
	Selected           *PreflightSelection `json:"selected,omitempty"`
	Node               PreflightNode       `json:"node"`
	Disk               PreflightDisk       `json:"disk"`
	Warnings           []string            `json:"warnings"`
	EstimateNote       string              `json:"estimate_note"`
	Cached             bool                `json:"cached"`
}

PreflightResult is the outcome of Preflight. It always describes the repository as far as the Hub allowed, with Status saying how far that was.

type PreflightSelection

type PreflightSelection struct {
	Label string `json:"label"`
	Bytes int64  `json:"bytes"`
	Fit   string `json:"fit"`
}

PreflightSelection is what a deploy would download.

type ProbeInput

type ProbeInput struct {
	BaseURL    string
	APIType    string
	Credential string
}

ProbeInput is a test request for an endpoint that may not be saved yet.

type Prober

type Prober interface {
	Probe(ctx context.Context, engine, dial, modelRef string) Status
}

Prober reports whether a running engine has loaded its model.

type Quant

type Quant struct {
	Name        string   `json:"name"`
	Bytes       int64    `json:"bytes"`
	Files       []string `json:"files"`
	Fit         string   `json:"fit"`
	Recommended bool     `json:"recommended"`
}

Quant is one GGUF quantization of a repository: all shards of one variant summed.

func DetectQuants

func DetectQuants(files []HFFile) []Quant

DetectQuants groups GGUF files by quantization, smallest first. Split shards of one variant are summed.

type SampleWriter

type SampleWriter interface {
	WriteSamples(ctx context.Context, samples []telemetry.Sample) error
}

SampleWriter persists telemetry samples.

type SecretWriter

type SecretWriter interface {
	SetValue(ctx context.Context, serviceName, envKey, plaintext string) error
	DeleteAll(ctx context.Context, serviceName string) error
}

SecretWriter stores the HuggingFace token.

type Secrets

type Secrets interface {
	Resolve(ctx context.Context, serviceName, envKey string) (string, error)
	DeleteAll(ctx context.Context, serviceName string) error
}

Secrets is the narrow secrets surface the controller needs.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service implements model management for the API, CLI and MCP surfaces.

func NewService

func NewService(st ServiceStore, secrets SecretWriter, hosts *HostResolver, localNodeID string) *Service

NewService builds a Service. secrets may be nil (HuggingFace tokens are then rejected). localNodeID identifies the control plane's own node so its GPU snapshot is found under the local key.

func (*Service) Benchmark

func (s *Service) Benchmark(ctx context.Context, name string) (BenchResult, error)

Benchmark runs the fixed prompt set through the running model, stores the result and returns it. It never wakes a model.

func (*Service) BenchmarkEnabled

func (s *Service) BenchmarkEnabled() bool

BenchmarkEnabled reports whether Benchmark can run.

func (*Service) CPUFitCheck

func (s *Service) CPUFitCheck(ctx context.Context, req CPUFitRequest) (CPUFitReport, error)

CPUFitCheck rates a model in CPU mode on a node.

func (*Service) CacheEnabled

func (s *Service) CacheEnabled() bool

CacheEnabled reports whether the cache manager is available.

func (*Service) CacheList

func (s *Service) CacheList(ctx context.Context) (CacheReport, error)

CacheList reports model weight volumes with size, last use and whether each is safe to prune.

func (*Service) CachePrune

func (s *Service) CachePrune(ctx context.Context, volumes []string, dryRun bool) (CachePruneResult, error)

CachePrune removes prunable volumes: not mounted, not owned by any configured model, and unused for CacheUnusedDays. volumes narrows the candidates; empty means all. With dryRun nothing is removed.

func (*Service) Create

func (s *Service) Create(ctx context.Context, in CreateInput) (Created, error)

Create validates and stores a new model, returning its one-time API key.

func (*Service) CreateKey

func (s *Service) CreateKey(ctx context.Context, model string, in CreateKeyInput) (CreatedKey, error)

CreateKey adds a named key to a model and returns its plaintext once.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, name string) error

Delete tombstones the model; its controller removes the container and row.

func (*Service) EngineMetrics

func (s *Service) EngineMetrics(ctx context.Context, name string, window time.Duration) (EngineMetricsReport, error)

EngineMetrics returns the model's engine metrics over window.

func (*Service) FitCheck

func (s *Service) FitCheck(ctx context.Context, req FitRequest) (FitReport, error)

FitCheck rates a model against GPU nodes.

func (*Service) GPUNodes

func (s *Service) GPUNodes(ctx context.Context) ([]GPUNode, error)

GPUNodes lists every node that has reported a GPU snapshot, the local host first.

func (*Service) Get

func (s *Service) Get(ctx context.Context, name string) (View, error)

Get returns one model with status.

func (*Service) GetEndpoint

func (s *Service) GetEndpoint(ctx context.Context, name string) (EndpointView, error)

GetEndpoint returns one endpoint with its health.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]View, error)

List returns every model with status.

func (*Service) ListEndpoints

func (s *Service) ListEndpoints(ctx context.Context) (map[string]EndpointView, error)

ListEndpoints returns every endpoint keyed by model name.

func (*Service) ListKeys

func (s *Service) ListKeys(ctx context.Context, model string) ([]KeyView, error)

ListKeys returns every key of a model, revoked ones included.

func (*Service) LocalCatalogView

func (s *Service) LocalCatalogView(ctx context.Context, nodeID string) (CatalogView, error)

LocalCatalogView returns the curated list with a default-caps fit for each entry on nodeID.

func (*Service) ModelFit

func (s *Service) ModelFit(ctx context.Context, name string) (FitReport, error)

ModelFit rates a deployed model against every GPU node, marking its own.

func (*Service) NodeGPU

func (s *Service) NodeGPU(ctx context.Context, nodeID string) (info gpu.Info, known bool, err error)

NodeGPU returns the GPU snapshot of nodeID ("" or the local node ID is the control plane's host). known is false when the node has not reported yet.

func (*Service) Preflight

func (s *Service) Preflight(ctx context.Context, in PreflightInput) (PreflightResult, error)

Preflight checks a Hugging Face repository against a node before a model is created. Hub failures come back as a Status, not an error.

func (*Service) PreflightEnabled

func (s *Service) PreflightEnabled() bool

PreflightEnabled reports whether Preflight can run.

func (*Service) ProbeAll

func (s *Service) ProbeAll(ctx context.Context)

ProbeAll re-probes every endpoint once.

func (*Service) Restart

func (s *Service) Restart(ctx context.Context, name string) error

Restart recreates the model's container.

func (*Service) RevokeKey

func (s *Service) RevokeKey(ctx context.Context, model, id string) error

RevokeKey stops a key from working at once.

func (*Service) RotateKey

func (s *Service) RotateKey(ctx context.Context, name string) (string, error)

RotateKey replaces the model's "default" key at once, with no grace.

func (*Service) RotateKeyByID

func (s *Service) RotateKeyByID(ctx context.Context, model, id, actor string, grace *time.Duration) (CreatedKey, error)

RotateKeyByID issues a replacement for a key with the same name, limits and expiry. The old key keeps working for grace (KeyRotationGrace when nil, no grace when zero) and is then dead.

func (*Service) RunEndpointHealth

func (s *Service) RunEndpointHealth(ctx context.Context, interval time.Duration)

RunEndpointHealth probes every endpoint each interval until ctx ends.

func (*Service) SetBenchmark

func (s *Service) SetBenchmark(cfg BenchConfig, client *http.Client, stats BenchStatsFunc)

SetBenchmark enables the benchmark. stats may be nil (memory then reads 0).

func (*Service) SetCPUPolicy

func (s *Service) SetCPUPolicy(p CPUPolicy)

SetCPUPolicy overrides the CPU guardrails read from the environment.

func (*Service) SetCacheBackend

func (s *Service) SetCacheBackend(b CacheBackend, prefix string)

SetCacheBackend enables the cache manager. prefix is the container and volume name prefix the model controller uses.

func (*Service) SetDiskFacts

func (s *Service) SetDiskFacts(fn DiskFactsFunc)

SetDiskFacts registers the source of node disk facts.

func (*Service) SetEndpointCredential

func (s *Service) SetEndpointCredential(ctx context.Context, name, credential string) (EndpointProbe, error)

SetEndpointCredential stores a new credential and re-probes. An empty credential removes it.

func (*Service) SetEndpointRouting

func (s *Service) SetEndpointRouting(ctx context.Context, name, fallback, fallbackRef string, budget time.Duration) error

SetEndpointRouting sets or clears the fallback policy; an empty fallback turns it off.

func (*Service) SetEndpoints

func (s *Service) SetEndpoints(p EndpointPlumbing)

SetEndpoints enables external endpoints on the service.

func (*Service) SetEngineMetricsReader

func (s *Service) SetEngineMetricsReader(r EngineMetricsReader)

SetEngineMetricsReader enables EngineMetrics. Call once at startup.

func (*Service) SetHFToken

func (s *Service) SetHFToken(ctx context.Context, name, token string) error

SetHFToken stores a new HuggingFace token and restarts the model so it takes effect.

func (*Service) SetHostFacts

func (s *Service) SetHostFacts(fn HostFactsFunc)

SetHostFacts registers the source of node CPU and memory facts.

func (*Service) SetHuggingFace

func (s *Service) SetHuggingFace(c *HFClient, fit FitConfig)

SetHuggingFace enables Preflight. Call once at startup.

func (*Service) SetKeyChangeHook

func (s *Service) SetKeyChangeHook(fn func())

SetKeyChangeHook registers fn to run after any key is created, revoked or rotated, so the gateway can drop its cached key list.

func (*Service) SetLiveStats

func (s *Service) SetLiveStats(fn func() map[string]int)

SetLiveStats registers a source of running request counts per key id.

func (*Service) SetLocalNodeID

func (s *Service) SetLocalNodeID(id string)

SetLocalNodeID tells the service which node ID is the control plane's own host. Call once at startup before serving requests.

func (*Service) SetResidency

func (s *Service) SetResidency(ctx context.Context, name, residency string, idleTTL time.Duration) error

SetResidency changes a model's residency mode and idle TTL (0 keeps the platform default). Switching to on-demand counts as activity.

func (*Service) SetSwapGroup

func (s *Service) SetSwapGroup(ctx context.Context, name, group string) error

SetSwapGroup changes a model's swap group. Empty clears it.

func (*Service) Sleep

func (s *Service) Sleep(ctx context.Context, name string) error

Sleep marks an on-demand model idle so its engine stops on the next reconcile pass.

func (*Service) TestEndpoint

func (s *Service) TestEndpoint(ctx context.Context, name string) (EndpointProbe, error)

TestEndpoint re-probes a saved endpoint, records the result and returns it.

func (*Service) TestEndpointInput

func (s *Service) TestEndpointInput(ctx context.Context, in ProbeInput) (EndpointProbe, error)

TestEndpointInput probes an endpoint that is not saved yet.

func (*Service) UnplacedWorkloads

func (s *Service) UnplacedWorkloads(ctx context.Context) ([]Unplaced, error)

UnplacedWorkloads lists GPU apps and models whose own node cannot serve them and for which no other eligible GPU node has enough free GPUs.

func (*Service) Usage

func (s *Service) Usage(ctx context.Context, model string, window time.Duration) (UsageReport, error)

Usage reports a model's usage over the last window, hourly and per key.

func (*Service) Wake

func (s *Service) Wake(ctx context.Context, name string) error

Wake marks an on-demand model active so its engine starts now.

type ServiceStore

type ServiceStore interface {
	SaveModel(ctx context.Context, m store.Model) error
	GetModel(ctx context.Context, name string) (*store.Model, error)
	ListModels(ctx context.Context) ([]store.Model, error)
	DeleteModel(ctx context.Context, name string) error
	MarkModelDeleting(ctx context.Context, name string) error
	RotateModelAPIKey(ctx context.Context, name, hash, prefix string) error
	ListModelKeys(ctx context.Context, model string) ([]store.ModelKey, error)
	GetModelKey(ctx context.Context, model, id string) (*store.ModelKey, error)
	CreateModelKey(ctx context.Context, k store.ModelKey) error
	RevokeModelKey(ctx context.Context, model, id string, now time.Time) error
	RotateModelKey(ctx context.Context, model, oldID string, next store.ModelKey, graceUntil *time.Time, now time.Time) error
	ListModelUsage(ctx context.Context, model string, from, to time.Time) ([]store.ModelUsage, error)
	RestartModel(ctx context.Context, name string) error
	SetModelBenchmark(ctx context.Context, name, resultJSON string) error
	SetModelHFTokenSet(ctx context.Context, name string, set bool) error
	SetModelResidency(ctx context.Context, name, residency string, idleTTLSeconds int, now time.Time) error
	TouchModel(ctx context.Context, name string, at time.Time) error
	SleepModel(ctx context.Context, name string) error
	SetModelSwapGroup(ctx context.Context, name, group string) error
	ListModelsInSwapGroup(ctx context.Context, group string) ([]store.Model, error)
	GetConditions(ctx context.Context, controllerName string) ([]reconcile.Condition, error)
	GetConditionsForControllers(ctx context.Context, controllerNames []string) (map[string][]reconcile.Condition, error)
	GetNode(ctx context.Context, id string) (*store.Node, error)
	GetNodeGPU(ctx context.Context, nodeID string) (store.NodeGPU, bool, error)
	ListNodes(ctx context.Context) ([]store.Node, error)
	ListNodeGPUs(ctx context.Context) (map[string]store.NodeGPU, error)
	ListDesiredServices(ctx context.Context) ([]store.DesiredService, error)
}

ServiceStore is the store surface Service uses. *store.DB satisfies it.

type Spec

type Spec struct {
	Name          string
	Engine        string
	ModelRef      string
	GPUCount      int
	GPUDeviceIDs  []string
	ContextLength int
	Quantization  string
	// Compute is "" or ComputeGPU (default) or ComputeCPU.
	Compute string
}

Spec is the validated user input for a model.

func SpecFromModel

func SpecFromModel(m *store.Model) Spec

SpecFromModel converts a stored model into its Spec.

func (Spec) Validate

func (s Spec) Validate() error

Validate checks s against its engine's rules.

type Status

type Status struct {
	Phase  Phase
	Detail string
}

Status is one probe result.

type Store

type Store interface {
	GetModel(ctx context.Context, name string) (*store.Model, error)
	SetModelEndpoint(ctx context.Context, name, dial string) error
	SetModelResidencyState(ctx context.Context, name, state string) error
	DeleteModel(ctx context.Context, name string) error
	// ListModelsInSwapGroup backs swap group eviction (residency.go's
	// waitForGPUWithSwap): finding a resident sibling to stop before
	// waking a model that would otherwise not fit.
	ListModelsInSwapGroup(ctx context.Context, group string) ([]store.Model, error)
}

Store is the narrow store surface the controller needs.

type Unplaced

type Unplaced struct {
	Kind   string
	Name   string
	NodeID string
	Reason string
}

Unplaced is a GPU workload no reported node can host right now.

type UsagePoint

type UsagePoint struct {
	Hour time.Time `json:"hour"`
	UsageTotals
}

UsagePoint is one hour of usage across all keys.

type UsageReport

type UsageReport struct {
	Model    string       `json:"model"`
	From     time.Time    `json:"from"`
	To       time.Time    `json:"to"`
	Totals   UsageTotals  `json:"totals"`
	Series   []UsagePoint `json:"series"`
	Keys     []KeyUsage   `json:"keys"`
	InFlight int          `json:"in_flight"`
	Note     string       `json:"note"`
}

UsageReport is a model's gateway usage over a window.

type UsageStore

type UsageStore interface {
	AddModelUsage(ctx context.Context, rows []store.ModelUsage) error
	TouchModelKeys(ctx context.Context, used map[string]time.Time) error
	PruneModelUsage(ctx context.Context, before time.Time) (int64, error)
}

UsageStore is the store surface the meter flushes to.

type UsageTotals

type UsageTotals struct {
	Requests      int64 `json:"requests"`
	Status2xx     int64 `json:"status_2xx"`
	Status4xx     int64 `json:"status_4xx"`
	Status5xx     int64 `json:"status_5xx"`
	RateLimited   int64 `json:"rate_limited"`
	UsageRequests int64 `json:"usage_requests"`
	InputTokens   int64 `json:"input_tokens"`
	OutputTokens  int64 `json:"output_tokens"`
	BytesOut      int64 `json:"bytes_out"`
	AvgDurationMs int64 `json:"avg_duration_ms"`
	AvgTTFTMs     int64 `json:"avg_ttft_ms"`
	// contains filtered or unexported fields
}

UsageTotals sums gateway usage over a set of hourly rows.

type View

type View struct {
	Model   store.Model
	Ready   bool
	Reason  string
	Message string
	BaseURL string
	// SharesGPUWith is every other model in the same non-empty
	// SwapGroup on the same node, excluding this one.
	SharesGPUWith []string
	// Endpoint is set for external models.
	Endpoint *EndpointView
}

View is a model with its reconcile status and endpoint.

type WakeStore

type WakeStore interface {
	GetModel(ctx context.Context, name string) (*store.Model, error)
	TouchModel(ctx context.Context, name string, at time.Time) error
}

WakeStore is the optional store surface that lets the gateway wake and keep alive on-demand models. *store.DB satisfies it; a store without it leaves on-demand models unreachable while asleep.

type Weights

type Weights interface {
	Ensure(spec WeightsSpec) DownloadState
	Dir(name string) string
	Forget(name string)
}

Weights is the control plane managed weights downloader the controller drives for local CPU models.

type WeightsSpec

type WeightsSpec struct {
	Name string
	Repo string
	File string
	// SHA256 is the expected digest; empty falls back to the digest the
	// Hub reports on the response (X-Linked-Etag), and to none for a file
	// the Hub gives no digest for.
	SHA256 string
	Token  string
	// Key changes when the download should be retried from scratch, for
	// example after a new token or a restart.
	Key string
}

WeightsSpec names one file to fetch into a model's weights directory.

Jump to

Keyboard shortcuts

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