packages feed

ollama-haskell 0.1.0.2 → 0.1.0.3

raw patch · 12 files changed

+209/−106 lines, 12 filesdep ~aesondep ~basedep ~bytestringPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: aeson, base, bytestring, http-client, http-types, text, time

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,8 +1,12 @@ # Revision history for ollama-haskell +## 0.1.0.3 -- 2024-11-05++* Moving to stack instead of cabal.+ ## 0.1.0.2 -- 2024-10-18 -* Increased response timeout time for chat function+* Increased response timeout time for chat function.   ## 0.1.0.1 -- 2024-10-18 
+ README.md view
@@ -0,0 +1,74 @@+# Ollama-haskell++**ollama-haskell** is an unofficial Haskell binding for [Ollama](https://ollama.com), similar to [`ollama-python`](https://github.com/ollama/ollama-python). ++This library allows you to interact with Ollama, a tool that lets you run large language models (LLMs) locally, from within your Haskell projects. ++## Examples++```haskell+{-# LANGUAGE OverloadedStrings #-}+module Lib where++import Ollama (GenerateOps(..), defaultGenerateOps, generate)++main :: IO ()+main = do+    void $+      generate+        defaultGenerateOps+          { modelName = "llama3.2"+          , prompt = "what is functional programming?"+          , stream = Just (T.putStr . Ollama.response_, pure ())+          }+```++### Output++```bash+ghci> import Lib+ghci> main++Whether Haskell is a "good" language depends on what you're looking for in a programming language and your personal preferences. Here are some points to consider:++**Pros:**++1. **Strongly typed**: Haskell's type system ensures that you catch errors early, which leads to fewer bugs and easier maintenance.+2. **Functional programming paradigm**: Haskell encourages declarative coding, making it easier to reason about code and write correct programs.+3. **Garbage collection**: Haskell handles memory management automatically, freeing you from worries about manual memory deallocation.+```++You can find practical examples demonstrating how to use the library in the `src/OllamaExamples.hs` file. ++## Prerequisite++Make sure you have [Ollama](https://ollama.com) installed and running on your local machine. You can download it from [here](https://ollama.com/download).++## How to Use It++1. Include the `ollama-haskell` package in your `.cabal` file:+   ```cabal+   build-depends:+       base >= 4.7 && < 5,+       ollama-haskell+   ```++3. Import the `Ollama` module and start integrating with your local LLM.++## Future Updates++- [x] Improve documentation+- [x] Add tests.+- [x] Add examples.+- [x] Add CI/CD pipeline.+- [ ] `options` parameter in `generate`.++Stay tuned for future updates and improvements!++## Author++This library is developed and maintained by [Tushar](https://github.com/tusharad). Feel free to reach out for any questions or suggestions!++## Contributions++Contributions are welcome! If you'd like to improve the library, please submit a pull request or open an issue. Whether it's fixing bugs, adding new features, or improving documentation, all contributions are greatly appreciated.
ollama-haskell.cabal view
@@ -1,71 +1,84 @@-cabal-version:      3.4-name:               ollama-haskell-version:            0.1.0.2-synopsis:           Ollama Haskell library--- description:-license:            MIT-license-file:       LICENSE-author:             Tushar Adhatrao-maintainer:         tusharadhatrao@gmail.com-description:        Haskell bindings for Ollama.--- copyright:-category:           Data-build-type:         Simple-extra-doc-files:    CHANGELOG.md--- extra-source-files:-Homepage:            https://github.com/tusharad/ollama-haskell-Bug-reports:         https://github.com/tusharad/ollama-haskell/issues-extra-source-files:  CHANGELOG.md+cabal-version: 1.12 -Source-repository head-  type:     git-  location: https://github.com/tusharad/ollama-haskell+-- This file has been generated from package.yaml by hpack version 0.37.0.+--+-- see: https://github.com/sol/hpack -common warnings-    ghc-options: -Wall+name:           ollama-haskell+version:        0.1.0.3+synopsis:       Haskell bindings for ollama.+description:    Please see the README on GitHub at <https://github.com/tusharad/ollama-haskell#readme>+category:       Web+homepage:       https://github.com/tusharad/ollama-haskell#readme+bug-reports:    https://github.com/tusharad/ollama-haskell/issues+author:         tushar+maintainer:     tusharadhatrao@gmail.com+copyright:      2024 tushar+license:        MIT+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    CHANGELOG.md -library-    import:           warnings-    exposed-modules:  Ollama-                    , Data.Ollama.Chat-                    , Data.Ollama.Copy-                    , Data.Ollama.Common.Types-                    , Data.Ollama.Common.Utils-                    , Data.Ollama.Create-                    , Data.Ollama.Delete-                    , Data.Ollama.Embeddings-                    , Data.Ollama.Generate-                    , Data.Ollama.List-                    , Data.Ollama.Ps-                    , Data.Ollama.Pull-                    , Data.Ollama.Push-                    , Data.Ollama.Show-                    , OllamaExamples-    -- other-modules:-    -- other-extensions:-    build-depends:    base ^>=4.18-                    , aeson >= 2.2.1 && < 2.3-                    , bytestring >= 0.11.5 && < 0.12-                    , text >= 2.0.2 && < 2.1-                    , time >= 1.12.2 && < 1.13-                    , http-client >= 0.7.17 && < 0.8-                    , http-types >= 0.12.4 && < 0.13+source-repository head+  type: git+  location: https://github.com/tusharad/ollama-haskell -    hs-source-dirs:   src-    default-language: GHC2021+library+  exposed-modules:+      Data.Ollama.Chat+      Data.Ollama.Common.Types+      Data.Ollama.Common.Utils+      Data.Ollama.Copy+      Data.Ollama.Create+      Data.Ollama.Delete+      Data.Ollama.Embeddings+      Data.Ollama.Generate+      Data.Ollama.List+      Data.Ollama.Ps+      Data.Ollama.Pull+      Data.Ollama.Push+      Data.Ollama.Show+      Ollama+      OllamaExamples+  other-modules:+      Paths_ollama_haskell+  hs-source-dirs:+      src+  default-extensions:+      ImportQualifiedPost+  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints+  build-depends:+      aeson+    , base >=4.7 && <5+    , bytestring+    , http-client+    , http-types+    , text+    , time+  default-language: Haskell2010  test-suite ollama-haskell-test-    import:           warnings-    default-language: GHC2021-    -- other-modules:-    -- other-extensions:-    type:             exitcode-stdio-1.0-    hs-source-dirs:   test-    main-is:          Main.hs-    build-depends:-        base ^>=4.18,-        tasty,-        tasty-hunit,-        text,-        silently,-        ollama-haskell+  type: exitcode-stdio-1.0+  main-is: Main.hs+  other-modules:+      Paths_ollama_haskell+  hs-source-dirs:+      test+  default-extensions:+      ImportQualifiedPost+  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      aeson+    , base >=4.7 && <5+    , bytestring+    , http-client+    , http-types+    , ollama-haskell+    , silently+    , tasty+    , tasty-hunit+    , text+    , time+  default-language: Haskell2010
src/Data/Ollama/Chat.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-}  module Data.Ollama.Chat@@ -119,14 +120,14 @@   deriving (Show, Eq)  instance ToJSON ChatOps where-  toJSON (ChatOps model messages tools format stream keepAlive) =+  toJSON (ChatOps model_ messages_ tools_ format_ stream_ keepAlive_) =     object-      [ "model" .= model-      , "messages" .= messages-      , "tools" .= tools-      , "format" .= format-      , "stream" .= if isNothing stream then Just False else Just True-      , "keep_alive" .= keepAlive+      [ "model" .= model_+      , "messages" .= messages_+      , "tools" .= tools_+      , "format" .= format_+      , "stream" .= if isNothing stream_ then Just False else Just True+      , "keep_alive" .= keepAlive_       ]  instance FromJSON ChatResponse where@@ -181,8 +182,10 @@ chat cOps = do   let url = CU.host defaultOllama   manager <--    newManager defaultManagerSettings -- Setting response timeout to 5 minutes, since llm takes time-                    { managerResponseTimeout = responseTimeoutMicro (5 * 60 * 1000000)}+    newManager+      defaultManagerSettings -- Setting response timeout to 5 minutes, since llm takes time+        { managerResponseTimeout = responseTimeoutMicro (5 * 60 * 1000000)+        }   initialRequest <- parseRequest $ T.unpack (url <> "/api/chat")   let reqBody = cOps       request =
src/Data/Ollama/Common/Types.hs view
@@ -1,7 +1,10 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} -module Data.Ollama.Common.Types where+module Data.Ollama.Common.Types+  ( ModelDetails (..)+  , OllamaClient (..)+  ) where  import Data.Aeson import Data.Text (Text)
src/Data/Ollama/Copy.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} @@ -32,16 +33,16 @@   Text ->   IO () copyModel-  source-  destination =+  source_+  destination_ =     do       let url = CU.host CU.defaultOllama       manager <- newManager defaultManagerSettings       initialRequest <- parseRequest $ T.unpack (url <> "/api/copy")       let reqBody =             CopyModelOps-              { source = source-              , destination = destination+              { source = source_+              , destination = destination_               }           request =             initialRequest
src/Data/Ollama/Create.hs view
@@ -33,16 +33,16 @@ instance ToJSON CreateModelOps where   toJSON     ( CreateModelOps-        name-        modelFile-        stream-        path+        name_+        modelFile_+        stream_+        path_       ) =       object-        [ "name" .= name-        , "modelfile" .= modelFile-        , "stream" .= stream-        , "path" .= path+        [ "name" .= name_+        , "modelfile" .= modelFile_+        , "stream" .= stream_+        , "path" .= path_         ]  instance FromJSON CreateModelResp where@@ -65,9 +65,9 @@   IO () createModelOps   modelName-  modelFile-  stream-  path =+  modelFile_+  stream_+  path_ =     do       let url = CU.host defaultOllama       manager <- newManager defaultManagerSettings@@ -75,9 +75,9 @@       let reqBody =             CreateModelOps               { name = modelName-              , modelFile = modelFile-              , stream = stream-              , path = path+              , modelFile = modelFile_+              , stream = stream_+              , path = path_               }           request =             initialRequest@@ -113,8 +113,8 @@   -- | Path   Maybe FilePath ->   IO ()-createModel modelName modelFile =+createModel modelName modelFile_ =   createModelOps     modelName-    modelFile+    modelFile_     Nothing
src/Data/Ollama/Delete.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE DuplicateRecordFields #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-}  module Data.Ollama.Delete
src/Data/Ollama/Embeddings.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} @@ -31,12 +32,12 @@   deriving (Show, Eq, Generic, FromJSON)  instance ToJSON EmbeddingOps where-  toJSON (EmbeddingOps model input truncate' keepAlive) =+  toJSON (EmbeddingOps model_ input_ truncate' keepAlive_) =     object-      [ "model" .= model-      , "input" .= input+      [ "model" .= model_+      , "input" .= input_       , "truncate" .= truncate'-      , "keep_alive" .= keepAlive+      , "keep_alive" .= keepAlive_       ]  -- TODO: Add Options parameter@@ -52,14 +53,14 @@   -- | Keep Alive   Maybe Text ->   IO (Maybe EmbeddingResp)-embeddingOps modelName input mTruncate mKeepAlive = do+embeddingOps modelName input_ mTruncate mKeepAlive = do   let url = CU.host defaultOllama   manager <- newManager defaultManagerSettings   initialRequest <- parseRequest $ T.unpack (url <> "/api/embed")   let reqBody =         EmbeddingOps           { model = modelName-          , input = input+          , input = input_           , truncate = mTruncate           , keepAlive = mKeepAlive           }@@ -83,5 +84,5 @@   -- | Input   Text ->   IO (Maybe EmbeddingResp)-embedding modelName input =-  embeddingOps modelName input Nothing Nothing+embedding modelName input_ =+  embeddingOps modelName input_ Nothing Nothing
src/Data/Ollama/Pull.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} 
src/Data/Ollama/Push.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} 
src/Data/Ollama/Show.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} @@ -138,7 +139,7 @@   IO (Maybe ShowModelResponse) showModelOps   modelName-  verbose =+  verbose_ =     do       let url = CU.host CU.defaultOllama       manager <- newManager defaultManagerSettings@@ -146,7 +147,7 @@       let reqBody =             ShowModelOps               { name = modelName-              , verbose = verbose+              , verbose = verbose_               }           request =             initialRequest