| Copyright | (c) 2025 Tushar Adhatrao |
|---|---|
| License | MIT |
| Maintainer | Tushar Adhatrao <tusharadhatrao@gmail.com> |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
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
generate,generateM– Generate text from a modeldefaultGenerateOps– Default generation parametersGenerateOps,GenerateResponse– Request and response types
💬 Chat with LLMs
chat,chatM– Send chat messages to a modelChatOps,ChatResponse,Role,Message– Chat input/output types- Supports tools via
InputTool,FunctionDef,OutputFunction, etc.
🧠 Embeddings
embedding,embeddingM– Generate vector embeddingsEmbeddingOps,EmbeddingResp– Request/response types
📦 Model Management
copyModel,createModel,deleteModellist– List all installed modelsps,psM– Show running modelsshowModel,showModelM– Show model infopull,push– Pull/push models (with progress support)
⚙️ Configuration
defaultOllamaConfig– Modify host, retries, streaming, etc.withOnModelStart,withOnModelFinish,withOnModelError– Hook support
🧰 Utilities
defaultModelOptions,encodeImage,withOllamaRequestloadGenModel,unloadGenModel– Load/unload generation modelsgetVersion– Ollama server version
🧾 Types
All request/response payloads and enums are exposed, including:
Synopsis
- generate :: GenerateOps -> Maybe OllamaConfig -> IO (Either OllamaError GenerateResponse)
- generateM :: MonadIO m => GenerateOps -> Maybe OllamaConfig -> m (Either OllamaError GenerateResponse)
- defaultGenerateOps :: GenerateOps
- data GenerateOps = GenerateOps {
- modelName :: !Text
- prompt :: !Text
- suffix :: Maybe Text
- images :: !(Maybe [Text])
- format :: !(Maybe Format)
- system :: !(Maybe Text)
- template :: !(Maybe Text)
- stream :: !(Maybe (GenerateResponse -> IO (), IO ()))
- raw :: !(Maybe Bool)
- keepAlive :: !(Maybe Int)
- options :: !(Maybe ModelOptions)
- think :: !(Maybe Bool)
- data GenerateResponse = GenerateResponse {
- model :: !Text
- createdAt :: !UTCTime
- genResponse :: !Text
- done :: !Bool
- totalDuration :: !(Maybe Int64)
- loadDuration :: !(Maybe Int64)
- promptEvalCount :: !(Maybe Int64)
- promptEvalDuration :: !(Maybe Int64)
- evalCount :: !(Maybe Int64)
- evalDuration :: !(Maybe Int64)
- thinking :: !(Maybe Text)
- doneReason :: !(Maybe Text)
- chat :: ChatOps -> Maybe OllamaConfig -> IO (Either OllamaError ChatResponse)
- chatM :: MonadIO m => ChatOps -> Maybe OllamaConfig -> m (Either OllamaError ChatResponse)
- data Role
- defaultChatOps :: ChatOps
- data ChatResponse = ChatResponse {
- model :: !Text
- createdAt :: !UTCTime
- message :: !(Maybe Message)
- done :: !Bool
- totalDuration :: !(Maybe Int64)
- loadDuration :: !(Maybe Int64)
- promptEvalCount :: !(Maybe Int64)
- promptEvalDuration :: !(Maybe Int64)
- evalCount :: !(Maybe Int64)
- evalDuration :: !(Maybe Int64)
- doneReason :: !(Maybe Text)
- data ChatOps = ChatOps {}
- data InputTool = InputTool {
- toolType :: Text
- function :: FunctionDef
- data FunctionDef = FunctionDef {}
- data FunctionParameters = FunctionParameters {}
- newtype ToolCall = ToolCall {}
- data OutputFunction = OutputFunction {}
- embedding :: Text -> [Text] -> IO (Either OllamaError EmbeddingResp)
- embeddingOps :: Text -> [Text] -> Maybe Bool -> Maybe Int -> Maybe ModelOptions -> Maybe Int -> Maybe OllamaConfig -> IO (Either OllamaError EmbeddingResp)
- embeddingM :: MonadIO m => Text -> [Text] -> m (Either OllamaError EmbeddingResp)
- embeddingOpsM :: MonadIO m => Text -> [Text] -> Maybe Bool -> Maybe Int -> Maybe ModelOptions -> Maybe Int -> Maybe OllamaConfig -> m (Either OllamaError EmbeddingResp)
- data EmbeddingOps = EmbeddingOps !Text ![Text] !(Maybe Bool) !(Maybe Int) !(Maybe ModelOptions) !(Maybe Int)
- data EmbeddingResp = EmbeddingResp {
- respondedModel :: !Text
- respondedEmbeddings :: ![[Float]]
- copyModel :: Text -> Text -> Maybe OllamaConfig -> IO (Either OllamaError ())
- copyModelM :: MonadIO m => Text -> Text -> Maybe OllamaConfig -> m (Either OllamaError ())
- createModel :: CreateOps -> Maybe OllamaConfig -> IO ()
- createModelM :: MonadIO m => CreateOps -> Maybe OllamaConfig -> m ()
- deleteModel :: Text -> Maybe OllamaConfig -> IO (Either OllamaError ())
- deleteModelM :: MonadIO m => Text -> Maybe OllamaConfig -> m (Either OllamaError ())
- list :: Maybe OllamaConfig -> IO (Either OllamaError Models)
- ps :: Maybe OllamaConfig -> IO (Either OllamaError RunningModels)
- psM :: MonadIO m => Maybe OllamaConfig -> m (Either OllamaError RunningModels)
- push :: Text -> Maybe Bool -> Maybe Bool -> Maybe OllamaConfig -> IO ()
- pushM :: MonadIO m => Text -> Maybe Bool -> Maybe Bool -> Maybe OllamaConfig -> m ()
- pull :: Text -> IO (Either OllamaError PullResp)
- pullM :: MonadIO m => Text -> m (Either OllamaError PullResp)
- pullOps :: Text -> Maybe Bool -> Maybe Bool -> Maybe OllamaConfig -> IO (Either OllamaError PullResp)
- pullOpsM :: MonadIO m => Text -> Maybe Bool -> Maybe Bool -> Maybe OllamaConfig -> m (Either OllamaError PullResp)
- showModel :: Text -> IO (Either OllamaError ShowModelResponse)
- showModelOps :: Text -> Maybe Bool -> Maybe OllamaConfig -> IO (Either OllamaError ShowModelResponse)
- showModelM :: MonadIO m => Text -> m (Either OllamaError ShowModelResponse)
- showModelOpsM :: MonadIO m => Text -> Maybe Bool -> Maybe OllamaConfig -> m (Either OllamaError ShowModelResponse)
- checkBlobExists :: Text -> Maybe OllamaConfig -> IO (Either OllamaError Bool)
- createBlob :: FilePath -> Text -> Maybe OllamaConfig -> IO (Either OllamaError ())
- defaultOllamaConfig :: OllamaConfig
- withOnModelStart :: IO () -> OllamaConfig -> OllamaConfig
- withOnModelFinish :: IO () -> OllamaConfig -> OllamaConfig
- withOnModelError :: IO () -> OllamaConfig -> OllamaConfig
- defaultModelOptions :: ModelOptions
- data ModelOptions = ModelOptions {
- numKeep :: Maybe Int
- seed :: Maybe Int
- numPredict :: Maybe Int
- topK :: Maybe Int
- topP :: Maybe Double
- minP :: Maybe Double
- typicalP :: Maybe Double
- repeatLastN :: Maybe Int
- temperature :: Maybe Double
- repeatPenalty :: Maybe Double
- presencePenalty :: Maybe Double
- frequencyPenalty :: Maybe Double
- penalizeNewline :: Maybe Bool
- stop :: Maybe [Text]
- numa :: Maybe Bool
- numCtx :: Maybe Int
- numBatch :: Maybe Int
- numGpu :: Maybe Int
- mainGpu :: Maybe Int
- useMmap :: Maybe Bool
- numThread :: Maybe Int
- encodeImage :: FilePath -> IO (Maybe Text)
- withOllamaRequest :: ToJSON payload => Text -> ByteString -> Maybe payload -> Maybe OllamaConfig -> (Response BodyReader -> IO (Either OllamaError response)) -> IO (Either OllamaError response)
- getVersion :: IO (Either OllamaError Version)
- loadGenModel :: Text -> IO (Either OllamaError ())
- unloadGenModel :: Text -> IO (Either OllamaError ())
- loadGenModelM :: MonadIO m => Text -> m (Either OllamaError ())
- unloadGenModelM :: MonadIO m => Text -> m (Either OllamaError ())
- data ShowModelResponse = ShowModelResponse {
- modelFile :: !Text
- parameters :: !(Maybe Text)
- template :: !(Maybe Text)
- details :: !ModelDetails
- modelInfo :: !ShowModelInfo
- license :: !(Maybe Text)
- capabilities :: Maybe [Text]
- newtype Models = Models [ModelInfo]
- data ModelInfo = ModelInfo {
- name :: !Text
- modifiedAt :: !UTCTime
- size :: !Int64
- digest :: !Text
- details :: !ModelDetails
- data ModelDetails = ModelDetails {
- parentModel :: !(Maybe Text)
- format :: !Text
- family :: !Text
- families :: ![Text]
- parameterSize :: !Text
- quantizationLevel :: Text
- data ShowModelInfo = ShowModelInfo {
- generalArchitecture :: !(Maybe Text)
- generalFileType :: !(Maybe Int)
- generalParameterCount :: !(Maybe Int64)
- generalQuantizationVersion :: !(Maybe Int)
- llamaAttentionHeadCount :: !(Maybe Int)
- llamaAttentionHeadCountKV :: !(Maybe Int)
- llamaAttentionLayerNormRMSEpsilon :: !(Maybe Float)
- llamaBlockCount :: !(Maybe Int)
- llamaContextLength :: !(Maybe Int)
- llamaEmbeddingLength :: !(Maybe Int)
- llamaFeedForwardLength :: !(Maybe Int)
- llamaRopeDimensionCount :: !(Maybe Int)
- llamaRopeFreqBase :: !(Maybe Int64)
- llamaVocabSize :: !(Maybe Int64)
- tokenizerGgmlBosToken_id :: !(Maybe Int)
- tokenizerGgmlEosToken_id :: !(Maybe Int)
- tokenizerGgmlMerges :: !(Maybe [Text])
- tokenizerGgmlMode :: !(Maybe Text)
- tokenizerGgmlPre :: !(Maybe Text)
- tokenizerGgmlTokenType :: !(Maybe [Text])
- tokenizerGgmlTokens :: !(Maybe [Text])
- newtype RunningModels = RunningModels [RunningModel]
- data RunningModel = RunningModel !Text !Text !Int64 !Text !ModelDetails !UTCTime !Int64
- data Message = Message {}
- data Format
- data OllamaError
- data OllamaConfig = OllamaConfig {
- hostUrl :: Text
- timeout :: Int
- onModelStart :: Maybe (IO ())
- onModelError :: Maybe (IO ())
- onModelFinish :: Maybe (IO ())
- retryCount :: Maybe Int
- retryDelay :: Maybe Int
- commonManager :: Maybe Manager
- newtype Version = Version Text
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 NothingRight (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) someContextRight (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
| |
Instances
| ToJSON GenerateOps Source # | |
Defined in Data.Ollama.Generate Methods toJSON :: GenerateOps -> Value # toEncoding :: GenerateOps -> Encoding # toJSONList :: [GenerateOps] -> Value # toEncodingList :: [GenerateOps] -> Encoding # omitField :: GenerateOps -> Bool # | |
| Show GenerateOps Source # | |
Defined in Data.Ollama.Generate Methods showsPrec :: Int -> GenerateOps -> ShowS # show :: GenerateOps -> String # showList :: [GenerateOps] -> ShowS # | |
| Eq GenerateOps Source # | |
Defined in Data.Ollama.Generate | |
data GenerateResponse Source #
Result type for generate function containing the model's response and meta-information.
Constructors
| GenerateResponse | |
Fields
| |
Instances
| FromJSON GenerateResponse Source # | |
Defined in Data.Ollama.Common.Types Methods parseJSON :: Value -> Parser GenerateResponse # parseJSONList :: Value -> Parser [GenerateResponse] # | |
| Show GenerateResponse Source # | |
Defined in Data.Ollama.Common.Types Methods showsPrec :: Int -> GenerateResponse -> ShowS # show :: GenerateResponse -> String # showList :: [GenerateResponse] -> ShowS # | |
| Eq GenerateResponse Source # | |
Defined in Data.Ollama.Common.Types Methods (==) :: GenerateResponse -> GenerateResponse -> Bool # (/=) :: GenerateResponse -> GenerateResponse -> Bool # | |
| HasDone GenerateResponse Source # | |
Defined in Data.Ollama.Common.Types Methods getDone :: GenerateResponse -> Bool Source # | |
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 NothingEither 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) someContextEither OllamaError ChatResponse
Enumerated roles that can participate in a chat.
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 NothingEither OllamaError ChatResponse
data ChatResponse Source #
Constructors
| ChatResponse | |
Fields
| |
Instances
| FromJSON ChatResponse Source # | |
Defined in Data.Ollama.Common.Types | |
| Show ChatResponse Source # | |
Defined in Data.Ollama.Common.Types Methods showsPrec :: Int -> ChatResponse -> ShowS # show :: ChatResponse -> String # showList :: [ChatResponse] -> ShowS # | |
| Eq ChatResponse Source # | |
Defined in Data.Ollama.Common.Types | |
| HasDone ChatResponse Source # | |
Defined in Data.Ollama.Common.Types Methods getDone :: ChatResponse -> Bool 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
| |
Represents a tool that can be used in the conversation.
Since: 0.2.0.0
Constructors
| InputTool | |
Fields
| |
Instances
data FunctionDef Source #
Represents a function that can be called by the model.
Since: 0.2.0.0
Constructors
| FunctionDef | |
Fields
| |
Instances
| FromJSON FunctionDef Source # | |||||
Defined in Data.Ollama.Common.Types | |||||
| ToJSON FunctionDef Source # | |||||
Defined in Data.Ollama.Common.Types Methods toJSON :: FunctionDef -> Value # toEncoding :: FunctionDef -> Encoding # toJSONList :: [FunctionDef] -> Value # toEncodingList :: [FunctionDef] -> Encoding # omitField :: FunctionDef -> Bool # | |||||
| Generic FunctionDef Source # | |||||
Defined in Data.Ollama.Common.Types Associated Types
| |||||
| Show FunctionDef Source # | |||||
Defined in Data.Ollama.Common.Types Methods showsPrec :: Int -> FunctionDef -> ShowS # show :: FunctionDef -> String # showList :: [FunctionDef] -> ShowS # | |||||
| Eq FunctionDef Source # | |||||
Defined in Data.Ollama.Common.Types | |||||
| type Rep FunctionDef Source # | |||||
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
| |
Instances
| FromJSON FunctionParameters Source # | |
Defined in Data.Ollama.Common.Types Methods parseJSON :: Value -> Parser FunctionParameters # parseJSONList :: Value -> Parser [FunctionParameters] # | |
| ToJSON FunctionParameters Source # | |
Defined in Data.Ollama.Common.Types Methods toJSON :: FunctionParameters -> Value # toEncoding :: FunctionParameters -> Encoding # toJSONList :: [FunctionParameters] -> Value # toEncodingList :: [FunctionParameters] -> Encoding # omitField :: FunctionParameters -> Bool # | |
| Show FunctionParameters Source # | |
Defined in Data.Ollama.Common.Types Methods showsPrec :: Int -> FunctionParameters -> ShowS # show :: FunctionParameters -> String # showList :: [FunctionParameters] -> ShowS # | |
| Eq FunctionParameters Source # | |
Defined in Data.Ollama.Common.Types Methods (==) :: FunctionParameters -> FunctionParameters -> Bool # (/=) :: FunctionParameters -> FunctionParameters -> Bool # | |
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 | |
Instances
| FromJSON OutputFunction Source # | |
Defined in Data.Ollama.Common.Types Methods parseJSON :: Value -> Parser OutputFunction # parseJSONList :: Value -> Parser [OutputFunction] # | |
| ToJSON OutputFunction Source # | |
Defined in Data.Ollama.Common.Types Methods toJSON :: OutputFunction -> Value # toEncoding :: OutputFunction -> Encoding # toJSONList :: [OutputFunction] -> Value # toEncodingList :: [OutputFunction] -> Encoding # omitField :: OutputFunction -> Bool # | |
| Show OutputFunction Source # | |
Defined in Data.Ollama.Common.Types Methods showsPrec :: Int -> OutputFunction -> ShowS # show :: OutputFunction -> String # showList :: [OutputFunction] -> ShowS # | |
| Eq OutputFunction Source # | |
Defined in Data.Ollama.Common.Types Methods (==) :: OutputFunction -> OutputFunction -> Bool # (/=) :: OutputFunction -> OutputFunction -> Bool # | |
Embeddings
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.
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 |
| -> 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 #
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.
Constructors
| EmbeddingOps !Text ![Text] !(Maybe Bool) !(Maybe Int) !(Maybe ModelOptions) !(Maybe Int) |
Instances
| ToJSON EmbeddingOps Source # | |
Defined in Data.Ollama.Embeddings Methods toJSON :: EmbeddingOps -> Value # toEncoding :: EmbeddingOps -> Encoding # toJSONList :: [EmbeddingOps] -> Value # toEncodingList :: [EmbeddingOps] -> Encoding # omitField :: EmbeddingOps -> Bool # | |
| Show EmbeddingOps Source # | |
Defined in Data.Ollama.Embeddings Methods showsPrec :: Int -> EmbeddingOps -> ShowS # show :: EmbeddingOps -> String # showList :: [EmbeddingOps] -> ShowS # | |
| Eq EmbeddingOps Source # | |
Defined in Data.Ollama.Embeddings | |
data EmbeddingResp Source #
Response type for an embedding request.
Constructors
| EmbeddingResp | |
Fields
| |
Instances
| FromJSON EmbeddingResp Source # | |
Defined in Data.Ollama.Embeddings Methods parseJSON :: Value -> Parser EmbeddingResp # parseJSONList :: Value -> Parser [EmbeddingResp] # | |
| Show EmbeddingResp Source # | |
Defined in Data.Ollama.Embeddings Methods showsPrec :: Int -> EmbeddingResp -> ShowS # show :: EmbeddingResp -> String # showList :: [EmbeddingResp] -> ShowS # | |
| Eq EmbeddingResp Source # | |
Defined in Data.Ollama.Embeddings Methods (==) :: EmbeddingResp -> EmbeddingResp -> Bool # (/=) :: EmbeddingResp -> EmbeddingResp -> Bool # | |
Copy Models
Arguments
| :: Text | Source model name |
| -> Text | Destination model name |
| -> Maybe OllamaConfig | Optional |
| -> 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" NothingRight ()
copyModelM :: MonadIO m => Text -> Text -> Maybe OllamaConfig -> m (Either OllamaError ()) Source #
Create Models
Arguments
| :: CreateOps | Model creation configuration |
| -> Maybe OllamaConfig | Optional |
| -> 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
fileswith file name to SHA256 digest mappings) - A GGUF file (specify
fileswith 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
Arguments
| :: Text | Model name to delete |
| -> Maybe OllamaConfig | Optional |
| -> 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
Arguments
| :: Maybe OllamaConfig | Optional |
| -> 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
Arguments
| :: Maybe OllamaConfig | Optional |
| -> 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 NothingRight (RunningModels [RunningModel {name_ = "gemma3:instance1", modelName = "gemma3", ...}])
psM :: MonadIO m => Maybe OllamaConfig -> m (Either OllamaError RunningModels) Source #
Push and Pull
Arguments
| :: Text | Model name |
| -> Maybe Bool | Optional insecure connection flag |
| -> Maybe Bool | Optional streaming flag |
| -> Maybe OllamaConfig | Optional |
| -> 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.
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.
Arguments
| :: Text | Model name |
| -> Maybe Bool | Optional insecure connection flag |
| -> Maybe Bool | Optional streaming flag |
| -> Maybe OllamaConfig | Optional |
| -> 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) someContextRemaining bytes: 123456789 ... Completed Right (PullResp {status = "success", ...})
Show Model Info
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.
Arguments
| :: Text | Model name |
| -> Maybe Bool | Optional verbose flag |
| -> Maybe OllamaConfig | Optional |
| -> 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 #
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
Arguments
| :: Text | SHA256 digest of the blob (without "sha256:" prefix) |
| -> Maybe OllamaConfig | Optional |
| -> 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.
Arguments
| :: FilePath | Path to the file to upload |
| -> Text | Expected SHA256 digest of the file (without "sha256:" prefix) |
| -> Maybe OllamaConfig | Optional |
| -> 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
| ToJSON ModelOptions Source # | Custom ToJSON instance for Options |
Defined in Data.Ollama.Common.Types Methods toJSON :: ModelOptions -> Value # toEncoding :: ModelOptions -> Encoding # toJSONList :: [ModelOptions] -> Value # toEncodingList :: [ModelOptions] -> Encoding # omitField :: ModelOptions -> Bool # | |
| Show ModelOptions Source # | |
Defined in Data.Ollama.Common.Types Methods showsPrec :: Int -> ModelOptions -> ShowS # show :: ModelOptions -> String # showList :: [ModelOptions] -> ShowS # | |
| Eq ModelOptions Source # | |
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.
Arguments
| :: ToJSON payload | |
| => Text | API endpoint |
| -> ByteString | |
| -> Maybe payload | Optional request payload (must implement |
| -> Maybe OllamaConfig | Optional |
| -> (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
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
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") someContextRight ()
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") someContextRight ()
Since: 0.2.0.0
Types
data ShowModelResponse Source #
Response structure for model information.
Constructors
| ShowModelResponse | |
Fields
| |
Instances
| FromJSON ShowModelResponse Source # | JSON parsing instance for |
Defined in Data.Ollama.Show Methods parseJSON :: Value -> Parser ShowModelResponse # parseJSONList :: Value -> Parser [ShowModelResponse] # | |
| Show ShowModelResponse Source # | |
Defined in Data.Ollama.Show Methods showsPrec :: Int -> ShowModelResponse -> ShowS # show :: ShowModelResponse -> String # showList :: [ShowModelResponse] -> ShowS # | |
| Eq ShowModelResponse Source # | |
Defined in Data.Ollama.Show Methods (==) :: ShowModelResponse -> ShowModelResponse -> Bool # (/=) :: ShowModelResponse -> ShowModelResponse -> Bool # | |
A wrapper type containing a list of available models.
Details about a specific model.
Constructors
| ModelInfo | |
Fields
| |
data ModelDetails Source #
Metadata describing a specific model's identity and configuration.
Constructors
| ModelDetails | |
Fields
| |
Instances
| FromJSON ModelDetails Source # | |
Defined in Data.Ollama.Common.Types | |
| Show ModelDetails Source # | |
Defined in Data.Ollama.Common.Types Methods showsPrec :: Int -> ModelDetails -> ShowS # show :: ModelDetails -> String # showList :: [ModelDetails] -> ShowS # | |
| Eq ModelDetails Source # | |
Defined in Data.Ollama.Common.Types | |
data ShowModelInfo Source #
Detailed technical information about a model.
Constructors
| ShowModelInfo | |
Fields
| |
Instances
| FromJSON ShowModelInfo Source # | JSON parsing instance for |
Defined in Data.Ollama.Show Methods parseJSON :: Value -> Parser ShowModelInfo # parseJSONList :: Value -> Parser [ShowModelInfo] # | |
| Show ShowModelInfo Source # | |
Defined in Data.Ollama.Show Methods showsPrec :: Int -> ShowModelInfo -> ShowS # show :: ShowModelInfo -> String # showList :: [ShowModelInfo] -> ShowS # | |
| Eq ShowModelInfo Source # | |
Defined in Data.Ollama.Show Methods (==) :: ShowModelInfo -> ShowModelInfo -> Bool # (/=) :: ShowModelInfo -> ShowModelInfo -> Bool # | |
newtype RunningModels Source #
A wrapper type containing a list of running models.
Constructors
| RunningModels [RunningModel] | List of |
Instances
| FromJSON RunningModels Source # | JSON parsing instance for |
Defined in Data.Ollama.Ps Methods parseJSON :: Value -> Parser RunningModels # parseJSONList :: Value -> Parser [RunningModels] # | |
| Show RunningModels Source # | |
Defined in Data.Ollama.Ps Methods showsPrec :: Int -> RunningModels -> ShowS # show :: RunningModels -> String # showList :: [RunningModels] -> ShowS # | |
| Eq RunningModels Source # | |
Defined in Data.Ollama.Ps Methods (==) :: RunningModels -> RunningModels -> Bool # (/=) :: RunningModels -> RunningModels -> Bool # | |
data RunningModel Source #
Details about a specific running model.
Constructors
| RunningModel !Text !Text !Int64 !Text !ModelDetails !UTCTime !Int64 |
Instances
| FromJSON RunningModel Source # | JSON parsing instance for |
Defined in Data.Ollama.Ps | |
| Show RunningModel Source # | |
Defined in Data.Ollama.Ps Methods showsPrec :: Int -> RunningModel -> ShowS # show :: RunningModel -> String # showList :: [RunningModel] -> ShowS # | |
| Eq RunningModel Source # | |
Defined in Data.Ollama.Ps | |
Represents a message within a chat, including its role and content.
Constructors
| Message | |
Fields | |
Instances
| FromJSON Message Source # | |||||
Defined in Data.Ollama.Common.Types | |||||
| ToJSON Message Source # | |||||
| Generic Message Source # | |||||
Defined in Data.Ollama.Common.Types Associated Types
| |||||
| Show Message Source # | |||||
| Eq Message Source # | |||||
| type Rep Message Source # | |||||
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)))))) | |||||
Format specification for the chat output.
Since: 0.1.3.0
Constructors
| JsonFormat | |
| SchemaFormat Schema |
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
| Exception OllamaError Source # | |||||
Defined in Data.Ollama.Common.Error Methods toException :: OllamaError -> SomeException # fromException :: SomeException -> Maybe OllamaError # displayException :: OllamaError -> String # backtraceDesired :: OllamaError -> Bool # | |||||
| Generic OllamaError Source # | |||||
Defined in Data.Ollama.Common.Error Associated Types
| |||||
| Show OllamaError Source # | |||||
Defined in Data.Ollama.Common.Error Methods showsPrec :: Int -> OllamaError -> ShowS # show :: OllamaError -> String # showList :: [OllamaError] -> ShowS # | |||||
| Eq OllamaError Source # | |||||
Defined in Data.Ollama.Common.Error | |||||
| type Rep OllamaError Source # | |||||
Defined in Data.Ollama.Common.Error type Rep OllamaError = D1 ('MetaData "OllamaError" "Data.Ollama.Common.Error" "ollama-haskell-0.2.1.0-inplace" 'False) ((C1 ('MetaCons "HttpError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HttpException)) :+: (C1 ('MetaCons "DecodeError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DecodingErrorMessage) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DecodingFailedValue)) :+: C1 ('MetaCons "ApiError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))) :+: ((C1 ('MetaCons "FileError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 IOException)) :+: C1 ('MetaCons "JsonSchemaError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))) :+: (C1 ('MetaCons "TimeoutError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :+: C1 ('MetaCons "InvalidRequest" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))) | |||||
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
| Generic OllamaConfig Source # | |||||
Defined in Data.Ollama.Common.Config Associated Types
| |||||
| type Rep OllamaConfig Source # | |||||
Defined in Data.Ollama.Common.Config type Rep OllamaConfig = D1 ('MetaData "OllamaConfig" "Data.Ollama.Common.Config" "ollama-haskell-0.2.1.0-inplace" 'False) (C1 ('MetaCons "OllamaConfig" 'PrefixI 'True) (((S1 ('MetaSel ('Just "hostUrl") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "timeout") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "onModelStart") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (IO ()))) :*: S1 ('MetaSel ('Just "onModelError") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (IO ()))))) :*: ((S1 ('MetaSel ('Just "onModelFinish") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (IO ()))) :*: S1 ('MetaSel ('Just "retryCount") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int))) :*: (S1 ('MetaSel ('Just "retryDelay") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int)) :*: S1 ('MetaSel ('Just "commonManager") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Manager)))))) | |||||