Compile-time Elixir macro DSL, model-aware two-tier content-addressed cache, and execution runner for ReqLLM.Evaluation — supporting TypeSafe Jev (typesafe:jev-latest), Google Gemini Decisions (google:gemini-decision-1), OpenAI Decisions (openai:gpt-6-luna), OpenRouter Decisions, and Azure Microsoft Decisions.
Installation
def deps do
[
{:system_one_dsl, "~> 1.0"}
]
endQuick Start
defmodule MyApp.TriageContracts do
use SystemOneDSL,
otp_app: :my_app,
cache: SystemOneDSL.Cache.ETS
defnoul :is_spam do
"Does this message contain unsolicited promotional spam?"
end
defchoice :sentiment, ask: "Classify the overall tone of the message." do
positive -> "Constructive, appreciative, or favorable tone."
neutral -> "Factual or informational without strong emotion."
negative -> "Critical, frustrated, or dissatisfied tone."
end
defscore :completeness, ask: "Rate how complete the submission is." do
incomplete -> "Missing required identity or contact fields."
partial -> "Core fields are present but optional context is missing."
complete -> "All identity, contact, and biographical fields are populated."
end
defcontract :ticket_triage do
noul :requires_escalation do
"Does this issue require immediate engineering escalation?"
end
choice :priority, ask: "Select the appropriate response priority." do
urgent -> "Production outage or security incident."
normal -> "Standard bug report or feature question."
end
end
defalias :legacy_spam, :is_spam
endMulti-Provider Evaluation
SystemOneDSL defaults to "typesafe:jev-latest" and can target any ReqLLM.Evaluation model per module or per call without cache collisions:
# Default ("typesafe:jev-latest")
{:ok, %ReqLLM.Response{} = resp} =
MyApp.TriageContracts.evaluate(:sentiment, %{text: "Great work!"})
{:ok, ans} = SystemOneDSL.fetch_answer(resp, :sentiment)
SystemOneDSL.choice?(ans, :positive)
SystemOneDSL.probability(ans, :positive)
# Google Gemini Decisions (uses GEMINI_API_KEY / GOOGLE_API_KEY)
{:ok, gemini_resp} =
MyApp.TriageContracts.evaluate(:is_spam, %{text: "Buy now!"},
model: "google:gemini-decision-1"
)
# Bounded concurrent batch evaluation (L1/L2 cache hits resolved first)
results =
MyApp.TriageContracts.evaluate_many(:is_spam, [%{text: "a"}, %{text: "b"}],
max_concurrency: 10
)Testing Offline
Use 1-arity :eval_fn stubs or Req.Test plugs (req_http_options: [plug: {Req.Test, MyStub}]):
{:ok, mocked} =
MyApp.TriageContracts.evaluate(:is_spam, %{text: "hello"},
eval_fn: fn _state -> {:ok, %{answers: %{is_spam: %{probability: 0.05}}}} end
)