Liking cljdoc? Tell your friends :D

com.blockether.svar.internal.llm

LLM client layer: HTTP transport, message construction, and all LLM interaction functions (ask!, abstract!, eval!, refine!, models!, sample!).

Extracted from svar.core to break the cyclic dependency between core and rlm. rlm.clj requires this namespace directly instead of svar.core.

LLM client layer: HTTP transport, message construction, and all LLM interaction
functions (ask!, abstract!, eval!, refine!, models!, sample!).

Extracted from svar.core to break the cyclic dependency between core and rlm.
rlm.clj requires this namespace directly instead of svar.core.
raw docstring

abstract!clj

(abstract! {:keys [text iterations target-length special-instructions eval?
                   refine? threshold]
            :as opts
            :or {iterations DEFAULT_ITERATIONS
                 target-length DEFAULT_TARGET_LENGTH
                 eval? false
                 refine? false
                 threshold 0.9}})

Creates a dense, entity-rich summary of text using Chain of Density prompting.

Based on "From Sparse to Dense: GPT-4 Summarization with Chain of Density Prompting" (Adams et al., 2023). Iteratively refines a summary by identifying missing salient entities and incorporating them while maintaining a fixed length.

When :eval? is true, each iteration is scored against the source text using eval!, giving a quality gradient across iterations (:score field per iteration).

When :refine? is true, the final summary is verified against the source text using Chain of Verification (CoVe) via refine!. This catches hallucinated framing, unfaithful claims, and information not present in the source.

Opts: :text - String. Source text to summarize. :model - String. LLM model to use. :config - Map, optional. LLM config. :iterations - Integer. Number of CoD densification iterations (default: 5). :target-length - Integer. Target summary length in words (default: 80). :special-instructions - String, optional. Additional instructions for the LLM. :eval? - Boolean. Score each iteration for a quality gradient (default: false). :refine? - Boolean. Run CoVe faithfulness verification on final summary (default: false). :threshold - Float. Min eval score for refinement early stop, 0.0-1.0 (default: 0.9).

Creates a dense, entity-rich summary of text using Chain of Density prompting.

Based on "From Sparse to Dense: GPT-4 Summarization with Chain of Density Prompting"
(Adams et al., 2023). Iteratively refines a summary by identifying missing salient
entities and incorporating them while maintaining a fixed length.

 When `:eval?` is true, each iteration is scored against the source text using `eval!`,
giving a quality gradient across iterations (`:score` field per iteration).

When `:refine?` is true, the final summary is verified against the source text using
Chain of Verification (CoVe) via `refine!`. This catches hallucinated framing,
unfaithful claims, and information not present in the source.

Opts:
  :text - String. Source text to summarize.
  :model - String. LLM model to use.
  :config - Map, optional. LLM config.
  :iterations - Integer. Number of CoD densification iterations (default: 5).
  :target-length - Integer. Target summary length in words (default: 80).
  :special-instructions - String, optional. Additional instructions for the LLM.
  :eval? - Boolean. Score each iteration for a quality gradient (default: false).
  :refine? - Boolean. Run CoVe faithfulness verification on final summary (default: false).
  :threshold - Float. Min eval score for refinement early stop, 0.0-1.0 (default: 0.9).
sourceraw docstring

ask!clj

(ask! {:keys [spec messages humanizer] :as opts})

Asks the LLM and returns structured Clojure data with token usage and cost.

Includes automatic pre-flight context limit checking. If your input exceeds the model's context window, throws a clear error with actionable suggestions BEFORE making the API call.

Supports multimodal input via the user + image helpers.

Params: opts - Map with keys:

  • :spec - Spec definition, required.
  • :messages - Vector of message maps, required.
  • :model - String, required. LLM model to use.
  • :config - Map, optional. LLM config from make-config.
  • :humanizer - Function, optional. Applied to ::spec/humanize? fields.
  • :output-reserve - Integer, optional.
  • :check-context? - Boolean, optional.
  • :timeout-ms - Integer, optional.

Returns: Map with :result, :tokens, :cost, :duration-ms.

Asks the LLM and returns structured Clojure data with token usage and cost.

Includes automatic pre-flight context limit checking. If your input exceeds
the model's context window, throws a clear error with actionable suggestions
BEFORE making the API call.

Supports multimodal input via the `user` + `image` helpers.

Params:
`opts` - Map with keys:
  - :spec - Spec definition, required.
  - :messages - Vector of message maps, required.
  - :model - String, required. LLM model to use.
  - :config - Map, optional. LLM config from make-config.
  - :humanizer - Function, optional. Applied to ::spec/humanize? fields.
  - :output-reserve - Integer, optional.
  - :check-context? - Boolean, optional.
  - :timeout-ms - Integer, optional.

Returns:
Map with :result, :tokens, :cost, :duration-ms.
sourceraw docstring

assistantclj

(assistant content)

Creates an assistant message (for few-shot examples or conversation history).

Params: content - String. The assistant's response.

Returns: Message map with :role "assistant".

Creates an assistant message (for few-shot examples or conversation history).

Params:
`content` - String. The assistant's response.

Returns:
Message map with :role "assistant".
sourceraw docstring

chat-completionclj

(chat-completion messages model api-key base-url)
(chat-completion messages model api-key base-url retry-opts)

Calls the LLM API (OpenAI compatible) with the given messages.

Calls the LLM API (OpenAI compatible) with the given messages.
sourceraw docstring

eval!clj

(eval! {:keys [task output messages criteria ground-truths context]
        :as opts
        :or {criteria EVAL_CRITERIA}})

Evaluates an LLM output using LLM self-evaluation for reliability and accuracy.

Evaluates an LLM output using LLM self-evaluation for reliability and accuracy.
sourceraw docstring

imageclj

(image source)
(image source media-type)

Creates an image attachment for use with user messages.

Accepts either base64-encoded image data or an HTTP(S) URL. URLs are passed through directly to the LLM API; base64 strings are wrapped in a data URI with the given media-type.

Params: source - String. Base64-encoded image data or an image URL (http/https). media-type - String, optional. MIME type (default: "image/png"). Ignored when source is a URL.

Returns: Map marker that user recognizes and converts to multimodal content. When source is a URL, returns {:svar/type :image :url "..."}. When source is base64, returns {:svar/type :image :base64 "..." :media-type "..."}.

Creates an image attachment for use with `user` messages.

Accepts either base64-encoded image data or an HTTP(S) URL.
URLs are passed through directly to the LLM API; base64 strings
are wrapped in a data URI with the given media-type.

Params:
`source` - String. Base64-encoded image data or an image URL (http/https).
`media-type` - String, optional. MIME type (default: "image/png").
               Ignored when source is a URL.

Returns:
Map marker that `user` recognizes and converts to multimodal content.
When source is a URL, returns {:svar/type :image :url "..."}.
When source is base64, returns {:svar/type :image :base64 "..." :media-type "..."}.
sourceraw docstring

models!clj

(models!)
(models! opts)

Fetches available models from the LLM API.

Fetches available models from the LLM API.
sourceraw docstring

refine!clj

(refine! {:keys [spec messages iterations threshold stop-strategy window-size
                 criteria documents]
          :as opts
          :or {iterations DEFAULT_REFINE_ITERATIONS
               threshold DEFAULT_REFINE_THRESHOLD
               stop-strategy :both
               window-size 3
               criteria EVAL_CRITERIA}})

Iteratively refines LLM output using decomposition and verification.

Implements the Factor+Revise variant of Chain of Verification (CoVe) from Dhuliawala et al. (2023), combined with DuTy decomposition.

Iteratively refines LLM output using decomposition and verification.

Implements the Factor+Revise variant of Chain of Verification (CoVe)
from Dhuliawala et al. (2023), combined with DuTy decomposition.
sourceraw docstring

sample!clj

(sample! {:keys [spec messages criteria iterations threshold]
          :as opts
          n :count
          :or {criteria SAMPLE_CRITERIA
               iterations DEFAULT_SAMPLE_ITERATIONS
               threshold DEFAULT_SAMPLE_THRESHOLD}})

Generates test data samples matching a spec with evaluation and self-correction.

Generates test data samples matching a spec with evaluation and self-correction.
sourceraw docstring

systemclj

(system content)

Creates a system message.

Params: content - String. System instructions / objective.

Returns: Message map with :role "system".

Creates a system message.

Params:
`content` - String. System instructions / objective.

Returns:
Message map with :role "system".
sourceraw docstring

userclj

(user content & images)

Creates a user message, optionally with images for multimodal models.

Params: content - String. The user's message text. images - Zero or more image maps created with image.

Creates a user message, optionally with images for multimodal models.

Params:
`content` - String. The user's message text.
`images` - Zero or more image maps created with `image`.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close