Skip to main content

weirdnet_model/
lib.rs

1//! Weirdnet local models.
2//!
3//! - [`catalog`]: pinned Gemma 4 E2B and E4B GGUF files (Hugging Face repo, file, size, SHA-256).
4//! - [`store`] and [`mod@download`]: where model files live, and a consent-gated download that
5//!   resumes a `.part` file and checks size and SHA-256 before the file appears.
6//! - [`hf`]: read a Hugging Face repo's GGUF files, so any repo can become a [`ModelSpec`].
7//! - [`prompt`]: render chat turns with the model's own Jinja template, and the `<tool_call>`
8//!   tag format for tools (prompt text and a streaming parser).
9//! - [`worker`]: an [`Engine`] on its own thread, streaming text with cancel.
10//! - `llama` (feature): the llama.cpp [`Engine`].
11//! - `agent` (feature): `weirdnet_agent::ModelBackend` over the worker.
12//!
13//! Nothing here knows an app: callers pass paths, consent and callbacks.
14#![forbid(unsafe_code)]
15
16pub mod catalog;
17pub mod download;
18pub mod hf;
19pub mod prompt;
20pub mod store;
21#[cfg(test)]
22mod testing;
23pub mod worker;
24
25#[cfg(feature = "agent")]
26pub mod agent;
27#[cfg(feature = "llama")]
28pub mod llama;
29
30pub use catalog::{Device, ModelSpec, human};
31pub use download::{Consent, Progress, download};
32pub use prompt::{ChatMessage, ChatRole};
33pub use store::ModelStore;
34pub use worker::{Chunk, Engine, GenerateRequest, Generation, Stats, Worker};
35
36/// Everything that can go wrong here.
37#[derive(Debug, thiserror::Error)]
38pub enum Error {
39    #[error("{0}")]
40    Io(#[from] std::io::Error),
41    #[error("network: {0}")]
42    Http(String),
43    #[error("{name}: checksum mismatch (got {got}); the file was deleted")]
44    Checksum { name: String, got: String },
45    #[error("download stopped at {done} of {total} (run it again to resume)")]
46    Incomplete { done: String, total: String },
47    #[error("download cancelled at {done} of {total} (run it again to resume)")]
48    Cancelled { done: String, total: String },
49    #[error("consent was given for another model")]
50    Consent,
51    #[error("{0:?} is not a Hugging Face model id (owner/name)")]
52    BadRepo(String),
53    #[error("{0}")]
54    Model(String),
55}
56
57pub type Result<T> = std::result::Result<T, Error>;