ollama-sdk 0.4.1

An idiomatic, unofficial Rust client for the Ollama API with support for streaming, tool calling, and custom transports.
Documentation
use serde::{Deserialize, Serialize};

/// Represents the role of a message sender in a chat conversation.
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Role {
    /// The system role, typically used for initial instructions or context.
    System,
    /// The user role, representing messages from the end-user.
    #[default]
    User,
    /// The assistant role, representing messages generated by the model.
    Assistant,
    /// The tool role, representing output from a tool call.
    Tool,
}

/// Specifies the "thinking" level for the model.
///
/// This can be a simple boolean to enable/disable thinking,
/// or a specific level (High, Medium, Low).
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum Thinking {
    /// A boolean value to enable (`true`) or disable (`false`) thinking.
    Boolean(bool),
    /// A specific thinking level.
    Level(ThinkingLevel),
}

impl Default for Thinking {
    fn default() -> Self {
        Self::Boolean(false)
    }
}

/// Defines the different levels of "thinking" for the model.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "lowercase")]
pub enum ThinkingLevel {
    /// High thinking level.
    High,
    /// Medium thinking level.
    Medium,
    /// Low thinking level.
    Low,
}

/// Represents an error response from the Ollama API.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct OllamaError {
    /// The error message.
    pub error: String,
}