A Clojure library inspired by DSPy, providing a declarative approach to building and optimizing language model pipelines.
DSCloj leverages litellm-clj to provide a unified interface for working with various LLM providers while bringing DSPy's powerful programming model to the Clojure ecosystem.
DSCloj brings the power of declarative LLM programming to Clojure. Inspired by Stanford's DSPy framework.
Add DSCloj to your deps.edn:
{:deps {io.unravel/dscloj {:mvn/version "0.1.0"}}}
DSCloj works by defining modules - declarative specifications of LLM tasks with typed inputs and outputs.
(require '[dscloj.core :as dscloj])
;; 1. Define a module
(def qa-module
  {:inputs [{:name :question
             :type "str"
             :description "The question to answer"}]
   :outputs [{:name :answer
              :type "str"
              :description "The answer to the question"}]
   :instructions "Provide concise and accurate answers."})
;; 2. Use the module with predict
(def result (dscloj/predict qa-module 
                            {:question "What is the capital of France?"}
                            {:model "gpt-4"
                             :api-key (System/getenv "OPENAI_API_KEY")}))
;; 3. Access the structured output
(:answer result)
;; => "Paris"
Modules are maps with:
:inputs - Vector of input field definitions:outputs - Vector of output field definitions:instructions - Optional string describing the task instructions, rules, and examplesFields are maps with:
:name - Keyword identifier:type - String type ("str", "int", "float", "bool"):description - Human-readable descriptionThe predict function:
See the examples/ directory for:
DSCloj uses litellm-clj and supports:
This project is licensed under the MIT License - see the LICENSE file for details.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs | 
| ← | Move to previous article | 
| → | Move to next article | 
| Ctrl+/ | Jump to the search field |