langchain-hs: Haskell implementation of Langchain

[ library, mit, web ] [ Propose Tags ] [ Report a vulnerability ]
Versions [RSS] 0.0.1.0
Change log CHANGELOG.md
Dependencies aeson (>=2 && <3), base (>=4.7 && <5), bytestring (>=0.10), containers (>=0.6 && <0.9), directory (>=1.3.6 && <1.4), http-conduit (>=2 && <3), http-types (>=0.11 && <0.13), ollama-haskell, pdf-toolbox-document (==0.1.4), scalpel (>=0.6 && <0.7), text (>=2 && <3) [details]
License MIT
Copyright 2025 tushar
Author tushar
Maintainer tusharadhatrao@gmail.com
Category Web
Home page https://github.com/tusharad/langchain-hs#readme
Bug tracker https://github.com/tusharad/langchain-hs/issues
Source repo head: git clone https://github.com/tusharad/langchain-hs
Uploaded by tusharad at 2025-04-10T13:46:52Z
Distributions Stackage:0.0.1.0
Downloads 1 total (1 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for langchain-hs-0.0.1.0

[back to package description]

🦜️🔗LangChain Haskell

⚡ Building applications with LLMs through composability in Haskell! ⚡

Introduction

LangChain Haskell is a robust port of the original LangChain library, bringing its powerful natural language processing capabilities to the Haskell ecosystem. This library enables developers to build applications powered by large language models (LLMs) with ease and flexibility.

Features

  • LLM Integration: Seamlessly interact with various language models, including OpenAI's GPT series and others.
  • Prompt Templates: Create and manage dynamic prompts for different tasks.
  • Memory Management: Implement conversational memory to maintain context across interactions.
  • Agents and Tools: Develop agents that can utilize tools to perform complex tasks.
  • Document Loaders: Load and process documents from various sources for use in your applications.

Current Supported Providers

  • Ollama
  • More to come...

Installation

To use LangChain Haskell in your project, add it to your package dependencies. If you're using Stack, include it in your package.yaml:

dependencies:
  - base >= 4.7 && < 5
  - langchain-hs

Then, run the build command for your respective build tool to fetch and compile the dependency.

Quickstart

Here's a simple example demonstrating how to use LangChain Haskell to interact with an LLM:

{-# LANGUAGE OverloadedStrings #-}
module Main (main) where

import Langchain.LLM.Ollama
import Langchain.LLM.Core
import Langchain.PromptTemplate
import Langchain.Callback
import qualified Data.Map.Strict as Map
import qualified Data.Text as T

main :: IO ()
main = do 
  let ollamaLLM = Ollama "llama3.2" [stdOutCallback]
      prompt = PromptTemplate "Translate the following English text to French: {text}"
      input = Map.fromList [("text", "Hello, how are you?")]
      
  case renderPrompt prompt input of
    Left e -> putStrLn $ "Error: " ++ e
    Right renderedPrompt -> do
      eRes <- generate ollamaLLM renderedPrompt Nothing
      case eRes of
        Left err -> putStrLn $ "Error: " ++ err
        Right response -> putStrLn $ "Translation: " ++ (T.unpack response)

Documentation

Documentation will soon be available on hackage.

Examples

Explore the examples directory in the repository for more use cases, including:

  • Conversational Agents: Building chatbots that maintain context.
  • Document Q&A: Answering questions based on the content of provided documents.
  • Tool Use: Creating agents that can use external tools to fetch information or perform calculations.

Contributing

Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you'd like to change.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

This project is inspired by and builds upon the original LangChain library and its various ports in other programming languages. Special thanks to the developers of those projects for their foundational work.