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`, vLLM-Omni (`vllm serve --omni`) and
8//! MLX-LM's `mlx_lm.server` are launched and probed, each model's [`Capabilities`] (chat,
9//! embeddings, images, audio, video, transcription, speech), and
10//! [`Wrap`] for a stock OpenAI-compatible server on loopback, and [`LoraAdapter`]s served
11//! next to a llama.cpp or vLLM base model.
12//! - [`mlx`]: installing a pinned `mlx-lm` into a venv, and the proxy the supervisor puts in front
13//! of `mlx_lm.server` (API key check, readiness after a one-token completion, `default_model`
14//! rewrite, text only).
15//! - [`supervisor`]: the local supervisor: load (random loopback port, per-process API key in
16//! the environment, readiness probe), drain and unload, swap groups, idle unload, crash
17//! restarts with backoff and crash loops, a [`Reservation`] that holds the node's GPU for one
18//! job (nothing is placed there until it is released), [`SupervisorEvent`]s and per-model logs; chat,
19//! completion and embedding forwarding; adapters routed to their base ([`AdapterChange`]).
20//! - [`sse`]: OpenAI server-sent events decoded into [`Chunk`]s, and [`ToolCalls`] to join
21//! streamed tool calls.
22//! - [`openai`]: engine request bodies from `weirdnet-agent` infer/2 requests.
23//! - [`host`]: [`ModelHost`], a `weirdnet-agent` `InferHost` serving raw infer/2 from the
24//! supervisor's models, transcription (infer/2 `Transcribe`) and speech out (infer/2 `Speak`,
25//! llama-server's and vLLM-Omni's `/v1/audio/speech`) included.
26//! - [`fence`]: placement-lease fencing ([`Fence`], [`FenceGuard`], [`FenceRefusal`]): a model node
27//! refuses node/1 `Load` and `Unload` from a lease holder with an older term than it has seen.
28//! - `node` (feature): `/weirdnet-backends/node/1` over `weirdnet-net`: signed capability
29//! records, `Load`, `Unload`, `Drain`, `Reserve`/`Release`, `GroupUp`/`GroupDown` and health.
30//! - `models` (feature `node`): `/weirdnet-backends/models/1`, for the owner only: search the
31//! Hugging Face Hub, see which files fit the node, pull (split GGUFs too) and serve without a
32//! restart, list and remove; LoRA adapters for a served base too. Uploads of model files made
33//! elsewhere (resumable, checked, with provenance), copies between nodes and a disk report,
34//! with writes under a [`models::WritePolicy`].
35//!
36//! Platforms: the supervisor runs on Unix and Windows. On Unix an engine gets its own process
37//! group, stops with SIGTERM then SIGKILL after a grace period, and on Linux dies with its
38//! parent; on Windows the engine process is killed outright and processes it started are not.
39//! vLLM and vLLM-Omni run on Linux only; MLX-LM on macOS on Apple silicon only.
40
41pub mod engine;
42pub mod error;
43pub mod fence;
44pub mod host;
45#[cfg(feature = "node")]
46pub mod link;
47mod measure;
48pub mod mlx;
49#[cfg(feature = "node")]
50pub mod models;
51#[cfg(feature = "node")]
52pub mod node;
53pub mod openai;
54mod speak;
55pub mod sse;
56pub mod supervisor;
57mod transcribe;
58
59pub use engine::{Capabilities, EngineConfig, EngineKind, LoraAdapter, ModelLaunch, Wrap, find_in_path};
60pub use fence::{Fence, FenceGuard, FenceRefusal};
61pub use host::{EngineModel, ModelHost, RAW_INFER_PROTOCOL, RawInferDialer, Speed};
62pub use openai::Target;
63pub use sse::{Chunk, ChunkDecoder, SseParser, ToolCalls};
64pub use supervisor::{
65 AdapterChange, ChunkStream, MAX_ADAPTER_SCALE, ModelState, ModelStatus, Reservation, Supervisor, SupervisorEvent, SupervisorOptions,
66};
67pub use weirdnet_agent::speech::SpeechProfile;
68
69/// What `messages` need beyond text (images, audio, video).
70pub(crate) fn model_needs(messages: &[weirdnet_agent::Message]) -> weirdnet_agent::Modalities {
71 weirdnet_agent::model::needs(messages)
72}