ollama-haskell
Copyright(c) 2025 Tushar Adhatrao
LicenseMIT
MaintainerTushar Adhatrao <tusharadhatrao@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Ollama

Description

Ollama Haskell

This module provides a high-level Haskell interface to the Ollama API for interacting with local LLMs. It includes support for:

  • Text generation (sync/streaming)
  • Conversational chat (with tools and images)
  • Embeddings
  • Model management (pull, push, delete, list, show)
  • Structured outputs
  • Custom configuration and model options

Inspired by ollama-python, this library is built to offer idiomatic Haskell bindings over Ollama’s HTTP API.

🔧 Usage

Import this module as a top-level interface:

import Ollama 

All functions return Either OllamaError a or can be used in a Monad stack using their *M variants.

🔑 Main APIs

✍️ Generate Text

💬 Chat with LLMs

🧠 Embeddings

📦 Model Management

⚙️ Configuration

🧰 Utilities

🧾 Types

All request/response payloads and enums are exposed, including:

Synopsis

Main APIs

Generate Texts

generate :: GenerateOps -> Maybe OllamaConfig -> IO (Either OllamaError GenerateResponse) Source #

Generates text using the specified model and configuration.

Validates the GenerateOps configuration and sends a POST request to the /api/generate endpoint. Supports both streaming and non-streaming responses based on the stream field in GenerateOps. Returns Right with a GenerateResponse on success or Left with an OllamaError on failure.

Example:

>>> let ops = defaultGenerateOps { modelName = "gemma3", prompt = "Write a short poem." } >>> generate ops Nothing Right (GenerateResponse ...) 

generateM :: MonadIO m => GenerateOps -> Maybe OllamaConfig -> m (Either OllamaError GenerateResponse) Source #

MonadIO version of generate for use in monadic contexts.

Lifts the generate function into a MonadIO context, allowing it to be used in monadic computations.

Example:

>>> import Control.Monad.IO.Class >>> let ops = defaultGenerateOps { modelName = "gemma3", prompt = "Hello!" } >>> runReaderT (generateM ops Nothing) someContext Right (GenerateResponse ...) 

defaultGenerateOps :: GenerateOps Source #

Default configuration for text generation.

Provides a default GenerateOps with the "gemma3" model and an empty prompt. Other fields are set to Nothing or default values. Can be customized by modifying fields as needed.

Example:

>>> let ops = defaultGenerateOps { modelName = "customModel", prompt = "Hello!" } >>> generate ops Nothing 

data GenerateOps Source #

Configuration for a text generation request.

Constructors

GenerateOps 

Fields

  • modelName :: !Text

    The name of the model to use for generation (e.g., "gemma3").

  • prompt :: !Text

    The prompt text to provide to the model for generating a response.

  • suffix :: Maybe Text

    Optional suffix to append to the generated text (not supported by all models).

  • images :: !(Maybe [Text])

    Optional list of Base64-encoded images to include with the request.

  • format :: !(Maybe Format)

    Optional format specifier for the response (e.g., JSON).

    Since: 0.1.3.0

  • system :: !(Maybe Text)

    Optional system text to include in the generation context.

  • template :: !(Maybe Text)

    Optional template to format the response.

  • stream :: !(Maybe (GenerateResponse -> IO (), IO ()))

    Optional callback function to be called with each incoming response.

  • raw :: !(Maybe Bool)

    Optional flag to return the raw response.

  • keepAlive :: !(Maybe Int)

    Optional override for how long (in minutes) the model stays loaded in memory (default: 5 minutes).

  • options :: !(Maybe ModelOptions)

    Optional model parameters (e.g., temperature) as specified in the Modelfile.

    Since: 0.1.3.0

  • think :: !(Maybe Bool)

    Optional flag to enable thinking mode.

    Since: 0.2.0.0

data GenerateResponse Source #

Result type for generate function containing the model's response and meta-information.

Constructors

GenerateResponse 

Fields

  • model :: !Text

    The name of the model that generated the response.

  • createdAt :: !UTCTime

    The timestamp when the response was created.

  • genResponse :: !Text

    The generated response from the model.

  • done :: !Bool

    A flag indicating whether the generation process is complete.

  • totalDuration :: !(Maybe Int64)

    Optional total duration in milliseconds for the generation process.

  • loadDuration :: !(Maybe Int64)

    Optional load duration in milliseconds for loading the model.

  • promptEvalCount :: !(Maybe Int64)

    Optional count of prompt evaluations during the generation process.

  • promptEvalDuration :: !(Maybe Int64)

    Optional duration in milliseconds for evaluating the prompt.

  • evalCount :: !(Maybe Int64)

    Optional count of evaluations during the generation process.

  • evalDuration :: !(Maybe Int64)

    Optional duration in milliseconds for evaluations during the generation process.

  • thinking :: !(Maybe Text)

    Thinking of reasoning models; if think is set to true

    Since: 0.2.0.0

  • doneReason :: !(Maybe Text)

    Reason why the generation process completed (e.g., "stop", "length", "cancel"). Available when the Ollama server provides completion reason information.

    Since: 0.2.1.0

Chat with LLMs

chat :: ChatOps -> Maybe OllamaConfig -> IO (Either OllamaError ChatResponse) Source #

Sends a chat request to the Ollama API.

Validates the ChatOps configuration and sends a POST request to the /api/chat endpoint. Supports both streaming and non-streaming responses based on the stream field in ChatOps. Returns an Either containing an OllamaError on failure or a ChatResponse on success.

Example:

>>> let ops = defaultChatOps { chatModelName = "gemma3", messages = userMessage "What's the capital of France?" :| [] } >>> chat ops Nothing Either OllamaError ChatResponse 

chatM :: MonadIO m => ChatOps -> Maybe OllamaConfig -> m (Either OllamaError ChatResponse) Source #

MonadIO version of chat for use in monadic contexts.

Lifts the chat function into a MonadIO context, allowing it to be used in monadic computations.

Example:

>>> import Control.Monad.IO.Class >>> let ops = defaultChatOps { chatModelName = "gemma3", messages = userMessage "Hello!" :| [] } >>> runReaderT (chatM ops Nothing) someContext Either OllamaError ChatResponse 

data Role Source #

Enumerated roles that can participate in a chat.

Constructors

System 
User 
Assistant 
Tool 

Instances

Instances details
FromJSON Role Source # 
Instance details

Defined in Data.Ollama.Common.Types

ToJSON Role Source # 
Instance details

Defined in Data.Ollama.Common.Types

Show Role Source # 
Instance details

Defined in Data.Ollama.Common.Types

Methods

showsPrec :: Int -> Role -> ShowS #

show :: Role -> String #

showList :: [Role] -> ShowS #

Eq Role Source # 
Instance details

Defined in Data.Ollama.Common.Types

Methods

(==) :: Role -> Role -> Bool #

(/=) :: Role -> Role -> Bool #

defaultChatOps :: ChatOps Source #

Default configuration for initiating a chat.

Provides a default ChatOps with the "gemma3" model and a sample user message ("What is 2+2?"). Can be customized by modifying fields as needed.

Example:

>>> let ops = defaultChatOps { chatModelName = "customModel", messages = userMessage "Hello!" :| [] } >>> chat ops Nothing Either OllamaError ChatResponse 

data ChatResponse Source #

Constructors

ChatResponse 

Fields

data ChatOps Source #

Configuration for initiating a chat with an Ollama model.

Defines the parameters for a chat request, including the model name, messages, and optional settings for tools, response format, streaming, timeout, and model options.

Constructors

ChatOps 

Fields

Instances

Instances details
ToJSON ChatOps Source # 
Instance details

Defined in Data.Ollama.Chat

Show ChatOps Source # 
Instance details

Defined in Data.Ollama.Chat

Eq ChatOps Source # 
Instance details

Defined in Data.Ollama.Chat

Methods

(==) :: ChatOps -> ChatOps -> Bool #

(/=) :: ChatOps -> ChatOps -> Bool #

data InputTool Source #

Represents a tool that can be used in the conversation.

Since: 0.2.0.0

Constructors

InputTool 

Fields

Instances

Instances details
FromJSON InputTool Source # 
Instance details

Defined in Data.Ollama.Common.Types

ToJSON InputTool Source # 
Instance details

Defined in Data.Ollama.Common.Types

Generic InputTool Source # 
Instance details

Defined in Data.Ollama.Common.Types

Associated Types

type Rep InputTool 
Instance details

Defined in Data.Ollama.Common.Types

type Rep InputTool = D1 ('MetaData "InputTool" "Data.Ollama.Common.Types" "ollama-haskell-0.2.1.0-inplace" 'False) (C1 ('MetaCons "InputTool" 'PrefixI 'True) (S1 ('MetaSel ('Just "toolType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "function") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FunctionDef)))
Show InputTool Source # 
Instance details

Defined in Data.Ollama.Common.Types

Eq InputTool Source # 
Instance details

Defined in Data.Ollama.Common.Types

type Rep InputTool Source # 
Instance details

Defined in Data.Ollama.Common.Types

type Rep InputTool = D1 ('MetaData "InputTool" "Data.Ollama.Common.Types" "ollama-haskell-0.2.1.0-inplace" 'False) (C1 ('MetaCons "InputTool" 'PrefixI 'True) (S1 ('MetaSel ('Just "toolType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "function") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FunctionDef)))

data FunctionDef Source #

Represents a function that can be called by the model.

Since: 0.2.0.0

Constructors

FunctionDef 

Fields

Instances

Instances details
FromJSON FunctionDef Source # 
Instance details

Defined in Data.Ollama.Common.Types

ToJSON FunctionDef Source # 
Instance details

Defined in Data.Ollama.Common.Types

Generic FunctionDef Source # 
Instance details

Defined in Data.Ollama.Common.Types

Associated Types

type Rep FunctionDef 
Instance details

Defined in Data.Ollama.Common.Types

type Rep FunctionDef = D1 ('MetaData "FunctionDef" "Data.Ollama.Common.Types" "ollama-haskell-0.2.1.0-inplace" 'False) (C1 ('MetaCons "FunctionDef" 'PrefixI 'True) ((S1 ('MetaSel ('Just "functionName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "functionDescription") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))) :*: (S1 ('MetaSel ('Just "functionParameters") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe FunctionParameters)) :*: S1 ('MetaSel ('Just "functionStrict") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Bool)))))
Show FunctionDef Source # 
Instance details

Defined in Data.Ollama.Common.Types

Eq FunctionDef Source # 
Instance details

Defined in Data.Ollama.Common.Types

type Rep FunctionDef Source # 
Instance details

Defined in Data.Ollama.Common.Types

type Rep FunctionDef = D1 ('MetaData "FunctionDef" "Data.Ollama.Common.Types" "ollama-haskell-0.2.1.0-inplace" 'False) (C1 ('MetaCons "FunctionDef" 'PrefixI 'True) ((S1 ('MetaSel ('Just "functionName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "functionDescription") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))) :*: (S1 ('MetaSel ('Just "functionParameters") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe FunctionParameters)) :*: S1 ('MetaSel ('Just "functionStrict") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Bool)))))

data FunctionParameters Source #

Parameters definition for a function call used in structured output or tool calls.

Since: 0.2.0.0

Constructors

FunctionParameters 

Fields

newtype ToolCall Source #

A single tool call returned from the model, containing the function to be invoked.

Since: 0.2.0.0

Constructors

ToolCall 

Fields

data OutputFunction Source #

Output representation of a function to be called, including its name and arguments.

Since: 0.2.0.0

Constructors

OutputFunction 

Fields

Embeddings

embedding Source #

Arguments

:: Text

Model name

-> [Text]

List of input texts

-> IO (Either OllamaError EmbeddingResp) 

Simplified API for generating embeddings.

A higher-level function that generates embeddings using default settings for truncation, keep-alive, model options, and Ollama configuration. Suitable for basic use cases.

embeddingOps Source #

Arguments

:: Text

Model name

-> [Text]

List of input texts

-> Maybe Bool

Optional truncation flag

-> Maybe Int

Optional keep-alive timeout in minutes

-> Maybe ModelOptions

Optional model options

-> Maybe Int

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> Maybe OllamaConfig 
-> IO (Either OllamaError EmbeddingResp) 

Generates embeddings for a list of input texts with full configuration.

Sends a POST request to the /api/embed endpoint to generate embeddings for the provided inputs. Allows customization of truncation, keep-alive settings, model options, and Ollama configuration. Returns Right with an EmbeddingResp on success or Left with an OllamaError on failure.

embeddingM :: MonadIO m => Text -> [Text] -> m (Either OllamaError EmbeddingResp) Source #

MonadIO version of embedding for use in monadic contexts.

Lifts the embedding function into a MonadIO context, allowing it to be used in monadic computations.

embeddingOpsM :: MonadIO m => Text -> [Text] -> Maybe Bool -> Maybe Int -> Maybe ModelOptions -> Maybe Int -> Maybe OllamaConfig -> m (Either OllamaError EmbeddingResp) Source #

MonadIO version of embeddingOps for use in monadic contexts.

Lifts the embeddingOps function into a MonadIO context, allowing it to be used in monadic computations with full configuration options.

data EmbeddingOps Source #

Configuration for an embedding request.

data EmbeddingResp Source #

Response type for an embedding request.

Constructors

EmbeddingResp 

Fields

Copy Models

copyModel Source #

Arguments

:: Text

Source model name

-> Text

Destination model name

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError ()) 

Copies a model from a source name to a destination name.

Sends a POST request to the /api/copy endpoint with the source and destination model names. Returns 'Right ()' on success or Left with an OllamaError on failure. Example:

>>> copyModel "gemma3" "gemma3-copy" Nothing Right () 

copyModelM :: MonadIO m => Text -> Text -> Maybe OllamaConfig -> m (Either OllamaError ()) Source #

MonadIO version of copyModel for use in monadic contexts.

Lifts the copyModel function into a MonadIO context, allowing it to be used in monadic computations.

Example:

>>> import Control.Monad.IO.Class >>> runReaderT (copyModelM "gemma3" "gemma3-copy" Nothing) someContext Right () 

Create Models

createModel Source #

Arguments

:: CreateOps

Model creation configuration

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO () 

Creates a new model according to the provided configuration.

Sends a POST request to the /api/create endpoint to create a model. The model can be created from:

  • Another existing model (specify fromModel)
  • A safetensors directory (specify files with file name to SHA256 digest mappings)
  • A GGUF file (specify files with file name to SHA256 digest mapping)

Supports quantization, custom templates, system prompts, parameters, and LORA adapters. Prints progress messages to the console during creation.

createModelM :: MonadIO m => CreateOps -> Maybe OllamaConfig -> m () Source #

MonadIO version of createModel for use in monadic contexts.

Lifts the createModel function into a MonadIO context, allowing it to be used in monadic computations.

Delete Models

deleteModel Source #

Arguments

:: Text

Model name to delete

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError ()) 

Deletes a model from the Ollama server.

Sends a DELETE request to the "apidelete" endpoint with the specified model name. Returns 'Right ()' on success or Left with an OllamaError on failure.

deleteModelM :: MonadIO m => Text -> Maybe OllamaConfig -> m (Either OllamaError ()) Source #

MonadIO version of deleteModel for use in monadic contexts.

Lifts the deleteModel function into a context, allowing it to be used in monadic computations.

List Models

list Source #

Arguments

:: Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError Models) 

Retrieves a list of available models from the Ollama server.

Sends a GET request to the /api/tags endpoint to fetch the list of models. Returns Right with a Models containing the list of ModelInfo on success, or Left with an OllamaError on failure.

List currently running models

ps Source #

Arguments

:: Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError RunningModels) 

Retrieves a list of currently running models from the Ollama server.

Sends a GET request to the /api/ps endpoint to fetch the list of running models. Returns Right with a RunningModels containing the list of RunningModel on success, or Left with an OllamaError on failure. Example:

>>> ps Nothing Right (RunningModels [RunningModel {name_ = "gemma3:instance1", modelName = "gemma3", ...}]) 

psM :: MonadIO m => Maybe OllamaConfig -> m (Either OllamaError RunningModels) Source #

MonadIO version of ps for use in monadic contexts.

Lifts the ps function into a MonadIO context, allowing it to be used in monadic computations.

Push and Pull

push Source #

Arguments

:: Text

Model name

-> Maybe Bool

Optional insecure connection flag

-> Maybe Bool

Optional streaming flag

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO () 

Pushes a model to the Ollama server with specified options.

Sends a POST request to the /api/pull endpoint to upload the specified model. Supports streaming progress updates (if stream is 'Just True') and insecure connections (if insecure is 'Just True'). Prints "Pushing..." during streaming and Completed when finished. Returns () on completion.

pushM :: MonadIO m => Text -> Maybe Bool -> Maybe Bool -> Maybe OllamaConfig -> m () Source #

MonadIO version of push for use in monadic contexts.

Lifts the push function into a MonadIO context, allowing it to be used in monadic computations.

Example:

>>> import Control.Monad.IO.Class >>> runReaderT (pushM "gemma3" Nothing (Just True) Nothing) someContext Pushing... Completed 

pull Source #

Arguments

:: Text

Model name

-> IO (Either OllamaError PullResp) 

Simplified API for pulling a model.

A higher-level function that pulls a model using default settings for insecure connections, streaming, and Ollama configuration. Suitable for basic use cases.

pullM :: MonadIO m => Text -> m (Either OllamaError PullResp) Source #

MonadIO version of pull for use in monadic contexts.

Lifts the pull function into a MonadIO context, allowing it to be used in monadic computations.

Example:

>>> import Control.Monad.IO.Class >>> runReaderT (pullM "gemma3") someContext Right (PullResp {status = "success", ...}) 

pullOps Source #

Arguments

:: Text

Model name

-> Maybe Bool

Optional insecure connection flag

-> Maybe Bool

Optional streaming flag

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError PullResp) 

Pulls a model with full configuration.

Sends a POST request to the /api/pull endpoint to download the specified model. Supports streaming progress updates (if stream is 'Just True') and insecure connections (if insecure is 'Just True'). Prints remaining bytes during streaming and Completed when finished. Returns Right with a PullResp on success or Left with an OllamaError on failure.

pullOpsM :: MonadIO m => Text -> Maybe Bool -> Maybe Bool -> Maybe OllamaConfig -> m (Either OllamaError PullResp) Source #

MonadIO version of pullOps for use in monadic contexts.

Lifts the pullOps function into a MonadIO context, allowing it to be used in monadic computations with full configuration options.

Example:

>>> import Control.Monad.IO.Class >>> runReaderT (pullOpsM "gemma3" Nothing (Just True) Nothing) someContext Remaining bytes: 123456789 ... Completed Right (PullResp {status = "success", ...}) 

Show Model Info

showModel Source #

Arguments

:: Text

Model name

-> IO (Either OllamaError ShowModelResponse) 

Simplified API for retrieving model information.

A higher-level function that fetches model information using default settings for verbose output and Ollama configuration. Suitable for basic use cases.

showModelOps Source #

Arguments

:: Text

Model name

-> Maybe Bool

Optional verbose flag

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError ShowModelResponse) 

Retrieves model information with configuration options.

Sends a POST request to the /api/show endpoint to fetch detailed information about the specified model. Supports verbose output if verbose is 'Just True' (though verbose mode parsing is currently incomplete). Returns Right with a ShowModelResponse on success or Left with an OllamaError on failure.

showModelM :: MonadIO m => Text -> m (Either OllamaError ShowModelResponse) Source #

MonadIO version of showModel for use in monadic contexts.

Lifts the showModel function into a MonadIO context, allowing it to be used in monadic computations.

showModelOpsM :: MonadIO m => Text -> Maybe Bool -> Maybe OllamaConfig -> m (Either OllamaError ShowModelResponse) Source #

MonadIO version of showModelOps for use in monadic contexts.

Lifts the showModelOps function into a MonadIO context, allowing it to be used in monadic computations with full configuration options.

Blob Operations

checkBlobExists Source #

Arguments

:: Text

SHA256 digest of the blob (without "sha256:" prefix)

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError Bool) 

Check if a blob exists on the Ollama server.

Sends a HEAD request to /api/blobs/sha256:<digest> to check if a blob with the given SHA256 digest exists on the server.

Returns: - Right True if the blob exists (HTTP 200 OK) - Right False if the blob does not exist (HTTP 404 Not Found) - Left OllamaError for other errors (network issues, invalid digest, etc.)

The digest should be a SHA256 hash string without the "sha256:" prefix.

createBlob Source #

Arguments

:: FilePath

Path to the file to upload

-> Text

Expected SHA256 digest of the file (without "sha256:" prefix)

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig if Nothing)

-> IO (Either OllamaError ()) 

Upload a file as a blob to the Ollama server.

Streams the contents of the file at the given FilePath to the Ollama server via a POST request to /api/blobs/sha256:<digest>. The server will verify that the uploaded file matches the expected SHA256 digest.

Returns: - Right () if the blob was uploaded successfully (HTTP 201 Created) - Left OllamaError if the upload failed

The digest should be the expected SHA256 hash of the file without the "sha256:" prefix. If the file content doesn't match the digest, the server will return an error.

Note: This function streams the file content, so it can handle large files efficiently without loading them entirely into memory.

Ollama config

defaultOllamaConfig :: OllamaConfig Source #

A default configuration pointing to localhost:11434 with 90s timeout and no hooks or retry logic.

withOnModelStart :: IO () -> OllamaConfig -> OllamaConfig Source #

Add a callback to be executed when a model starts.

withOnModelFinish :: IO () -> OllamaConfig -> OllamaConfig Source #

Add a callback to be executed when a model finishes successfully.

withOnModelError :: IO () -> OllamaConfig -> OllamaConfig Source #

Add a callback to be executed when a model errors.

Utils

defaultModelOptions :: ModelOptions Source #

Default model options for API requests.

Provides a default ModelOptions configuration with all fields set to Nothing, suitable as a starting point for customizing model parameters like temperature or token limits.

Example:

>>> let opts = defaultModelOptions { temperature = Just 0.7 } 

data ModelOptions Source #

Optional model tuning parameters that influence generation behavior.

Since: 0.2.0.0

Constructors

ModelOptions 

Fields

Instances

Instances details
ToJSON ModelOptions Source #

Custom ToJSON instance for Options

Instance details

Defined in Data.Ollama.Common.Types

Show ModelOptions Source # 
Instance details

Defined in Data.Ollama.Common.Types

Eq ModelOptions Source # 
Instance details

Defined in Data.Ollama.Common.Types

encodeImage :: FilePath -> IO (Maybe Text) Source #

Encodes an image file to Base64 format.

Takes a file path to an image (jpg, jpeg, or png) and returns its data encoded as a Base64 Text. Returns Nothing if the file extension is unsupported or the file cannot be read. This is useful for including images in API requests that expect Base64-encoded data, such as GenerateOps images field.

withOllamaRequest Source #

Arguments

:: ToJSON payload 
=> Text

API endpoint

-> ByteString

HTTP method (GET or POST)

-> Maybe payload

Optional request payload (must implement ToJSON)

-> Maybe OllamaConfig

Optional OllamaConfig (defaults to defaultOllamaConfig)

-> (Response BodyReader -> IO (Either OllamaError response))

Response handler to process the HTTP response

-> IO (Either OllamaError response) 

Sends an HTTP request to the Ollama API.

A unified function for making API requests to the Ollama server. Supports both GET and POST methods, customizable payloads, and optional configuration. The response is processed by the provided handler.

getVersion :: IO (Either OllamaError Version) Source #

Retrieves the Ollama server version.

Sends a GET request to the /api/version endpoint and returns the server version as a Version wrapped in an Either OllamaError.

Example:

>>> getVersion 

Since: 0.2.0.0

loadGenModel Source #

Arguments

:: Text

Model name (e.g., "gemma3")

-> IO (Either OllamaError ()) 

Loads a generative model into memory.

Sends a POST request to the /api/generate endpoint to load the specified model into memory, ensuring faster response times for subsequent requests. Returns 'Right ()' on success or Left with an OllamaError on failure.

Since: 0.2.0.0

unloadGenModel Source #

Arguments

:: Text

Model name (e.g., "gemma3")

-> IO (Either OllamaError ()) 

Unloads a generative model from memory.

Sends a POST request to the /api/generate endpoint with a keep-alive duration of zero to unload the specified model from memory, freeing up resources. Returns 'Right ()' on success or Left with an OllamaError on failure.

Since: 0.2.0.0

loadGenModelM :: MonadIO m => Text -> m (Either OllamaError ()) Source #

MonadIO version of loadGenModel for use in monadic contexts.

Lifts the loadGenModel function into a MonadIO context, allowing it to be used in monadic computations.

Example:

>>> import Control.Monad.IO.Class >>> runReaderT (loadGenModelM "gemma3") someContext Right () 

Since: 0.2.0.0

unloadGenModelM :: MonadIO m => Text -> m (Either OllamaError ()) Source #

MonadIO version of unloadGenModel for use in monadic contexts.

Lifts the unloadGenModel function into a MonadIO context, allowing it to be used in monadic computations.

Example:

>>> import Control.Monad.IO.Class >>> runReaderT (unloadGenModelM "gemma3") someContext Right () 

Since: 0.2.0.0

Types

data ShowModelResponse Source #

Response structure for model information.

Constructors

ShowModelResponse 

Fields

newtype Models Source #

A wrapper type containing a list of available models.

Constructors

Models [ModelInfo]

List of ModelInfo records describing available models.

Instances

Instances details
FromJSON Models Source #

JSON parsing instance for Models.

Instance details

Defined in Data.Ollama.List

Show Models Source # 
Instance details

Defined in Data.Ollama.List

Eq Models Source # 
Instance details

Defined in Data.Ollama.List

Methods

(==) :: Models -> Models -> Bool #

(/=) :: Models -> Models -> Bool #

data ModelInfo Source #

Details about a specific model.

Constructors

ModelInfo 

Fields

Instances

Instances details
FromJSON ModelInfo Source #

JSON parsing instance for ModelInfo.

Instance details

Defined in Data.Ollama.List

Show ModelInfo Source # 
Instance details

Defined in Data.Ollama.List

Eq ModelInfo Source # 
Instance details

Defined in Data.Ollama.List

data ModelDetails Source #

Metadata describing a specific model's identity and configuration.

Constructors

ModelDetails 

Fields

data ShowModelInfo Source #

Detailed technical information about a model.

Constructors

ShowModelInfo 

Fields

Instances

Instances details
FromJSON ShowModelInfo Source #

JSON parsing instance for ShowModelInfo.

Instance details

Defined in Data.Ollama.Show

Show ShowModelInfo Source # 
Instance details

Defined in Data.Ollama.Show

Eq ShowModelInfo Source # 
Instance details

Defined in Data.Ollama.Show

newtype RunningModels Source #

A wrapper type containing a list of running models.

Constructors

RunningModels [RunningModel]

List of RunningModel records describing currently running models.

Instances

Instances details
FromJSON RunningModels Source #

JSON parsing instance for RunningModels.

Instance details

Defined in Data.Ollama.Ps

Show RunningModels Source # 
Instance details

Defined in Data.Ollama.Ps

Eq RunningModels Source # 
Instance details

Defined in Data.Ollama.Ps

data RunningModel Source #

Details about a specific running model.

Instances

Instances details
FromJSON RunningModel Source #

JSON parsing instance for RunningModel.

Instance details

Defined in Data.Ollama.Ps

Show RunningModel Source # 
Instance details

Defined in Data.Ollama.Ps

Eq RunningModel Source # 
Instance details

Defined in Data.Ollama.Ps

data Message Source #

Represents a message within a chat, including its role and content.

Constructors

Message 

Fields

Instances

Instances details
FromJSON Message Source # 
Instance details

Defined in Data.Ollama.Common.Types

ToJSON Message Source # 
Instance details

Defined in Data.Ollama.Common.Types

Generic Message Source # 
Instance details

Defined in Data.Ollama.Common.Types

Associated Types

type Rep Message 
Instance details

Defined in Data.Ollama.Common.Types

type Rep Message = D1 ('MetaData "Message" "Data.Ollama.Common.Types" "ollama-haskell-0.2.1.0-inplace" 'False) (C1 ('MetaCons "Message" 'PrefixI 'True) ((S1 ('MetaSel ('Just "role") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Role) :*: S1 ('MetaSel ('Just "content") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "images") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe [Text])) :*: (S1 ('MetaSel ('Just "tool_calls") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe [ToolCall])) :*: S1 ('MetaSel ('Just "thinking") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Text))))))

Methods

from :: Message -> Rep Message x #

to :: Rep Message x -> Message #

Show Message Source # 
Instance details

Defined in Data.Ollama.Common.Types

Eq Message Source # 
Instance details

Defined in Data.Ollama.Common.Types

Methods

(==) :: Message -> Message -> Bool #

(/=) :: Message -> Message -> Bool #

type Rep Message Source # 
Instance details

Defined in Data.Ollama.Common.Types

type Rep Message = D1 ('MetaData "Message" "Data.Ollama.Common.Types" "ollama-haskell-0.2.1.0-inplace" 'False) (C1 ('MetaCons "Message" 'PrefixI 'True) ((S1 ('MetaSel ('Just "role") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Role) :*: S1 ('MetaSel ('Just "content") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "images") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe [Text])) :*: (S1 ('MetaSel ('Just "tool_calls") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe [ToolCall])) :*: S1 ('MetaSel ('Just "thinking") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Text))))))

data Format Source #

Format specification for the chat output.

Since: 0.1.3.0

Instances

Instances details
ToJSON Format Source # 
Instance details

Defined in Data.Ollama.Common.Types

Show Format Source # 
Instance details

Defined in Data.Ollama.Common.Types

Eq Format Source # 
Instance details

Defined in Data.Ollama.Common.Types

Methods

(==) :: Format -> Format -> Bool #

(/=) :: Format -> Format -> Bool #

data OllamaError Source #

Represents all possible errors that may occur when using the Ollama client.

Since: 0.2.0.0

Constructors

HttpError HttpException

Low-level HTTP exception (connection failure, etc.)

DecodeError DecodingErrorMessage DecodingFailedValue

Failure to decode a JSON response, includes message and raw value

ApiError Text

Error returned from Ollama's HTTP API

FileError IOException

Error during file operations (e.g., loading an image)

JsonSchemaError String

Mismatch in expected JSON schema or structure

TimeoutError String

Request timed out

InvalidRequest String

Request is malformed or violates input constraints

Instances

Instances details
Exception OllamaError Source # 
Instance details

Defined in Data.Ollama.Common.Error

Generic OllamaError Source # 
Instance details

Defined in Data.Ollama.Common.Error

Show OllamaError Source # 
Instance details

Defined in Data.Ollama.Common.Error

Eq OllamaError Source # 
Instance details

Defined in Data.Ollama.Common.Error

type Rep OllamaError Source # 
Instance details

Defined in Data.Ollama.Common.Error

data OllamaConfig Source #

Configuration for the Ollama client. Used across all requests to customize behavior such as timeouts, retries, custom HTTP manager, and lifecycle hooks.

Since: 0.2.0.0

Constructors

OllamaConfig 

Fields

Instances

Instances details
Generic OllamaConfig Source # 
Instance details

Defined in Data.Ollama.Common.Config

Associated Types

type Rep OllamaConfig 
Instance details

Defined in Data.Ollama.Common.Config

type Rep OllamaConfig Source # 
Instance details

Defined in Data.Ollama.Common.Config

newtype Version Source #

A wrapper for the Ollama engine version string.

Constructors

Version Text 

Instances

Instances details
FromJSON Version Source # 
Instance details

Defined in Data.Ollama.Common.Types

Show Version Source # 
Instance details

Defined in Data.Ollama.Common.Types

Eq Version Source # 
Instance details

Defined in Data.Ollama.Common.Types

Methods

(==) :: Version -> Version -> Bool #

(/=) :: Version -> Version -> Bool #