packages feed

llama-cpp-haskell 0.0.1 → 0.1

raw patch · 2 files changed

+20/−18 lines, 2 files

Files

Llama.hs view
@@ -27,7 +27,7 @@       , "content" .= content m       ] -data LlamaApplyTemplateRequest = LlamaApplyTemplateRequest+newtype LlamaApplyTemplateRequest = LlamaApplyTemplateRequest   { messages :: [LlamaMessage]   } deriving (Show, Generic) instance ToJSON LlamaApplyTemplateRequest@@ -37,7 +37,7 @@ --  } deriving (Show)  -- Llama request and response-data LlamaRequest = LlamaRequest+newtype LlamaRequest = LlamaRequest   { prompt :: Text   } deriving (Show) @@ -49,7 +49,7 @@   toJSON (LlamaRequest p) =     object ["prompt" .= p] -data LlamaResponse = LlamaResponse+newtype LlamaResponse = LlamaResponse   { generatedText :: Text   } deriving (Show) @@ -57,9 +57,11 @@   parseJSON = withObject "LlamaResponse" $ \v -> LlamaResponse     <$> v .: "content" -applyTemplate :: Manager -> LlamaApplyTemplateRequest -> IO (Maybe Text)-applyTemplate manager input = do-  let request = parseRequest_ "http://localhost:8080/apply-template"+type URL = String++applyTemplate :: URL -> Manager -> LlamaApplyTemplateRequest -> IO (Maybe Text)+applyTemplate url manager input = do+  let request = parseRequest_ $ url ++ "/apply-template"       body = encode input       req = request { method = "POST"                     , requestBody = RequestBodyLBS body@@ -73,9 +75,9 @@       return Nothing  -- Function to send a message to the Llama model-sendToLlama :: Manager -> Text -> IO (Maybe Text)-sendToLlama manager input = do-  let request = parseRequest_ "http://localhost:8080/completion"+sendToLlama :: URL -> Manager -> Text -> IO (Maybe Text)+sendToLlama url manager input = do+  let request = parseRequest_ $ url ++ "/completion"       body = encode (LlamaRequest input)       req = request { method = "POST"                     , requestBody = RequestBodyLBS body@@ -88,15 +90,15 @@       liftIO $ hPutStrLn stderr "Failed to decode Llama response"       return Nothing -llama :: Text -> IO (Maybe Text)-llama input = do+llama :: URL -> Text -> IO (Maybe Text)+llama url input = do   manager <- liftIO $ newManager tlsManagerSettings { managerResponseTimeout = responseTimeoutNone }-  sendToLlama manager input+  sendToLlama url manager input -llamaTemplated :: LlamaApplyTemplateRequest -> IO (Maybe Text)-llamaTemplated input = do+llamaTemplated :: URL -> LlamaApplyTemplateRequest -> IO (Maybe Text)+llamaTemplated url input = do   manager <- liftIO $ newManager tlsManagerSettings { managerResponseTimeout = responseTimeoutNone }-  res <- applyTemplate manager input+  res <- applyTemplate url manager input   case res of-    Just text -> sendToLlama manager text+    Just text -> sendToLlama url manager text     _ -> pure Nothing
llama-cpp-haskell.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.2 name:               llama-cpp-haskell-version:            0.0.1+version:            0.1 synopsis:           Haskell bindings for the llama.cpp llama-server -- description: license:            AGPL-3.0-only@@ -19,7 +19,7 @@ Source-repository this   type:              git   location:          https://github.com/l29ah/llama-cpp-haskell.git-  tag:               0.0.1+  tag:               0.1  common stuff     ghc-options: -Wall