MonoAI

Struct MonoAI 

Source
pub struct MonoAI { /* private fields */ }

Implementations§

Source§

impl MonoAI

Source

pub fn ollama(endpoint: String, model: String) -> Self

Create Ollama client with endpoint URL and model name

Source

pub fn anthropic(api_key: String, model: String) -> Self

Create Anthropic client with API key and model name

Source

pub fn openai(api_key: String, model: String) -> Self

Create OpenAI client with API key and model name

Source

pub fn openrouter(api_key: String, model: String) -> Self

Create OpenRouter client with API key and model name

Source

pub async fn add_tool(&mut self, tool: Tool) -> Result<(), Box<dyn Error>>

Add function tool to client. Automatically enables fallback mode for non-supporting models

Source

pub async fn is_fallback_mode(&self) -> bool

Check if client is using fallback tool calling (XML prompting vs native tools)

Source

pub fn set_debug_mode(&mut self, debug: bool)

Enable/disable debug mode to show raw tool call XML in fallback mode

Source

pub fn debug_mode(&self) -> bool

Check if debug mode is enabled

Source

pub async fn supports_tool_calls(&self) -> Result<bool, Box<dyn Error>>

Check if model supports native tool calling by examining template

Source

pub async fn send_chat_request( &self, messages: &[Message], ) -> Result<Pin<Box<dyn Stream<Item = Result<ChatStreamItem, String>> + Send>>, Box<dyn Error>>

Send chat request with real-time streaming response

Source

pub async fn send_chat_request_no_stream( &self, messages: &[Message], ) -> Result<(String, Option<Vec<ToolCall>>), Box<dyn Error>>

Send chat request without streaming, returns complete response and tool calls

Source

pub async fn send_chat_request_with_images( &self, messages: &[Message], image_paths: Vec<String>, ) -> Result<Pin<Box<dyn Stream<Item = Result<ChatStreamItem, String>> + Send>>, Box<dyn Error>>

Send chat request with images from file paths, returns real-time streaming response

Source

pub async fn send_chat_request_with_images_no_stream( &self, messages: &[Message], image_paths: Vec<String>, ) -> Result<(String, Option<Vec<ToolCall>>), Box<dyn Error>>

Send chat request with images from file paths, returns complete response and tool calls

Source

pub async fn send_chat_request_with_image_data( &self, messages: &[Message], images_data: Vec<Vec<u8>>, ) -> Result<Pin<Box<dyn Stream<Item = Result<ChatStreamItem, String>> + Send>>, Box<dyn Error>>

Send chat request with image data from memory, returns real-time streaming response (single image: vec![data], multiple: vec![data1, data2])

Source

pub async fn send_chat_request_with_image_data_no_stream( &self, messages: &[Message], images_data: Vec<Vec<u8>>, ) -> Result<(String, Option<Vec<ToolCall>>), Box<dyn Error>>

Send chat request with image data from memory, returns complete response and tool calls (single image: vec![data], multiple: vec![data1, data2])

Source

pub async fn generate(&self, prompt: &str) -> Result<String, Box<dyn Error>>

Generate single completion from prompt without conversation context

Source

pub async fn generate_stream( &self, prompt: &str, ) -> Result<Pin<Box<dyn Stream<Item = Result<String, String>> + Send>>, Box<dyn Error>>

Generate streaming completion from prompt without conversation context

Source

pub async fn get_available_models( &self, ) -> Result<Vec<MonoModel>, Box<dyn Error>>

Get available models from any provider

Source

pub async fn list_local_models(&self) -> Result<Vec<Model>, Box<dyn Error>>

List locally installed models (legacy method, use get_available_models instead)

Source

pub async fn show_model_info( &self, model_name: &str, ) -> Result<ModelInfo, Box<dyn Error>>

Get detailed model information including template and parameters

Source

pub async fn pull_model(&self, model_name: &str) -> Result<(), Box<dyn Error>>

Download model from provider registry (provider-specific operation)

Source

pub async fn pull_model_stream( &self, model_name: &str, ) -> Result<Pin<Box<dyn Stream<Item = Result<PullProgress, String>> + Send>>, Box<dyn Error>>

Download model with streaming progress updates (provider-specific operation)

Source

pub async fn handle_tool_calls(&self, tool_calls: Vec<ToolCall>) -> Vec<Message>

Execute tool calls and return formatted messages for conversation continuation

Source

pub async fn process_fallback_response( &self, content: &str, ) -> (String, Option<Vec<ToolCall>>)

Parse fallback tool calls from response content and clean XML artifacts

Source

pub fn model(&self) -> &str

Get current model name for display purposes

Source

pub fn as_ollama(&self) -> Option<&OllamaClient>

Access underlying Ollama client for provider-specific operations

Source

pub fn as_ollama_mut(&mut self) -> Option<&mut OllamaClient>

Access underlying Ollama client mutably for provider-specific operations

Source

pub fn as_anthropic(&self) -> Option<&AnthropicClient>

Access underlying Anthropic client for provider-specific operations

Source

pub fn as_anthropic_mut(&mut self) -> Option<&mut AnthropicClient>

Access underlying Anthropic client mutably for provider-specific operations

Source

pub async fn encode_image_file( &self, path: &str, ) -> Result<String, Box<dyn Error>>

Encode image file to base64 string for use in Message.images

Source

pub async fn encode_image_data( &self, bytes: Vec<u8>, ) -> Result<String, Box<dyn Error>>

Encode image bytes to base64 string for use in Message.images

Auto Trait Implementations§

§

impl Freeze for MonoAI

§

impl !RefUnwindSafe for MonoAI

§

impl Send for MonoAI

§

impl Sync for MonoAI

§

impl Unpin for MonoAI

§

impl !UnwindSafe for MonoAI

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,