SystemOneDSL (SystemOneDSL v1.0.0)

Copy Markdown View Source

Compile-time Elixir macro DSL, two-tier caching layer, and execution runner for ReqLLM.Evaluation (TypeSafe Jev, Google Gemini Decisions, OpenAI Decisions, and more).

SystemOneDSL compiles %SystemOneDSL.Prepared{} contracts at build time (defnoul, defchoice, defscore, defcontract, defjev, defalias), provides model-aware deterministic SHA-256 content-addressed L1/L2 caching (SystemOneDSL.Cache), and generates evaluate/3, evaluate!/3, evaluate_many/3, available?/2, cache_key/3, contract/1, prepared/1, and __export_cue__/0 directly on your contract module.

Summary

Functions

Returns true if a choice answer map (or choice value) selected expected_option, comparing atoms and strings equivalently.

Aliases a secondary or legacy contract name (atom or string) to a canonical contract name.

Defines a single-question Choice contract using key -> "description" stab clauses.

Defines a multi-question contract combining choice, noul, and/or score sub-questions.

Defines a single-question Noul (boolean probability) contract.

Defines a single-question ordered Score contract (2..10 rubric levels) using label -> "description" stab clauses.

Exports compiled contracts into a CUE schema document.

Fetches an answer from a %ReqLLM.Response{object: answers} (or plain map double with :object or :answers), matching key whether passed as an atom or a string.

Fetches an answer by atom or string key, raising KeyError if not present.

Fetches the probability for option_key (atom or string) from a choice answer or probability map.

Functions

choice?(choice, expected)

@spec choice?(map() | atom() | String.t(), atom() | String.t()) :: boolean()

Returns true if a choice answer map (or choice value) selected expected_option, comparing atoms and strings equivalently.

defalias(alias_name, target_name)

(macro)

Aliases a secondary or legacy contract name (atom or string) to a canonical contract name.

defchoice(name, opts_or_block, maybe_block \\ nil)

(macro)

Defines a single-question Choice contract using key -> "description" stab clauses.

defcontract(name, list)

(macro)

Defines a multi-question contract combining choice, noul, and/or score sub-questions.

defjev(name, list)

(macro)

Alias for defcontract/2.

defnoul(name, opts_or_block \\ [], maybe_block \\ nil)

(macro)

Defines a single-question Noul (boolean probability) contract.

defscore(name, opts_or_block, maybe_block \\ nil)

(macro)

Defines a single-question ordered Score contract (2..10 rubric levels) using label -> "description" stab clauses.

export_cue(contracts_map)

@spec export_cue(%{
  optional(atom() | String.t()) => SystemOneDSL.Contract.t() | map()
}) :: String.t()

Exports compiled contracts into a CUE schema document.

fetch_answer(arg1, key)

@spec fetch_answer(ReqLLM.Response.t() | map(), atom() | String.t()) ::
  {:ok, term()} | :error

Fetches an answer from a %ReqLLM.Response{object: answers} (or plain map double with :object or :answers), matching key whether passed as an atom or a string.

fetch_answer!(response, key)

@spec fetch_answer!(ReqLLM.Response.t() | map(), atom() | String.t()) :: term()

Fetches an answer by atom or string key, raising KeyError if not present.

probability(probs, option_key)

@spec probability(map(), atom() | String.t()) :: {:ok, number()} | :error

Fetches the probability for option_key (atom or string) from a choice answer or probability map.