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
- Variables
- func AudioDurationMS(format string, head []byte, size int64, sampleRate int) int
- func AudioMIME(contentType, format string) string
- func EndpointFor(served string) string
- func FamilyOf(inst Instance) string
- func FormatSize(width, height int) string
- func HasImages(msgs []Message) bool
- func IsInvalidInput(err error) bool
- func MediaMIME(format string) string
- func NormalizeReasoningEffort(s string) (effort string, ok bool)
- func PCM16WAV(pcm []byte, sampleRate, channels int) []byte
- func ParseSize(s string) (width, height int, ok bool)
- func SendChunk(ctx context.Context, ch chan<- Chunk, c Chunk) bool
- func SpeechBody(model string, req *SpeechRequest) map[string]any
- func SplitSpeech(text string) []string
- func TakesImages(inst Instance) bool
- func WAVFormat(header []byte) (byteRate, dataOffset int, ok bool)
- type BuildIdentified
- type Chunk
- type CompletionRequest
- type ContentPart
- type DecisionAnswer
- type DecisionInput
- type DecisionOption
- type DecisionProbability
- type DecisionQuestion
- type DecisionType
- type FamilyIdentified
- type GenerationParams
- type Image
- type ImageInputter
- type ImageModel
- type ImageRequest
- type Instance
- type InvalidInputError
- type Kind
- type MediaInfo
- type MediaPiece
- type MediaResult
- type MediaWriter
- type Message
- type MockRuntime
- type ModelFile
- type ModelSpec
- type ModelSupporter
- type Registry
- func (g *Registry) Families() []string
- func (g *Registry) Family(family string) (Runtime, bool)
- func (g *Registry) Load(ctx context.Context, m ModelSpec, res ResourceBudget) (Instance, error)
- func (g *Registry) PrepareRuntime(ctx context.Context, m ModelSpec) error
- func (g *Registry) Register(family string, r Runtime)
- func (g *Registry) SupportsModel(ctx context.Context, m ModelSpec) error
- type ResourceBudget
- type Runtime
- type RuntimePreparer
- type SpeechModel
- type SpeechRequest
- type Stats
- type TokenStream
- type Usage
Constants ¶
const ( ServedChat = "chat" ServedEmbedding = "embedding" ServedDecision = "decision" ServedSpeech = "speech" ServedImage = "image" )
What a model is served for, as the catalog's `kind` and the API spell it.
const ( ReasoningNone = "none" ReasoningLow = "low" ReasoningMedium = "medium" ReasoningHigh = "high" )
Reasoning effort: how much a reasoning model thinks before it answers (GenerationParams.ReasoningEffort; proto design note 2026-11-29-reasoning-effort). The empty string is the model's default.
const FamilyLlamaCpp = "llamacpp"
FamilyLlamaCpp is the runtime family of a model that names none.
const FamilyMock = "mock"
FamilyMock is the family the in-process mock runtime reports: it is not llama.cpp and must never be advertised as if it were.
const MaxAudioBytes = 64 << 20
MaxAudioBytes bounds one speech result: 64 MiB, the bound the mesh puts on a speech file (proto design note 2026-11-30-media-output). The longest input the API takes (4,096 characters) is a few minutes of audio, some tens of megabytes uncompressed; a runtime that sends more is not answering the request, and failing here says so plainly instead of leaving it to the coordinator to fail the dispatch.
const MediaPieceMax = 256 << 10
MediaPieceMax is the largest data piece of a media result: 256 KiB, the size the tunnel's MediaChunk is bounded to, so no message ever holds a whole file.
const MediaProgressInterval = 5 * time.Second
MediaProgressInterval is how often a media request that has produced no data yet reports progress. The contract is "at least every 10 seconds" (it is what tells a coordinator a node generating an image for a minute from a dead one); half of that leaves room for a slow tick.
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).
const SpeechSegmentChars = 300
SpeechSegmentChars is the most code points a segment has (rule 5 aside). A few hundred characters is two or three seconds of work on current hardware: short enough for progress and cancellation to mean something, long enough that the pauses of a paragraph are the model's own rather than the joins'.
Variables ¶
var ErrNoImageInput = errors.New("runtime: the loaded model does not take image input")
ErrNoImageInput is returned for a request that carries an image when the loaded instance cannot take one (no vision projector).
var ErrNoMediaData = errors.New("the runtime answered with no data")
ErrNoMediaData is a runtime answering a media request with nothing.
var ErrNoRuntimeFamily = errors.New("runtime: runtime family not available on this node")
ErrNoRuntimeFamily is returned for a model whose runtime family this node does not have: no adapter is registered under that name (the family is not configured here, or this daemon predates it). Test with errors.Is.
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.
var ErrRuntimeTooOld = errors.New("runtime: build too old for this model")
ErrRuntimeTooOld is returned when a model needs a runtime build newer than the one this node runs (a decision model on a llama.cpp build that predates /v1/systemone).
var ErrUnsupportedModel = errors.New("runtime: this runtime does not serve models of this kind")
ErrUnsupportedModel is returned when a runtime family is asked for a model of a kind it does not serve: a speech model under llama.cpp, a chat model under a speech runtime. The catalog names the wrong family.
Functions ¶
func AudioDurationMS ¶ added in v0.10.0
AudioDurationMS is the length of size bytes of audio in a format whose length follows from its size: PCM at the model's sample rate (16-bit mono), or WAV by its own header. 0 for a compressed format, where it does not.
func AudioMIME ¶ added in v0.10.0
AudioMIME is the type of a speech answer: the runtime's own Content-Type when it names an audio type (one spelling per format, whatever the runtime calls it), else the type of the format asked for.
func EndpointFor ¶ added in v0.10.0
EndpointFor is the public endpoint that serves a kind of model.
func FormatSize ¶ added in v0.10.0
FormatSize is the "<width>x<height>" spelling of a size.
func IsInvalidInput ¶ added in v0.7.0
IsInvalidInput reports whether err is (or wraps) an InvalidInputError.
func MediaMIME ¶ added in v0.10.0
MediaMIME is the content type of a media format ("" for one this daemon does not know).
func NormalizeReasoningEffort ¶ added in v0.9.10
NormalizeReasoningEffort maps what a client may send to the values the runtime takes: "" (unset), none, low, medium, high. OpenAI's "minimal" is "none": as little reasoning as the model can do, which is off where the template has a switch and its lowest level where it has not. ok is false for anything else.
func PCM16WAV ¶ added in v0.10.0
PCM16WAV wraps 16-bit little-endian PCM samples in a WAV container.
func ParseSize ¶ added in v0.10.0
ParseSize reads "<width>x<height>" (decimal, no signs, no spaces).
func SpeechBody ¶ added in v0.10.0
func SpeechBody(model string, req *SpeechRequest) map[string]any
SpeechBody is OpenAI's body for a speech request: model, input, voice, response_format, speed. An adapter edits it for its runtime's quirks.
func SplitSpeech ¶ added in v0.10.0
SplitSpeech cuts text into the segments a speech runtime is given one by one. See the rule at the top of this file. A text that is all white space has no segments.
func TakesImages ¶ added in v0.9.7
TakesImages reports whether inst takes image input.
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
// Reasoning is a chain-of-thought delta (OpenAI's `reasoning_content`).
// Empty for models the runtime cannot parse, whose thinking then
// arrives inline in Delta (e.g. as `<think>…</think>`).
Reasoning string
TokenCount int
Done bool
FinishReason string // "stop", "length", "cancelled", "error"
// Usage is the final count, on the Done chunk.
Usage *Usage
// Running is the count so far, on a chunk that is not Done, when the
// runtime reports one: the whole prompt, and the completion tokens
// generated up to and including this chunk. The tunnel relays it so
// the coordinator can close out and bill an answer its time limit
// cuts off (proto design note 2026-11-29-running-usage). Nothing on
// the node reads it.
Running *Usage
Embeddings [][]float32
Decision []DecisionAnswer // KindDecision: one per question, in order
// Media is the next piece of a media result, or progress towards one.
Media *MediaPiece
Err string
// InvalidInput, with Err: the runtime refused the input itself. A
// media request reports it in the stream because the runtime only
// answers once it has done (or declined) the work, long after
// Complete returned.
InvalidInput bool
}
Chunk is one streamed unit. For KindEmbedding a single final chunk carries Embeddings; for KindDecision a single final chunk carries Decision. For KindSpeech and KindImage chunks carry Media (pieces of the file, or progress), then a final chunk. Usage is set on the final chunk.
Every token the model produces is relayed as either Delta (the answer) or Reasoning (chain-of-thought, for models whose runtime separates it), and TokenCount covers both: the customer is billed for reasoning tokens and canary comparison diffs the whole stream, so nothing is dropped on the node. A chunk may carry both when the runtime emits them together.
func MediaError ¶ added in v0.10.0
MediaError is the final chunk of a media request that failed. err that is (or wraps) an InvalidInputError marks the input as refused.
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
// Decision is the KindDecision payload. The result is a single final
// Chunk carrying Decision answers (in question order) and Usage.
Decision *DecisionInput
// Speech and Image are the KindSpeech and KindImage payloads, with
// every default already resolved by whoever built the request.
Speech *SpeechRequest
Image *ImageRequest
Params GenerationParams
// Origin says who asked, for the live activity view only: "local"
// (the local API; also what "" means), "mesh" (a coordinator
// dispatch) or "challenge" (a fingerprint probe). The runtime
// ignores it.
Origin string
}
type ContentPart ¶ added in v0.9.7
ContentPart is one piece of a message that carries an image: text, or an image.
type DecisionAnswer ¶ added in v0.7.0
type DecisionAnswer struct {
QuestionID string
Type DecisionType
Choice string // choice: the most probable option key
Score float64 // score: expected level index
Noul float64 // noul: probability the statement is true
Probabilities []DecisionProbability
Confidence float64 // choice and score: 0..1
}
DecisionAnswer is the typed answer to one question. Probabilities are ordered like the question's options and empty for noul.
type DecisionInput ¶ added in v0.7.0
type DecisionInput struct {
StateJSON string // compact JSON: string, object or array
Questions []DecisionQuestion
}
DecisionInput is a validated /v1/systemone request: the state and the questions in request order (ids unique).
type DecisionOption ¶ added in v0.7.0
type DecisionOption struct {
// Key is the option key (choice), the level index "0", "1", … (score)
// or "true"/"false" (noul, only when described).
Key string
// DescriptionJSON is compact JSON (string, object or array); "" means
// JSON null: the option has no description.
DescriptionJSON string
}
DecisionOption is one possible answer. Order is part of the contract: the model reads the options in the order the customer wrote them.
type DecisionProbability ¶ added in v0.7.0
DecisionProbability is the probability of one option (or score level).
type DecisionQuestion ¶ added in v0.7.0
type DecisionQuestion struct {
ID string
Type DecisionType
InstructionsJSON string // compact JSON: string, object or array
Options []DecisionOption
}
DecisionQuestion is one typed question. Options is a list, never a map, so the order survives every hop.
type DecisionType ¶ added in v0.7.0
type DecisionType int
DecisionType is the type of one decision question (and of its answer); it mirrors typesv1.DecisionQuestionType.
const ( DecisionChoice DecisionType = iota + 1 // pick one labelled option DecisionScore // place on an ordered scale DecisionNoul // probability a statement is true )
func (DecisionType) String ¶ added in v0.7.0
func (t DecisionType) String() string
String is the public name of the type ("choice", "score", "noul").
type FamilyIdentified ¶ added in v0.10.0
type FamilyIdentified interface {
RuntimeFamily() string
}
FamilyIdentified is implemented by an Instance that knows which runtime family serves it. One that does not is a llama.cpp instance (or the mock), as every instance was before there was more than one family.
type GenerationParams ¶
type GenerationParams struct {
Seed uint64
Temperature float64
TopP float64
// MaxTokens caps the completion; 0 is no cap, and the reply then
// runs until the model stops or its context is full.
MaxTokens int
Stop []string
FrequencyPenalty float64
PresencePenalty float64
// ReasoningEffort asks a reasoning model for less thinking, or none:
// "" (the model's default), "none", "low", "medium", "high" (see
// reasoning.go). Chat only; a model with no reasoning ignores it.
ReasoningEffort string
}
GenerationParams: seed is always set upstream so retries and canary comparisons are deterministic for greedy decoding (SPEC §6).
type Image ¶ added in v0.9.7
Image is an image by value: the file's bytes and its type ("image/png", "image/jpeg").
type ImageInputter ¶ added in v0.9.7
type ImageInputter interface {
ImageInput() bool
}
ImageInputter is implemented by an Instance that can take images. An instance that does not implement it takes none.
type ImageModel ¶ added in v0.10.0
type ImageModel struct {
Sizes []string // "<width>x<height>"
DefaultSize string
Steps int
Guidance float64 // the classifier-free scale
// DistilledGuidance is the guidance of a guidance-distilled model (the
// FLUX family), which keeps Guidance at 1 and takes this instead. 0 =
// the model does not use it and the runtime is not sent one.
DistilledGuidance float64
Formats []string // of "png", "jpeg"
}
ImageModel is what an image model offers, from its catalog entry. Steps and both guidance values are the model's fixed values: a request cannot change them.
func (*ImageModel) CheckImage ¶ added in v0.10.0
func (m *ImageModel) CheckImage(req *ImageRequest) error
CheckImage is CheckSpeech for an image request.
type ImageRequest ¶ added in v0.10.0
type ImageRequest struct {
Prompt string
NegativePrompt string
Width, Height int
Steps int
Guidance float64
// DistilledGuidance: see ImageModel. 0 = not sent to the runtime.
DistilledGuidance float64
Seed uint64
Format string // "png" or "jpeg"
}
ImageRequest is one image-generation request, for one image, every default resolved.
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 InvalidInputError ¶ added in v0.7.0
type InvalidInputError struct{ Msg string }
InvalidInputError means the runtime rejected the input itself (too many options for this model, a prompt over its context — llama-server's 400): another node would reject it too, so the request must not be retried elsewhere. Callers test with errors.As.
func (*InvalidInputError) Error ¶ added in v0.7.0
func (e *InvalidInputError) Error() string
type MediaInfo ¶ added in v0.10.0
type MediaInfo struct {
Width, Height int // image: pixels
DurationMS int // audio: the whole file, when known up front
SampleRate int // audio: Hz
}
MediaInfo describes the output file, where the runtime knows it.
type MediaPiece ¶ added in v0.10.0
type MediaPiece struct {
Data []byte
// MIME and Info ride on the first data piece.
MIME string
Info *MediaInfo
// ProgressPermille is how far along the runtime is, 0..1000, never
// decreasing; 0 when it cannot say.
ProgressPermille int
}
MediaPiece is one unit of a media result: the next piece of the file (Data set; at most MediaPieceMax), or progress while there is nothing to send yet (Data empty).
type MediaResult ¶ added in v0.10.0
type MediaResult struct {
Data []byte
MIME string
Info *MediaInfo
Usage Usage
// Progress counts the progress pieces seen before the data.
Progress int
}
MediaResult is a whole media result, collected.
func DrainMedia ¶ added in v0.10.0
func DrainMedia(ts TokenStream) (MediaResult, error)
DrainMedia reads a media stream to its end. A failure reported in the stream comes back as an error, an *InvalidInputError when the runtime refused the input.
type MediaWriter ¶ added in v0.10.0
type MediaWriter struct {
// contains filtered or unexported fields
}
MediaWriter turns a runtime's output into the chunks of a media result: data in pieces of at most MediaPieceMax, the first one carrying the type and what is known about the file.
func NewMediaWriter ¶ added in v0.10.0
func NewMediaWriter(ctx context.Context, ch chan<- Chunk, mime string, info *MediaInfo) *MediaWriter
NewMediaWriter writes to ch until ctx ends.
func (*MediaWriter) Progress ¶ added in v0.10.0
func (w *MediaWriter) Progress(permille int) bool
Progress sends a progress piece.
func (*MediaWriter) Write ¶ added in v0.10.0
func (w *MediaWriter) Write(data []byte) bool
Write sends data as one or more pieces. It reports false once ctx has ended: the request was cancelled and nothing more will be read.
type Message ¶
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
Parts []ContentPart `json:"-"`
}
Message is one chat message. Content is its text. Parts is set only for a message that carries an image (proto design note 2026-11-29): it is then the whole content in order, and Content holds just the text.
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
// ReasoningTokens makes chat generations emit this many chain-of-thought
// tokens (Chunk.Reasoning) before the answer, the way llama.cpp's
// reasoning_content parsing does for reasoning models. They count
// toward max_tokens and completion_tokens like any other token.
ReasoningTokens int
// ImageDelay is how long the mock takes to "generate" an image: the
// work is split into the model's steps, with a progress piece after
// each. 0 = at once.
ImageDelay time.Duration
}
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 ¶
func (m *MockRuntime) Load(_ context.Context, spec ModelSpec, res ResourceBudget) (Instance, error)
type ModelFile ¶ added in v0.10.0
ModelFile is one further file of a model, with the role the runtime uses it for ("voices"; "vae", "llm", "clip_l", "clip_g", "t5xxl").
type ModelSpec ¶
type ModelSpec struct {
ID string
Family string
Quant string
SHA256 string
Path string // local GGUF path (part 1 of a sharded model)
ContextLength int
Embeddings bool // model is served for /v1/embeddings
// Decision marks a typed decision model served for /v1/systemone
// (KindDecision): it answers bounded questions with probabilities and
// generates no tokens. Mutually exclusive with Embeddings.
Decision bool
// MmprojPath is the vision projector sidecar passed to the runtime
// (llama-server --mmproj); "" when the model has none.
MmprojPath string
// SizeBytes is what the artifact occupies on disk across all of its
// files; 0 = unknown (the runtime stats Path instead).
SizeBytes int64
// Runtime is the runtime family that serves the model; "" is llama.cpp
// (see RuntimeFamily).
Runtime string
// Speech and Image are set for a media model (served for
// /v1/audio/speech or /v1/images/generations and nothing else): what
// a request may ask of it. At most one is set; neither goes with
// Embeddings or Decision. Path is then the model's main file, which
// need not be a GGUF.
Speech *SpeechModel
Image *ImageModel
// Files are the further files the model needs, by role (the voices
// of a speech model; the VAE and text encoders of an image model).
Files []ModelFile
}
ModelSpec identifies a locally available model artifact ready to load. It is derived from the catalog's typesv1.ModelSpec after download+verify.
func MockImageSpec ¶ added in v0.10.0
func MockImageSpec() ModelSpec
MockImageSpec is the mock's image model.
func MockSpeechSpec ¶ added in v0.10.0
func MockSpeechSpec() ModelSpec
MockSpeechSpec is the mock's speech model.
func (ModelSpec) FilePath ¶ added in v0.10.0
FilePath is the path of the model's file with the given role, "" when it has none.
func (ModelSpec) Media ¶ added in v0.10.0
Media reports whether the model is a speech or image model.
func (ModelSpec) MediaKind ¶ added in v0.10.0
MediaKind is the request kind a media model answers; 0 for every other model.
func (ModelSpec) RuntimeFamily ¶ added in v0.10.0
RuntimeFamily is the family that serves the model: Runtime, or llama.cpp when it names none.
func (ModelSpec) ServedKind ¶ added in v0.10.0
ServedKind is what the model is served for.
type ModelSupporter ¶ added in v0.7.0
ModelSupporter is implemented by runtimes that can tell, without loading, that their build cannot serve a model. modelops and assign ask before downloading so an unservable placement is refused up front.
type Registry ¶ added in v0.10.0
type Registry struct {
// contains filtered or unexported fields
}
Registry is the runtime families a node runs, by name. It is itself a Runtime: a model is loaded by the adapter of its family (ModelSpec.RuntimeFamily), so everything that loads models keeps talking to one Runtime however many families there are.
func NewRegistry ¶ added in v0.10.0
func NewRegistry() *Registry
NewRegistry returns an empty registry.
func (*Registry) PrepareRuntime ¶ added in v0.10.0
PrepareRuntime implements RuntimePreparer for the family of m, when that family has something to prepare. A family this node does not have is not an error here: Load says so.
func (*Registry) Register ¶ added in v0.10.0
Register makes r the adapter of family. A later Register for the same family replaces it.
func (*Registry) SupportsModel ¶ added in v0.10.0
SupportsModel implements ModelSupporter: a model of a family this node does not have is refused before anything is downloaded for it, and one of a family it has is put to that family's own check, when it has one.
type ResourceBudget ¶
type ResourceBudget struct {
MaxVRAMPercent int
MaxRAMMB int64
// MaxConcurrent is the slot ceiling (budget.max_concurrent, or the
// hardware default when that is 0).
MaxConcurrent int
// Slots and ContextTokens are what memory.PlanContext decided for
// this load: --parallel and --ctx-size. 0 = unplanned; the adapter
// falls back to MaxConcurrent and its own context resolution.
Slots int
ContextTokens int
}
ResourceBudget is the operator-configured ceiling passed to Load, plus the layout admission planned for this particular 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 RuntimePreparer ¶ added in v0.10.0
RuntimePreparer is implemented by runtimes whose own build may have to be downloaded before the first model can be loaded. modelops calls it before it takes the admission lock, so a first load of one family does not hold up every other load for the length of a download.
type SpeechModel ¶ added in v0.10.0
type SpeechModel struct {
Voices []string
Formats []string // of "wav", "pcm", "mp3", "opus", "flac"
SampleRate int // Hz
}
SpeechModel is what a speech model offers, from its catalog entry.
func (*SpeechModel) CheckSpeech ¶ added in v0.10.0
func (m *SpeechModel) CheckSpeech(req *SpeechRequest) error
CheckSpeech holds a speech request to what the model offers. The gateway and the local API validate before they route, so a failure here is a model whose catalog entry moved under a request: the runtime refusing the input, not a fault of the node.
type SpeechRequest ¶ added in v0.10.0
type SpeechRequest struct {
Text string
Voice string
Format string
Speed float64 // 1.0 = the voice's own; never 0
Language string // BCP-47, "" = the voice decides
}
SpeechRequest is one text-to-speech request, every default resolved.
type Stats ¶
type Stats struct {
Healthy bool
ModelID string
QueueDepth int
TokensPerSec float64
MemUsedMB int64
Restarts int
}
Stats is the Health snapshot.
type TokenStream ¶
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
// The units of the kinds that are not metered in tokens (proto design
// note 2026-11-30-media-output); zero for every other kind.
InputCharacters int // KindSpeech: Unicode code points of the text
OutputAudioMS int // KindSpeech: milliseconds of audio, 0 = unknown
OutputImages int // KindImage: images produced
OutputPixels int64 // KindImage: width x height, summed
}
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 (challenges, tests). Reasoning deltas are discarded here; callers that must relay them use DrainAll.
Source Files
¶
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). |
|
Package media adapts "OpenAI-style media servers" to the runtime.Runtime interface: runtimes that are a server process answering POST /v1/audio/speech with an audio file or POST /v1/images/generations with an image (proto design note 2026-11-30-media-output).
|
Package media adapts "OpenAI-style media servers" to the runtime.Runtime interface: runtimes that are a server process answering POST /v1/audio/speech with an audio file or POST /v1/images/generations with an image (proto design note 2026-11-30-media-output). |
|
Package supervise keeps one runtime server child process alive: start, health-gate, restart with exponential backoff on crash, graceful stop.
|
Package supervise keeps one runtime server child process alive: start, health-gate, restart with exponential backoff on crash, graceful stop. |