runtime

package
v0.1.3 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: 10 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 runtime defines the inference Runtime interface (SPEC §A1.3) and its adapters. llama.cpp is supervised as a subprocess (never cgo); the mock runtime backs tests and --standalone demos.

Index

Constants

View Source
const MockRuntimeBuildID = "mock-runtime-v1"

MockRuntimeBuildID identifies the in-process mock as a runtime build. It is deliberately distinct from any real llama.cpp build id so that fingerprint expected outputs generated against a mock can never be mistaken for a reference for real hardware (SPEC §2.2).

Variables

View Source
var ErrNotLoaded = errors.New("runtime: model not loaded")

ErrNotLoaded is returned when an Instance is used after Shutdown or before the backing process is ready.

Functions

This section is empty.

Types

type BuildIdentified

type BuildIdentified interface {
	RuntimeBuildID() string
}

BuildIdentified is implemented by runtime instances that know which runtime build they are running. The daemon reports this in its CapabilityProfile; it is one third of the fingerprint trust tuple (model_sha, quant, runtime_build_id) — SPEC §2.2, §A2.5.

type Chunk

type Chunk struct {
	Delta        string
	TokenCount   int
	Done         bool
	FinishReason string // "stop", "length", "cancelled", "error"
	Usage        *Usage
	Embeddings   [][]float32
	Err          string
}

Chunk is one streamed unit. For KindEmbedding a single final chunk carries Embeddings. Usage is set on the final chunk.

type CompletionRequest

type CompletionRequest struct {
	ID             string
	Model          string // requested model id ("" = node default)
	Kind           Kind
	Messages       []Message // KindChat
	Prompt         string    // KindCompletion
	EmbeddingInput []string  // KindEmbedding
	Params         GenerationParams
}

type GenerationParams

type GenerationParams struct {
	Seed             uint64
	Temperature      float64
	TopP             float64
	MaxTokens        int
	Stop             []string
	FrequencyPenalty float64
	PresencePenalty  float64
}

GenerationParams: seed is always set upstream so retries and canary comparisons are deterministic for greedy decoding (SPEC §6).

type Instance

type Instance interface {
	Complete(ctx context.Context, req CompletionRequest) (TokenStream, error)
	Health(ctx context.Context) (Stats, error)
	Shutdown(ctx context.Context) error
}

Instance is one loaded model.

type Kind

type Kind int

Kind mirrors typesv1.RequestKind for runtime-local use.

const (
	KindChat Kind = iota + 1
	KindCompletion
	KindEmbedding
)

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type MockRuntime

type MockRuntime struct {
	// TokensPerSec throttles generation; <= 0 means unthrottled.
	TokensPerSec float64
	// FailLoads causes the next N Load calls to fail (supervisor tests).
	FailLoads int
}

MockRuntime is a deterministic in-process runtime used by tests, the fake coordinator path, and `flockd --standalone --runtime=mock`. Same seed -> same output, so it also exercises the fingerprint-challenge flow.

func NewMockRuntime

func NewMockRuntime(tps float64) *MockRuntime

NewMockRuntime returns a mock producing ~tps tokens/second.

func (*MockRuntime) Load

type ModelSpec

type ModelSpec struct {
	ID            string
	Family        string
	Quant         string
	SHA256        string
	Path          string // local GGUF path
	ContextLength int
	Embeddings    bool // model is served for /v1/embeddings
}

ModelSpec identifies a locally available model artifact ready to load. It is derived from the catalog's typesv1.ModelSpec after download+verify.

type ResourceBudget

type ResourceBudget struct {
	MaxVRAMPercent int
	MaxRAMMB       int64
	MaxConcurrent  int
}

ResourceBudget is the operator-configured ceiling passed to Load.

type Runtime

type Runtime interface {
	Load(ctx context.Context, m ModelSpec, res ResourceBudget) (Instance, error)
}

Runtime loads models into serving Instances. Exactly per SPEC §A1.3.

type Stats

type Stats struct {
	Healthy      bool
	ModelID      string
	QueueDepth   int
	TokensPerSec float64
	MemUsedMB    int64
	Restarts     int
}

Stats is the Health snapshot.

type TokenStream

type TokenStream interface {
	Recv() (Chunk, error)
	Close() error
}

TokenStream yields Chunks until io.EOF. Close releases resources early (cancels generation server-side where supported).

func NewChanStream

func NewChanStream(ch <-chan Chunk, cancel context.CancelFunc) TokenStream

NewChanStream builds a TokenStream from a channel; cancel (may be nil) is invoked on Close.

type Usage

type Usage struct {
	PromptTokens     int
	CompletionTokens int
}

func Drain

func Drain(ts TokenStream) (text string, usage Usage, finish string, err error)

Drain reads a stream to completion and concatenates deltas. Convenience for non-streaming callers (localapi non-stream mode, challenges, tests).

Directories

Path Synopsis
Package llamacpp adapts a supervised llama-server subprocess to the runtime.Runtime interface (SPEC §A1.3: subprocess, never cgo).
Package llamacpp adapts a supervised llama-server subprocess to the runtime.Runtime interface (SPEC §A1.3: subprocess, never cgo).

Jump to

Keyboard shortcuts

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