Documentation
¶
Overview ¶
Package eval grades an AI target against cases with deterministic checks or a judge model. Evals spend tokens, so they live in tests behind the eval build tag and run with `fletch test --evals`:
//go:build eval
func TestRefunds(t *testing.T) {
eval.Run(t, eval.Model(assistant), eval.Cases{
{Input: "I want a refund for a 45-day-old order", Expect: eval.Rubric("declines; cites the 30-day policy")},
}, eval.Judge(judge), eval.Threshold(0.8), eval.Repeat(3))
}
When ReportDirEnv names a directory, Run writes one JSON Report there per call; `fletch test --evals` collects them into .fletch/evals.
Index ¶
Constants ¶
const DefaultThreshold = 0.8
DefaultThreshold is the mean score a case needs when Threshold is not set.
const ReportDirEnv = "FLETCH_EVAL_REPORT_DIR"
ReportDirEnv names the environment variable that holds the directory Run writes its reports to.
Variables ¶
var ErrNoJudge = errors.New("eval: a Rubric needs eval.Judge(model)")
ErrNoJudge is returned for a Rubric case when no Judge is set.
Functions ¶
This section is empty.
Types ¶
type Case ¶
type Case struct {
// Name names the case in reports; default "case_<n>".
Name string
Input string
Expect Expectation
}
Case is one input and what its answer must meet.
type CaseResult ¶
type CaseResult struct {
Name string `json:"name"`
Input string `json:"input"`
Score float64 `json:"score"`
Threshold float64 `json:"threshold"`
Pass bool `json:"pass"`
Attempts []Attempt `json:"attempts"`
}
CaseResult is how one case did.
type Expectation ¶
type Expectation interface {
Grade(ctx context.Context, judge aikit.Model, input, output string) (Score, error)
}
Expectation grades one answer. judge is the Judge model, or nil.
func Contains ¶
func Contains(subs ...string) Expectation
Contains scores the share of subs that the answer contains, ignoring case.
func Rubric ¶
func Rubric(criteria string) Expectation
Rubric is graded by the Judge model against criteria written in plain language.
type Option ¶
type Option func(*config)
Option configures Evaluate and Run.
type Report ¶
type Report struct {
// Test is the test's name and Dir the package directory; Run sets them.
Test string `json:"test,omitempty"`
Dir string `json:"dir,omitempty"`
Cases []CaseResult `json:"cases"`
}
Report is the result of one Evaluate or Run.
func Evaluate ¶
Evaluate asks target each case and grades the answers. An answer that fails, or a grade that errors, scores 0 for that attempt. Only an expectation that cannot be graded at all, such as a Rubric with no Judge, returns an error.