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 ¶
- Variables
- func DecisionModelError(id string) error
- type Admitter
- type Engine
- func (e *Engine) Complete(ctx context.Context, req rt.CompletionRequest) (rt.TokenStream, error)
- func (e *Engine) DefaultModel() string
- func (e *Engine) Demand(id string) (now, peak int, ok bool)
- func (e *Engine) Health(ctx context.Context, model string) (rt.Stats, error)
- func (e *Engine) Models() []*ModelEntry
- func (e *Engine) Register(spec rt.ModelSpec, inst rt.Instance)
- func (e *Engine) RegisterSlots(spec rt.ModelSpec, inst rt.Instance, slots int)
- func (e *Engine) Replace(spec rt.ModelSpec, inst rt.Instance, slots int) *ModelEntry
- func (e *Engine) Requests() *live.Tracker
- func (e *Engine) SetDefault(id string) error
- func (e *Engine) Stats() *telemetry.Stats
- func (e *Engine) Unregister(id string) *ModelEntry
- func (e *Engine) UnregisterIdle(id string) (*ModelEntry, error)
- func (e *Engine) Usage(id string) (Usage, bool)
- type ModelEntry
- type Usage
Constants ¶
This section is empty.
Variables ¶
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.
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.
var ErrModelNotFound = errors.New("engine: model not loaded")
ErrModelNotFound is returned for unknown model ids.
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
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 Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine implements tunnel.Engine and backs localapi.
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 ¶
DefaultModel returns the fallback model id.
func (*Engine) Demand ¶ added in v0.8.0
Demand reports a loaded model's load: requests running plus waiting right now, and the peak of that since the previous call (which resets it). It is what slot scaling follows.
func (*Engine) Register ¶
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) RegisterSlots ¶ added in v0.8.0
RegisterSlots is Register for an instance that serves at most slots requests at once (llama-server --parallel): the engine runs that many on it and holds the rest at the gate. slots <= 0 = ungated.
func (*Engine) Replace ¶ added in v0.8.0
Replace swaps a loaded model's instance for another (a resize: same model, different slot count) without a moment in which the model is not loaded. Requests running on the old instance finish there; requests waiting for a slot, and every later one, go to the new instance. The default model stays the default. It returns the old entry, which the caller shuts down once Draining reports it idle; nil when the model was not loaded (inst is then not registered).
func (*Engine) Requests ¶ added in v0.7.3
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
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) 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.
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.
func (*ModelEntry) Draining ¶ added in v0.8.0
func (m *ModelEntry) Draining() int
Draining reports how many requests still hold a replaced or unregistered entry.
func (*ModelEntry) Slots ¶ added in v0.8.0
func (m *ModelEntry) Slots() int
Slots is the entry's concurrency gate (0 = ungated).
type Usage ¶ added in v0.4.0
type Usage struct {
LastUsed time.Time
Inflight int
// Served reports whether any request has started on the model since
// it was loaded; LastUsed is then that request's start, set before
// the request reaches the runtime, so a busy model always has it.
Served bool
}
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.