#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(rust_2018_idioms, single_use_lifetimes, missing_docs)]
#[cfg(feature = "bundled")]
pub(crate) mod bundled;
pub mod chat_template;
#[cfg(all(feature = "inference", feature = "decoders"))]
mod engine;
pub mod error;
#[cfg(all(feature = "inference", feature = "decoders"))]
pub(crate) mod generate;
mod image_analysis;
pub mod options;
pub mod preproc;
#[cfg(feature = "inference")]
pub(crate) mod runtime;
mod task;
pub use chat_template::{
BOS, BOS_TOKEN_ID, EOS_TOKEN_ID, IM_END, IM_START, IMAGE_END, IMAGE_START, IMAGE_THUMBNAIL,
IMAGE_TOKEN, IMAGE_TOKEN_ID, ImagePlaceholderInfo, PAD, PAD_TOKEN_ID, TOOL_CALL_END,
TOOL_CALL_START, expand_image_placeholders,
};
#[cfg(feature = "inference")]
#[cfg_attr(docsrs, doc(cfg(feature = "inference")))]
pub use chat_template::{
BUNDLED_CHAT_TEMPLATE_JINJA, ContentItem, Message, UserContent, apply_chat_template,
};
#[cfg(all(feature = "inference", feature = "decoders"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "inference", feature = "decoders"))))]
pub use engine::{Engine, EnginePaths};
pub use error::{Error, Result};
#[cfg(feature = "inference")]
#[cfg_attr(docsrs, doc(cfg(feature = "inference")))]
pub use options::GraphOptimizationLevel;
pub use options::{ImageBudget, Options, RequestOptions, ThreadOptions};
#[cfg(feature = "decoders")]
#[cfg_attr(docsrs, doc(cfg(feature = "decoders")))]
pub use preproc::decode_bytes_with_orientation;
#[cfg(all(feature = "decoders", not(target_arch = "wasm32")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "decoders", not(target_arch = "wasm32"))))
)]
pub use preproc::decode_with_orientation;
pub use preproc::{PreprocessedImage, Preprocessor, TileGrid};
#[derive(Debug, Clone)]
pub struct ChatMessage {
role: smol_str::SmolStr,
content: ChatContent,
}
impl ChatMessage {
pub fn new(role: smol_str::SmolStr, content: ChatContent) -> Self {
Self { role, content }
}
pub fn text(role: smol_str::SmolStr, text: impl Into<String>) -> Self {
Self {
role,
content: ChatContent::Text(text.into()),
}
}
pub fn parts(role: smol_str::SmolStr, parts: Vec<ContentPart>) -> Self {
Self {
role,
content: ChatContent::Parts(parts),
}
}
pub fn role(&self) -> &smol_str::SmolStr {
&self.role
}
pub fn content(&self) -> &ChatContent {
&self.content
}
pub fn set_role(&mut self, role: smol_str::SmolStr) {
self.role = role;
}
pub fn set_content(&mut self, content: ChatContent) {
self.content = content;
}
pub fn with_role(mut self, role: smol_str::SmolStr) -> Self {
self.role = role;
self
}
pub fn with_content(mut self, content: ChatContent) -> Self {
self.content = content;
self
}
}
#[derive(Debug, Clone)]
pub enum ChatContent {
Text(String),
Parts(Vec<ContentPart>),
}
#[derive(Debug, Clone)]
pub enum ContentPart {
Text(String),
Image,
}
#[derive(Debug, Clone, Copy)]
pub enum ImageInput<'a> {
#[cfg(not(target_arch = "wasm32"))]
Path(&'a std::path::Path),
Bytes(&'a [u8]),
}
pub use image_analysis::{ImageAnalysis, ImageAnalysisTask};
pub use task::{JsonParseError, Task};