Documentation
¶
Overview ¶
Package eval is used to run evals in Braintrust.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Case ¶
type Case[I, R any] struct { // Input is the input to the task function. Input I // Expected is the expected output (for scoring). // Optional. Expected R // Tags are labels to attach to this case. // Optional. Tags []string // Metadata is additional metadata for this case. // Optional. Metadata map[string]interface{} // These fields are only set if the Case is part of a Dataset. // They link the eval result back to the source dataset row. ID string // Dataset record ID XactID string // Transaction ID Created string // Creation timestamp }
Case represents a single test case in an evaluation.
type Dataset ¶
type Dataset[I, R any] interface { // Next returns the next case, or io.EOF if there are no more cases. Next() (Case[I, R], error) // ID returns the dataset ID if backed by a Braintrust dataset. // Returns empty string for literal in-memory cases. ID() string // Version returns the dataset version if applicable. // Returns empty string for literal cases or unversioned datasets. Version() string }
Dataset is an iterator interface for evaluation datasets. It is commonly an in-memory slice of cases, but can also be a dataset lazily loaded from the Braintrust API.
func NewDataset ¶
NewDataset creates a Dataset iterator from a slice of cases.
type DatasetAPI ¶
type DatasetAPI[I, R any] struct { // contains filtered or unexported fields }
DatasetAPI provides methods for loading datasets with automatic type conversion so they can be easily used in evals.
func (*DatasetAPI[I, R]) Query ¶
func (d *DatasetAPI[I, R]) Query(ctx context.Context, opts DatasetQueryOpts) (Dataset[I, R], error)
Query loads a dataset with advanced query options.
type DatasetQueryOpts ¶
type DatasetQueryOpts struct {
// Name is the dataset name (requires project context)
Name string
// ID is the dataset ID
ID string
// Version specifies a specific dataset version
Version string
// Limit specifies the maximum number of records to return (0 = unlimited)
Limit int
}
DatasetQueryOpts contains options for querying datasets.
type Evaluator ¶
type Evaluator[I, R any] struct { // contains filtered or unexported fields }
Evaluator provides a reusable way to run multiple evaluations with the same input and output types. This is useful when you need to run several evaluations in sequence with the same type signature, or use hosted prompts, scorers and datasets with automatic type conversion.
func NewEvaluator ¶
func NewEvaluator[I, R any](session *auth.Session, cfg *config.Config, tp *trace.TracerProvider) *Evaluator[I, R]
NewEvaluator creates a new evaluator with explicit dependencies. The type parameters I (input) and R (result/output) must be specified explicitly. Most users should use braintrust.NewEvaluator(client).
func (*Evaluator[I, R]) Datasets ¶
func (e *Evaluator[I, R]) Datasets() *DatasetAPI[I, R]
Datasets returns a DatasetAPI for loading datasets with this evaluator's type parameters.
type Opts ¶
type Opts[I, R any] struct { // Experiment is the name of the experiment to create or use. // Required. Experiment string // ProjectName is the name of the project to create the experiment in. // Optional. If not specified, uses the default project from config. ProjectName string // Dataset is an iterator over the test cases to evaluate. // Can be literal in-memory cases or API-backed dataset. // Required. Dataset Dataset[I, R] // Task is the function to evaluate for each case. // It receives the input and should return the output. // Required. Task TaskFunc[I, R] // Scorers are the scoring functions to apply to each case result. // Optional. If empty, no scoring is performed. Scorers []Scorer[I, R] // Tags are labels to attach to the experiment. // Optional. Tags []string // Metadata is additional metadata to attach to the experiment. // Optional. Metadata map[string]interface{} // Update controls whether to update an existing experiment or fail if it exists. // Optional. Defaults to false. Update bool // Parallelism controls the number of goroutines to use for parallel execution. // Optional. Defaults to 1 (sequential execution). // Set to a value > 1 to enable parallel case evaluation. Parallelism int // Quiet controls whether to suppress printing the result summary. // Optional. Defaults to false (summary is printed). // Set to true to suppress output. Quiet bool }
Opts defines the options for running an evaluation. I is the input type and R is the result/output type.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result contains the results of an evaluation.
func Run ¶
func Run[I, R any](ctx context.Context, opts Opts[I, R], cfg *config.Config, session *auth.Session, tp *trace.TracerProvider) (*Result, error)
Run executes an evaluation using client resources (config, session, tracerProvider). This is the main entry point for eval execution.
type Score ¶
type Score struct {
// Name is the name of the score (e.g., "accuracy", "exact_match").
Name string
// Score is the numeric score value.
Score float64
// Metadata is optional additional metadata for this score.
Metadata map[string]interface{}
}
Score represents a single score result.
type Scorer ¶
type Scorer[I, R any] interface { // Name returns the name of this scorer. Name() string // Run evaluates the task result. // It returns one or more Score results. Run(context.Context, TaskResult[I, R]) (Scores, error) }
Scorer is an interface for scoring the output of a task.
type ScorerAPI ¶
type ScorerAPI[I, R any] struct { // contains filtered or unexported fields }
ScorerAPI provides methods for loading scorers for evaluation.
func (*ScorerAPI[I, R]) Query ¶
func (s *ScorerAPI[I, R]) Query(ctx context.Context, opts ScorerQueryOpts) ([]ScorerInfo, error)
Query searches for scorers matching the given options.
type ScorerInfo ¶
ScorerInfo contains metadata about a scorer.
type ScorerQueryOpts ¶
type ScorerQueryOpts struct {
// Project filters scorers by project
Project string
// Name filters by specific name
Name string
}
ScorerQueryOpts contains options for querying scorers.
type TaskAPI ¶
type TaskAPI[I, R any] struct { // contains filtered or unexported fields }
TaskAPI provides methods for loading tasks/prompts for evaluation.
type TaskFunc ¶
TaskFunc is the signature for evaluation task functions. It receives the input, hooks for accessing eval context, and returns a TaskOutput.
func T ¶
T is a simple adapter that converts a basic task function into a TaskFunc. This is useful if your task is only concerned with inputs and outputs. Example:
task := eval.T(func(ctx context.Context, input string) (string, error) {
return input, nil
})
eval.Run(ctx, eval.Opts[string, string]{Task: task, Dataset: cases}, cfg, session, tp)
type TaskHooks ¶
type TaskHooks struct {
// The eval and task spans are included, if you want to add custom attributes or events.
TaskSpan oteltrace.Span
EvalSpan oteltrace.Span
// Readonly fields. These aren't necessarily recommended to be included in the task function,
// but are available for advanced use cases.
Expected any // type-assert
Metadata Metadata
Tags []string
}
TaskHooks provides access to evaluation context within a task. All fields are read-only except for span modification.
type TaskOutput ¶
type TaskOutput[R any] struct { Value R }
TaskOutput wraps the output value from a task.
type TaskResult ¶
type TaskResult[I, R any] struct { Input I // The case input Expected R // What we expected Output R // What the task actually returned Metadata Metadata // Case metadata }
TaskResult represents the complete result of executing a task on a case. This is passed to scorers for evaluation.