Packages

Compile-time contract DSL, two-tier content-addressed cache, and execution runner for ReqLLM.Evaluation (TypeSafe Jev, Gemini Decisions, and more).

Current section

Files

Jump to
Raw

README.md

# SystemOneDSL

[![CI](https://github.com/boxxxie/jev_dsl/actions/workflows/ci.yml/badge.svg)](https://github.com/boxxxie/jev_dsl/actions/workflows/ci.yml)
[![Hex.pm](https://img.shields.io/hexpm/v/system_one_dsl.svg)](https://hex.pm/packages/system_one_dsl)
[![HexDocs](https://img.shields.io/badge/docs-hexdocs-blue.svg)](https://hexdocs.pm/system_one_dsl)
[![License: MIT](https://img.shields.io/hexpm/l/system_one_dsl.svg)](LICENSE)
[![Elixir](https://img.shields.io/badge/elixir-~%3E%201.20-purple.svg)](https://elixir-lang.org)

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

```elixir
def deps do
  [
    {:system_one_dsl, "~> 1.0"}
  ]
end
```

## Quick Start

```elixir
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
end
```

## Multi-Provider Evaluation

`SystemOneDSL` defaults to `"typesafe:jev-latest"` and can target any `ReqLLM.Evaluation` model per module or per call without cache collisions:

```elixir
# 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}]`):

```elixir
{:ok, mocked} =
  MyApp.TriageContracts.evaluate(:is_spam, %{text: "hello"},
    eval_fn: fn _state -> {:ok, %{answers: %{is_spam: %{probability: 0.05}}}} end
  )
```