Liking cljdoc? Tell your friends :D

dscloj.core


module->promptclj

(module->prompt module)

Convert a module signature/schema into a prompt template.

A module is a map with:

  • :inputs - Vector of field definitions with :name, :spec, :description keys
  • :outputs - Vector of field definitions with :name, :spec, :description keys
  • :instructions - Optional string describing the task instructions, rules, and examples

Example: (module->prompt example-module)

Returns a formatted prompt string.

Convert a module signature/schema into a prompt template.

A module is a map with:
- :inputs - Vector of field definitions with :name, :spec, :description keys
- :outputs - Vector of field definitions with :name, :spec, :description keys
- :instructions - Optional string describing the task instructions, rules, and examples

Example:
  (module->prompt example-module)

Returns a formatted prompt string.
sourceraw docstring

parse-outputclj

(parse-output response {:keys [outputs]})

Parse LLM output based on module's output field definitions.

Parameters:

  • response: The LLM response string
  • module: The module definition with :outputs

Returns a map with field names as keys and parsed values.

Example: (parse-output llm-response {:outputs [{:name :answer :spec :string} {:name :confidence :spec :boolean}]})

Parse LLM output based on module's output field definitions.

Parameters:
- response: The LLM response string
- module: The module definition with :outputs

Returns a map with field names as keys and parsed values.

Example:
  (parse-output llm-response {:outputs [{:name :answer :spec :string}
                                        {:name :confidence :spec :boolean}]})
sourceraw docstring

parse-streaming-json-arrayclj

(parse-streaming-json-array accumulated-text)

Progressively parse a JSON array from accumulated text. Returns a vector of parsed items found so far.

This handles incomplete JSON by extracting complete objects and leaving incomplete ones for the next iteration.

Progressively parse a JSON array from accumulated text.
Returns a vector of parsed items found so far.

This handles incomplete JSON by extracting complete objects and leaving
incomplete ones for the next iteration.
sourceraw docstring

parse-streaming-outputclj

(parse-streaming-output accumulated-text module)

Parse streaming LLM output progressively.

Parameters:

  • accumulated-text: The accumulated response text so far
  • module: The module definition with :outputs

Returns parsed output, which may be partial/incomplete.

Parse streaming LLM output progressively.

Parameters:
- accumulated-text: The accumulated response text so far
- module: The module definition with :outputs

Returns parsed output, which may be partial/incomplete.
sourceraw docstring

predictclj

(predict module input-map & [options])

Make a prediction using an LLM.

Parameters:

  • module: The module definition with :inputs/:outputs fields containing :spec for Malli schemas
  • input-map: Map of input field names to values
  • options: Optional configuration map (e.g., :model, :temperature, :validate?)

Options:

  • :model - LLM model to use
  • :temperature - Temperature for sampling
  • :validate? - Whether to validate inputs/outputs with Malli specs (default: true)

Returns parsed output as a map based on module's output fields.

Example: (predict qa-module {:question "What is 2+2?"} {:model "gpt-4"})

Make a prediction using an LLM.

Parameters:
- module: The module definition with :inputs/:outputs fields containing :spec for Malli schemas
- input-map: Map of input field names to values
- options: Optional configuration map (e.g., :model, :temperature, :validate?)

Options:
- :model - LLM model to use
- :temperature - Temperature for sampling
- :validate? - Whether to validate inputs/outputs with Malli specs (default: true)

Returns parsed output as a map based on module's output fields.

Example:
  (predict qa-module {:question "What is 2+2?"} {:model "gpt-4"})
sourceraw docstring

predict-streamclj

(predict-stream module input-map & [options])

Stream predictions from an LLM with progressive structured output parsing.

Parameters:

  • module: The module definition with :inputs/:outputs fields
  • input-map: Map of input field names to values
  • options: Configuration map with :model, :on-chunk callback, :debounce-ms, etc.

Options:

  • :model - LLM model to use
  • :temperature - Temperature for sampling
  • :validate? - Whether to validate inputs/outputs with Malli specs (default: false for streaming)
  • :debounce-ms - Milliseconds to debounce emissions (default: 10)
  • :on-chunk - Optional callback function called with each chunk

Returns: core.async channel that emits progressively parsed output maps.

Example: (let [ch (predict-stream whales-module {:query "Tell me about whales"} {:model "gpt-4"})] (go-loop [] (when-let [output (<! ch)] (println output) (recur))))

Stream predictions from an LLM with progressive structured output parsing.

Parameters:
- module: The module definition with :inputs/:outputs fields
- input-map: Map of input field names to values
- options: Configuration map with :model, :on-chunk callback, :debounce-ms, etc.

Options:
- :model - LLM model to use
- :temperature - Temperature for sampling
- :validate? - Whether to validate inputs/outputs with Malli specs (default: false for streaming)
- :debounce-ms - Milliseconds to debounce emissions (default: 10)
- :on-chunk - Optional callback function called with each chunk

Returns: core.async channel that emits progressively parsed output maps.

Example:
  (let [ch (predict-stream whales-module {:query "Tell me about whales"} {:model "gpt-4"})]
    (go-loop []
      (when-let [output (<! ch)]
        (println output)
        (recur))))
sourceraw docstring

spec->type-strclj

(spec->type-str spec)

Convert Malli spec to string type representation.

Convert Malli spec to string type representation.
sourceraw docstring

validate-fieldclj

(validate-field field value)

Validate a single field value against its Malli spec.

Parameters:

  • field: Field definition with :name, :spec, :description
  • value: The value to validate

Returns value if valid, throws exception if invalid.

Validate a single field value against its Malli spec.

Parameters:
- field: Field definition with :name, :spec, :description
- value: The value to validate

Returns value if valid, throws exception if invalid.
sourceraw docstring

validate-inputsclj

(validate-inputs fields input-map)

Validate all input fields against their Malli specs.

Parameters:

  • fields: Vector of field definitions with :name, :spec, :description
  • input-map: Map of field names to values

Returns input-map if valid, throws exception if invalid.

Validate all input fields against their Malli specs.

Parameters:
- fields: Vector of field definitions with :name, :spec, :description
- input-map: Map of field names to values

Returns input-map if valid, throws exception if invalid.
sourceraw docstring

validate-outputsclj

(validate-outputs fields output-map)

Validate all output fields against their Malli specs.

Parameters:

  • fields: Vector of field definitions with :name, :spec, :description
  • output-map: Map of field names to values

Returns output-map if valid, throws exception if invalid.

Validate all output fields against their Malli specs.

Parameters:
- fields: Vector of field definitions with :name, :spec, :description
- output-map: Map of field names to values

Returns output-map if valid, throws exception if invalid.
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