diff --git a/Cargo.toml b/Cargo.toml index e88e168..8b42c18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,3 +41,7 @@ ollama-rs = { path = ".", features = [ "function-calling", ] } base64 = "0.22.0" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/src/generation.rs b/src/generation.rs index a29c4ae..77b9ef4 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -1,6 +1,7 @@ pub mod chat; pub mod completion; pub mod embeddings; +#[cfg_attr(docsrs, doc(cfg(feature = "function-calling")))] #[cfg(feature = "function-calling")] pub mod functions; pub mod images; diff --git a/src/generation/chat/mod.rs b/src/generation/chat/mod.rs index bf511f0..6971587 100644 --- a/src/generation/chat/mod.rs +++ b/src/generation/chat/mod.rs @@ -7,15 +7,18 @@ pub mod request; use super::images::Image; use request::ChatMessageRequest; +#[cfg_attr(docsrs, doc(cfg(feature = "chat-history")))] #[cfg(feature = "chat-history")] use crate::history::MessagesHistory; +#[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] /// A stream of `ChatMessageResponse` objects pub type ChatMessageResponseStream = std::pin::Pin> + Send>>; impl Ollama { + #[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] /// Chat message generation with streaming. /// Returns a stream of `ChatMessageResponse` objects @@ -101,8 +104,10 @@ impl Ollama { } } +#[cfg_attr(docsrs, doc(cfg(feature = "chat-history")))] #[cfg(feature = "chat-history")] impl Ollama { + #[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] pub async fn send_chat_messages_with_history_stream( &mut self, diff --git a/src/generation/completion/mod.rs b/src/generation/completion/mod.rs index 99382d0..bca409b 100644 --- a/src/generation/completion/mod.rs +++ b/src/generation/completion/mod.rs @@ -6,6 +6,7 @@ use request::GenerationRequest; pub mod request; +#[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] /// A stream of `GenerationResponse` objects pub type GenerationResponseStream = std::pin::Pin< @@ -16,6 +17,7 @@ pub type GenerationResponseStream = std::pin::Pin< pub type GenerationResponseStreamChunk = Vec; impl Ollama { + #[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] /// Completion generation with streaming. /// Returns a stream of `GenerationResponse` objects diff --git a/src/generation/functions/mod.rs b/src/generation/functions/mod.rs index 52d83b9..73b1206 100644 --- a/src/generation/functions/mod.rs +++ b/src/generation/functions/mod.rs @@ -19,6 +19,7 @@ use crate::generation::functions::pipelines::RequestParserBase; use crate::generation::functions::tools::Tool; use std::sync::Arc; +#[cfg_attr(docsrs, doc(cfg(feature = "function-calling")))] #[cfg(feature = "function-calling")] impl crate::Ollama { fn has_system_prompt(&self, messages: &[ChatMessage], system_prompt: &str) -> bool { @@ -30,6 +31,7 @@ impl crate::Ollama { self.get_messages_history("default").is_some() } + #[cfg_attr(docsrs, doc(cfg(feature = "chat-history")))] #[cfg(feature = "chat-history")] pub async fn send_function_call_with_history( &mut self, diff --git a/src/lib.rs b/src/lib.rs index 3dfaf7a..d27d353 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,16 @@ +#![cfg_attr(docsrs, feature(doc_cfg))] + +#[cfg_attr(docsrs, doc(cfg(feature = "chat-history")))] #[cfg(feature = "chat-history")] use crate::history::WrappedMessageHistory; use url::Url; pub mod error; pub mod generation; +#[cfg_attr(docsrs, doc(cfg(feature = "headers")))] #[cfg(feature = "headers")] pub mod headers; +#[cfg_attr(docsrs, doc(cfg(feature = "chat-history")))] #[cfg(feature = "chat-history")] pub mod history; pub mod models; diff --git a/src/models/create.rs b/src/models/create.rs index 7bc75df..9caf12c 100644 --- a/src/models/create.rs +++ b/src/models/create.rs @@ -3,12 +3,14 @@ use serde::{Deserialize, Serialize}; use crate::Ollama; /// A stream of `CreateModelStatus` objects +#[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] pub type CreateModelStatusStream = std::pin::Pin< Box> + Send>, >; impl Ollama { + #[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] /// Create a model with streaming, meaning that each new status will be streamed. pub async fn create_model_stream( diff --git a/src/models/pull.rs b/src/models/pull.rs index 201ee3a..292e7d5 100644 --- a/src/models/pull.rs +++ b/src/models/pull.rs @@ -3,12 +3,14 @@ use serde::{Deserialize, Serialize}; use crate::Ollama; /// A stream of `PullModelStatus` objects. +#[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] pub type PullModelStatusStream = std::pin::Pin< Box> + Send>, >; impl Ollama { + #[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] /// Pull a model with streaming, meaning that each new status will be streamed. /// - `model_name` - The name of the model to pull. diff --git a/src/models/push.rs b/src/models/push.rs index e3a3264..d7d851b 100644 --- a/src/models/push.rs +++ b/src/models/push.rs @@ -3,12 +3,14 @@ use serde::{Deserialize, Serialize}; use crate::Ollama; /// A stream of `PushModelStatus` objects. +#[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] pub type PushModelStatusStream = std::pin::Pin< Box> + Send>, >; impl Ollama { + #[cfg_attr(docsrs, doc(cfg(feature = "stream")))] #[cfg(feature = "stream")] /// Upload a model to a model library. Requires registering for ollama.ai and adding a public key first. /// Push a model with streaming, meaning that each new status will be streamed.