Add comprehensive RustDocs for all public API items
- Add crate-level docs with usage examples for lib.rs - Document OllamaClient, OllamaClientBuilder, and all public methods - Document error module with OllamaError variants and OllamaResult - Document types module with endpoint mapping table - Document all types in common, chat, generate, ps, pull, tags, version - Add doc examples for builders, constructors, and key types - All 26 doc-tests pass
This commit is contained in:
@@ -1,15 +1,56 @@
|
||||
//! Types for the model pull (download) endpoint (`POST /api/pull`).
|
||||
//!
|
||||
//! Use [`PullRequest::builder()`] to construct a request and pass it to
|
||||
//! [`OllamaClient::pull()`](crate::OllamaClient::pull). The response is
|
||||
//! streamed as a sequence of [`PullResponse`] status updates.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # use ollama_rs::OllamaClient;
|
||||
//! # use ollama_rs::types::pull::PullRequest;
|
||||
//! # use futures_util::StreamExt;
|
||||
//! # async fn run() -> ollama_rs::error::OllamaResult<()> {
|
||||
//! let client = OllamaClient::default();
|
||||
//! let request = PullRequest::builder("llama3").build();
|
||||
//!
|
||||
//! let mut stream = client.pull(request);
|
||||
//! while let Some(chunk) = stream.next().await {
|
||||
//! println!("{}", chunk?.status);
|
||||
//! }
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A request to download a model from the Ollama registry (`POST /api/pull`).
|
||||
///
|
||||
/// Construct via [`PullRequest::builder()`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use ollama_rs::types::pull::PullRequest;
|
||||
///
|
||||
/// let request = PullRequest::builder("llama3")
|
||||
/// .stream(true)
|
||||
/// .build();
|
||||
/// ```
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PullRequest {
|
||||
/// The model name to pull (e.g., `"llama3"`, `"llama3:latest"`).
|
||||
pub model: String,
|
||||
/// Allow insecure (HTTP) connections to the registry.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub insecure: Option<bool>,
|
||||
/// Whether to stream status updates. When `None`, the server default applies.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stream: Option<bool>,
|
||||
}
|
||||
|
||||
impl PullRequest {
|
||||
/// Returns a [`PullRequestBuilder`] for the given model name.
|
||||
pub fn builder<M: Into<String>>(model: M) -> PullRequestBuilder {
|
||||
PullRequestBuilder {
|
||||
pull_request: PullRequest {
|
||||
@@ -21,28 +62,37 @@ impl PullRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// A builder for constructing a [`PullRequest`].
|
||||
///
|
||||
/// Obtain a builder via [`PullRequest::builder()`].
|
||||
pub struct PullRequestBuilder {
|
||||
pull_request: PullRequest,
|
||||
}
|
||||
|
||||
impl PullRequestBuilder {
|
||||
/// Sets whether to stream status updates.
|
||||
pub fn stream(mut self, stream: bool) -> Self {
|
||||
self.pull_request.stream = Some(stream);
|
||||
self
|
||||
}
|
||||
|
||||
/// Allows insecure (HTTP) connections to the model registry.
|
||||
pub fn insecure(mut self, insecure: bool) -> Self {
|
||||
self.pull_request.insecure = Some(insecure);
|
||||
self
|
||||
}
|
||||
|
||||
/// Consumes the builder and returns the configured [`PullRequest`].
|
||||
pub fn build(self) -> PullRequest {
|
||||
self.pull_request
|
||||
}
|
||||
}
|
||||
|
||||
/// A streaming status update from the model pull operation.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PullResponse {
|
||||
/// A human-readable status message (e.g., `"pulling manifest"`,
|
||||
/// `"downloading sha256:..."`).
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user