Struct Ollama

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

Implementations§

Source§

impl Ollama

Source

pub async fn send_chat_messages_stream( &self, request: ChatMessageRequest, ) -> Result<ChatMessageResponseStream>

Available on crate feature stream only.

Chat message generation with streaming. Returns a stream of ChatMessageResponse objects

Source

pub async fn send_chat_messages( &self, request: ChatMessageRequest, ) -> Result<ChatMessageResponse>

Chat message generation. Returns a ChatMessageResponse object

Source§

impl Ollama

Source

pub async fn send_chat_messages_with_history_stream<C: ChatHistory + Send + 'static>( &self, history: Arc<Mutex<C>>, request: ChatMessageRequest, ) -> Result<ChatMessageResponseStream>

Available on crate feature stream only.
Source

pub async fn send_chat_messages_with_history<C: ChatHistory>( &mut self, history: &mut C, request: ChatMessageRequest, ) -> Result<ChatMessageResponse>

Chat message generation Returns a ChatMessageResponse object

Source§

impl Ollama

Source

pub async fn generate_stream( &self, request: GenerationRequest<'_>, ) -> Result<GenerationResponseStream>

Available on crate feature stream only.

Completion generation with streaming. Returns a stream of GenerationResponse objects

Source

pub async fn generate( &self, request: GenerationRequest<'_>, ) -> Result<GenerationResponse>

Completion generation with a single response. Returns a single GenerationResponse object

Source§

impl Ollama

Source

pub async fn generate_embeddings( &self, request: GenerateEmbeddingsRequest, ) -> Result<GenerateEmbeddingsResponse>

Generate embeddings from a model

  • model_name - Name of model to generate embeddings from
  • prompt - Prompt to generate embeddings for
Source§

impl Ollama

Source

pub fn new_with_request_headers( host: impl IntoUrl, port: u16, headers: HeaderMap, ) -> Self

Available on crate feature headers only.

Creates a new Ollama instance with the specified host, port, and request headers.

§Arguments
  • host - The host of the Ollama service.
  • port - The port of the Ollama service.
  • headers - The request headers to be used.
§Returns

A new Ollama instance with the specified request headers.

§Panics

Panics if the host is not a valid URL or if the URL cannot have a port.

Source

pub fn set_headers(&mut self, headers: Option<HeaderMap>)

Available on crate feature headers only.

Sets the request headers for the Ollama instance.

§Arguments
  • headers - An optional HeaderMap containing the request headers.

If None is provided, the headers will be reset to an empty HeaderMap.

Source§

impl Ollama

Source

pub async fn copy_model( &self, source: String, destination: String, ) -> Result<()>

Copy a model. Creates a model with another name from an existing model.

Source§

impl Ollama

Source

pub async fn create_model_stream( &self, request: CreateModelRequest, ) -> Result<CreateModelStatusStream>

Available on crate feature stream only.

Create a model with streaming, meaning that each new status will be streamed.

Source

pub async fn create_model( &self, request: CreateModelRequest, ) -> Result<CreateModelStatus>

Create a model with a single response, only the final status will be returned.

Source§

impl Ollama

Source

pub async fn delete_model(&self, model_name: String) -> Result<()>

Delete a model and its data.

Source§

impl Ollama

Source

pub async fn list_local_models(&self) -> Result<Vec<LocalModel>>

Source§

impl Ollama

Source

pub async fn pull_model_stream( &self, model_name: String, allow_insecure: bool, ) -> Result<PullModelStatusStream>

Available on crate feature stream only.

Pull a model with streaming, meaning that each new status will be streamed.

  • model_name - The name of the model to pull.
  • allow_insecure - Allow insecure connections to the library. Only use this if you are pulling from your own library during development.
Source

pub async fn pull_model( &self, model_name: String, allow_insecure: bool, ) -> Result<PullModelStatus>

Pull a model with a single response, only the final status will be returned.

  • model_name - The name of the model to pull.
  • allow_insecure - Allow insecure connections to the library. Only use this if you are pulling from your own library during development.
Source§

impl Ollama

Source

pub async fn push_model_stream( &self, model_name: String, allow_insecure: bool, ) -> Result<PushModelStatusStream>

Available on crate feature stream only.

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.

  • model_name - The name of the model to push in the form of <namespace>/<model>:<tag>.
  • allow_insecure - Allow insecure connections to the library. Only use this if you are pushing to your library during development.
Source

pub async fn push_model( &self, model_name: String, allow_insecure: bool, ) -> Result<PushModelStatus>

Upload a model to a model library. Requires registering for ollama.ai and adding a public key first. Push a model with a single response, only the final status will be returned.

  • model_name - The name of the model to push in the form of <namespace>/<model>:<tag>.
  • allow_insecure - Allow insecure connections to the library. Only use this if you are pushing to your library during development.
Source§

impl Ollama

Source

pub async fn show_model_info(&self, model_name: String) -> Result<ModelInfo>

Show details about a model including modelfile, template, parameters, license, and system prompt.

Source§

impl Ollama

The main struct representing an Ollama client.

This struct is used to interact with the Ollama service.

§Fields

  • url - The base URL of the Ollama service.
  • reqwest_client - The HTTP client used for requests.
  • request_headers - Optional headers for requests (enabled with the headers feature).
Source

pub fn new(host: impl IntoUrl, port: u16) -> Self

Creates a new Ollama instance with the specified host and port.

§Arguments
  • host - The host of the Ollama service.
  • port - The port of the Ollama service.
§Returns

A new Ollama instance.

§Panics

Panics if the host is not a valid URL or if the URL cannot have a port.

Source

pub fn new_with_client( host: impl IntoUrl, port: u16, reqwest_client: Client, ) -> Self

Creates a new Ollama instance with the specified host, port, and reqwest client.

§Arguments
  • host - The host of the Ollama service.
  • port - The port of the Ollama service.
  • reqwest_client - The reqwest client instance.
§Returns

A new Ollama instance with the specified reqwest client.

§Panics

Panics if the host is not a valid URL or if the URL cannot have a port.

Source

pub fn try_new(url: impl IntoUrl) -> Result<Self, ParseError>

Attempts to create a new Ollama instance from a URL.

§Arguments
  • url - The URL of the Ollama service.
§Returns

A Result containing the new Ollama instance or a url::ParseError.

Source

pub fn from_url(url: Url) -> Self

Create new instance from a Url.

Source

pub fn uri(&self) -> String

Returns the URI of the Ollama service as a String.

§Panics

Panics if the URL does not have a host.

Source

pub fn url(&self) -> &Url

Returns a reference to the URL of the Ollama service.

Source

pub fn url_str(&self) -> &str

Returns the URL of the Ollama service as a &str.

Syntax in pseudo-BNF:

  url = scheme ":" [ hierarchical | non-hierarchical ] [ "?" query ]? [ "#" fragment ]?
  non-hierarchical = non-hierarchical-path
  non-hierarchical-path = /* Does not start with "/" */
  hierarchical = authority? hierarchical-path
  authority = "//" userinfo? host [ ":" port ]?
  userinfo = username [ ":" password ]? "@"
  hierarchical-path = [ "/" path-segment ]+

Trait Implementations§

Source§

impl Clone for Ollama

Source§

fn clone(&self) -> Ollama

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ollama

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Ollama

Source§

fn default() -> Self

Returns a default Ollama instance with the host set to http://127.0.0.1:11434.

Source§

impl From<Url> for Ollama

Source§

fn from(url: Url) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Ollama

§

impl !RefUnwindSafe for Ollama

§

impl Send for Ollama

§

impl Sync for Ollama

§

impl Unpin for Ollama

§

impl !UnwindSafe for Ollama

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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,

Source§

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

Source§

impl<T> MaybeSendSync for T