engine

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 11 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 engine routes completion requests to loaded runtime Instances, applying governor admission and telemetry accounting. It is the single serving funnel shared by the local OpenAI API and the tunnel dispatcher.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("engine: model busy")

ErrBusy is returned by UnregisterIdle when the model has requests in flight (or waiting in admission) and so must not be unloaded.

View Source
var ErrDecisionModel = errors.New("engine: decision model")

ErrDecisionModel is returned when a chat, completion or embedding request names a decision model. The catalog flag decides, not what the weights could do: a decision model is served by /v1/systemone only.

View Source
var ErrModelNotFound = errors.New("engine: model not loaded")

ErrModelNotFound is returned for unknown model ids.

View Source
var ErrNotChatModel = errors.New("engine: not a chat model")

ErrNotChatModel is returned by SetDefault for a decision or embedding model: the default answers chat requests that name no model, so only a chat model can be it.

Functions

func DecisionModelError added in v0.7.1

func DecisionModelError(id string) error

DecisionModelError is the error for a generation or embedding request aimed at decision model id. It wraps ErrDecisionModel and reads exactly like the gateway's refusal.

Types

type Admitter

type Admitter interface {
	Admit(ctx context.Context, id string) (context.Context, func(), error)
}

Admitter gates requests (usually *governor.Governor).

type Engine

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

Engine implements tunnel.Engine and backs localapi.

func New

func New(admit Admitter, stats *telemetry.Stats, touch func(string)) *Engine

New builds an Engine. admit may be nil (no gating), stats may be nil.

func (*Engine) Complete

func (e *Engine) Complete(ctx context.Context, req rt.CompletionRequest) (rt.TokenStream, error)

Complete runs one request through admission, the runtime, and telemetry.

func (*Engine) DefaultModel

func (e *Engine) DefaultModel() string

DefaultModel returns the fallback model id.

func (*Engine) Health

func (e *Engine) Health(ctx context.Context, model string) (rt.Stats, error)

Health proxies the default (or named) instance health.

func (*Engine) Models

func (e *Engine) Models() []*ModelEntry

Models lists loaded entries.

func (*Engine) Register

func (e *Engine) Register(spec rt.ModelSpec, inst rt.Instance)

Register adds a loaded model; the first chat model registered becomes the default. A decision or embedding model never does: the default is what answers a chat request that names no model, and with only such models loaded there is simply no default.

func (*Engine) Requests added in v0.7.3

func (e *Engine) Requests() *live.Tracker

Requests is the live request tracker: what is running on the runtimes right now and what ran recently (GET /api/v1/requests). Set its Events hub before serving to get request_started / request_finished events.

func (*Engine) SetDefault added in v0.3.0

func (e *Engine) SetDefault(id string) error

SetDefault names the model used when a request omits one. The model must be loaded — a default pointing at nothing would turn every bare request into a 404.

func (*Engine) Stats

func (e *Engine) Stats() *telemetry.Stats

Stats exposes the telemetry accumulator.

func (*Engine) Unregister

func (e *Engine) Unregister(id string) *ModelEntry

Unregister removes a model (eviction); callers shut the instance down. Requests in flight on it fail when the instance goes away — use UnregisterIdle when that is not acceptable.

func (*Engine) UnregisterIdle added in v0.4.0

func (e *Engine) UnregisterIdle(id string) (*ModelEntry, error)

UnregisterIdle removes a model only if nothing is in flight on it. The in-flight check and the removal happen under the same lock the request path takes to route to the model, so a request cannot slip in between: after this returns, either the model is gone and no request holds it, or ErrBusy says a request does. Daemon-initiated unloads (memory admission, idle unload) use this; the operator's explicit unload keeps Unregister's forced semantics.

func (*Engine) Usage added in v0.4.0

func (e *Engine) Usage(id string) (Usage, bool)

Usage reports a loaded model's last request time and in-flight count.

type ModelEntry

type ModelEntry struct {
	Spec     rt.ModelSpec
	Instance rt.Instance
	// LoadedAt is when the instance was registered.
	LoadedAt time.Time
	// contains filtered or unexported fields
}

ModelEntry pairs a loaded instance with its metadata.

type Usage added in v0.4.0

type Usage struct {
	LastUsed time.Time
	Inflight int
}

Usage is the per-model activity view idle unload and memory admission read: when it last started serving a request (LoadedAt if never) and how many requests it is serving right now.

Jump to

Keyboard shortcuts

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