Home
LangChain4Clj
A Clojure wrapper for LangChain4j - Build powerful AI applications with the simplicity and elegance of Clojure.
Quick Start
Add to your deps.edn:
{:deps {io.github.nandoolle/langchain4clj {:mvn/version "1.6.1"}}}
Or to your Leiningen project.clj:
[io.github.nandoolle/langchain4clj "1.6.1"]
Simple Example
(require '[langchain4clj.chat :as chat])
(def model (chat/create-chat-model
{:model-name "gpt-4"
:api-key (System/getenv "OPENAI_API_KEY")}))
(chat/chat model "What is the capital of France?")
;; => "The capital of France is Paris."
Core Features
Explore the fundamental capabilities of LangChain4Clj:
- Core Chat - Model creation, chat function, and provider configuration
- Model Presets - Pre-configured models for quick setup
- Environment Resolution - Secure API key management with
[:env "VAR"] - JSON Schema Converter - Convert JSON Schema to LangChain4j format
- Memory Patterns - Conversation history and context management
- Streaming Responses - Real-time streaming with callbacks and error handling
- Image Generation - DALL-E 2/3 integration with quality and style controls
- Native JSON Mode - Provider-guaranteed valid JSON output
- Structured Output - Schema-validated responses with multiple strategies
- Chat Listeners - Observability, token tracking, and event handling
- Message Serialization - Convert messages to EDN/JSON for persistence
Advanced Features
Build sophisticated AI applications:
- Tools & Function Calling - Extend LLM capabilities with custom functions
- Tool Helpers - JSON Schema tool definitions for external integration
- Assistant System - Memory management and autonomous tool execution
- Multi-Agent Systems - Orchestrate multiple agents for complex workflows
- RAG (Document Processing) - Load, parse, and split documents for retrieval-augmented generation
- Resilience & Failover - Automatic retries and provider fallback strategies
Why LangChain4Clj?
- Idiomatic Clojure - Leverages Clojure’s strengths: immutability, data-first design, and composability
- Comprehensive - Full access to LangChain4j’s powerful features
- Type-Safe - Malli and Schema support for request/response validation
- Production-Ready - Built-in resilience, failover, and error handling
- Well-Documented - Extensive guides and examples
Provider Support
LangChain4Clj supports all major AI providers:
- OpenAI (GPT-4, GPT-3.5, DALL-E)
- Anthropic (Claude 3.5 Sonnet, Claude 3 Opus/Haiku)
- Google (Gemini Pro/Flash)
- Azure OpenAI
- Ollama (Local models)
- And many more…
Getting Help
- GitHub Repository - Source code, issues, and contributions
- Clojars - Download and dependency information
- Changelog - Version history and updates
- Contributing - Guidelines for contributors
License
Copyright © 2024 Fernando Olle
Distributed under the Apache License 2.0.