1#![allow(clippy::pedantic, clippy::module_name_repetitions)]
11
12use std::ffi::NulError;
13
14pub mod context;
15pub mod gguf;
16pub mod grammar;
17pub mod llama_backend;
18pub mod llama_batch;
19pub mod model;
20#[cfg(feature = "mtmd")]
21pub mod mtmd;
22pub mod quantize;
23pub mod sampling;
24pub mod speculative;
25pub mod timing;
26pub mod token;
27
28pub use context::params::{LlamaContextParams, LlamaContextType};
29pub use context::LlamaContext;
30#[cfg(feature = "common")]
31pub use grammar::{json_schema_to_grammar, JsonSchemaError};
32pub use grammar::{DryInitError, DryParams, GrammarInitError, LlamaDrySampler, LlamaGrammar};
33pub use llama_backend::LlamaBackend;
34pub use llama_batch::LlamaBatch;
35pub use model::params::LlamaModelParams;
36pub use model::{AddBos, LlamaModel};
37#[cfg(feature = "mtmd")]
38pub use mtmd::{
39 mtmd_default_marker, MtmdBitmap, MtmdBitmapError, MtmdContext, MtmdContextParams,
40 MtmdEncodeError, MtmdEvalError, MtmdInitError, MtmdInputChunk, MtmdInputChunkError,
41 MtmdInputChunkType, MtmdInputChunks, MtmdInputChunksError, MtmdInputText, MtmdTokenizeError,
42};
43pub use sampling::LlamaSampler;
44pub use speculative::{MtpOpType, MtpSpeculativeParams};
45#[cfg(feature = "common")]
46pub use speculative::{MtpSpeculative, MtpStep};
47pub use token::data::LlamaTokenData;
48pub use token::data_array::LlamaTokenDataArray;
49pub use token::LlamaToken;
50
51#[derive(Debug, thiserror::Error)]
53pub enum LlamaError {
54 #[error("llama backend already initialized")]
56 BackendAlreadyInitialized,
57 #[error("failed to load model from {0}")]
59 ModelLoad(String),
60 #[error("failed to create llama context")]
62 ContextCreation,
63 #[error("string contained an interior NUL byte")]
65 Nul(#[from] NulError),
66 #[error("invalid model path")]
68 InvalidPath,
69 #[error("tokenization failed")]
71 Tokenize,
72 #[error("token could not be converted to text")]
74 TokenToPiece,
75 #[error("llama_decode failed with status {0}")]
77 Decode(i32),
78 #[error("batch capacity {capacity} exceeded (tried to add token {index})")]
80 BatchOverflow {
81 capacity: usize,
83 index: usize,
85 },
86 #[error("too many seq_ids for a batch token: got {got}, max {max}")]
88 TooManySeqIds {
89 got: usize,
91 max: usize,
93 },
94 #[error("no logits available at index {0}")]
96 NoLogits(i32),
97 #[error("failed to initialize MTP speculative driver")]
100 MtpInit,
101 #[error("MTP begin failed with status {0}")]
103 MtpBegin(i32),
104 #[error("MTP step failed with status {0}")]
106 MtpStep(i32),
107}