Skip to main content

weirdnet_backends/
lib.rs

1//! The Weirdnet model-node wrapper.
2//!
3//! A model node runs models and takes requests, like a llama.cpp or vLLM server (it can be one:
4//! a stock server it only wraps). This crate starts and stops the engines and serves them; it
5//! decides nothing beyond the node: what to load is the caller's decision.
6//!
7//! - [`engine`]: how llama.cpp `llama-server`, `vllm serve` and MLX-LM's `mlx_lm.server` are
8//!   launched and probed, each model's [`Capabilities`] (chat, embeddings, images, audio), and
9//!   [`Wrap`] for a stock OpenAI-compatible server on loopback, and [`LoraAdapter`]s served
10//!   next to a llama.cpp or vLLM base model.
11//! - [`mlx`]: installing a pinned `mlx-lm` into a venv, and the proxy the supervisor puts in front
12//!   of `mlx_lm.server` (API key check, readiness after a one-token completion, `default_model`
13//!   rewrite, text only).
14//! - [`supervisor`]: the local supervisor: load (random loopback port, per-process API key in
15//!   the environment, readiness probe), drain and unload, swap groups, idle unload, crash
16//!   restarts with backoff and crash loops, a [`Reservation`] that holds the node's GPU for one
17//!   job (nothing is placed there until it is released), [`SupervisorEvent`]s and per-model logs; chat,
18//!   completion and embedding forwarding; adapters routed to their base ([`AdapterChange`]).
19//! - [`sse`]: OpenAI server-sent events decoded into [`Chunk`]s, and [`ToolCalls`] to join
20//!   streamed tool calls.
21//! - [`openai`]: engine request bodies from `weirdnet-agent` infer/2 requests.
22//! - [`host`]: [`ModelHost`], a `weirdnet-agent` `InferHost` serving raw infer/2 from the
23//!   supervisor's models.
24//! - `node` (feature): `/weirdnet-backends/node/1` over `weirdnet-net`: signed capability
25//!   records, `Load`, `Unload`, `Drain`, `Reserve`/`Release`, `GroupUp`/`GroupDown` and health.
26//! - `models` (feature `node`): `/weirdnet-backends/models/1`, for the owner only: search the
27//!   Hugging Face Hub, see which files fit the node, pull (split GGUFs too) and serve without a
28//!   restart, list and remove; LoRA adapters for a served base too. Uploads of model files made
29//!   elsewhere (resumable, checked, with provenance), copies between nodes and a disk report,
30//!   with writes under a [`models::WritePolicy`].
31//!
32//! Platforms: the supervisor runs on Unix and Windows. On Unix an engine gets its own process
33//! group, stops with SIGTERM then SIGKILL after a grace period, and on Linux dies with its
34//! parent; on Windows the engine process is killed outright and processes it started are not.
35//! vLLM runs on Linux only; MLX-LM on macOS on Apple silicon only.
36
37pub mod engine;
38pub mod error;
39pub mod host;
40#[cfg(feature = "node")]
41pub mod link;
42pub mod mlx;
43#[cfg(feature = "node")]
44pub mod models;
45#[cfg(feature = "node")]
46pub mod node;
47pub mod openai;
48pub mod sse;
49pub mod supervisor;
50
51pub use engine::{Capabilities, EngineConfig, EngineKind, LoraAdapter, ModelLaunch, Wrap, find_in_path};
52pub use host::{EngineModel, ModelHost, RAW_INFER_PROTOCOL, RawInferDialer, Speed};
53pub use openai::Target;
54pub use sse::{Chunk, ChunkDecoder, SseParser, ToolCalls};
55pub use supervisor::{
56    AdapterChange, ChunkStream, MAX_ADAPTER_SCALE, ModelState, ModelStatus, Reservation, Supervisor, SupervisorEvent, SupervisorOptions,
57};