Tribunal.ExUnit (Tribunal v3.0.0)

Copy Markdown View Source

ExUnit integration for LLM evaluations.

Usage

defmodule MyApp.RAGEvalTest do
  use ExUnit.Case
  use Tribunal.ExUnit

  @moduletag :eval

  test "response is faithful" do
    response = MyApp.RAG.query("What's the return policy?")

    assert response =~ "30 days"
    assert_faithful response, context: @docs, threshold: 0.8
  end
end

Dataset-Driven Tests

defmodule MyApp.RAGEvalTest do
  use ExUnit.Case
  use Tribunal.ExUnit

  @moduletag :eval

  tribunal_dataset "test/evals/datasets/questions.json",
    provider: {MyApp.RAG, :query}
end

Run with: mix test --only eval

Summary

Functions

Evaluates a zero-arity callback one or more times inside a normal ExUnit test.

Generates tests from a dataset file.

Functions

tribunal_assert(callback, opts)

(macro)

Evaluates a zero-arity callback one or more times inside a normal ExUnit test.

:input and a non-empty :expected assertion list are required. :repeat defaults to 1 and :pass_rule defaults to :all.

tribunal_dataset(path, opts \\ [])

(macro)

Generates tests from a dataset file.

Options

  • :provider - {Module, :function} to call for each input
  • :defaults - Default assertion options