@arizeai/phoenix-client
Version:
A client for the Phoenix API
55 lines • 2.86 kB
TypeScript
import { type SuiteState } from "./state";
import type { Annotation, EvaluationParams, EvaluationResult, Evaluator, KVMap } from "./types";
/**
* Log the output produced by the test for the current run.
*
* Calling this multiple times overwrites the previously recorded value.
* The argument can be any JSON-serializable value — typically an object
* matching the shape of the example's `expected` field.
*/
export declare function logOutput(output: unknown): void;
/**
* Record an annotation on the current run.
*
* Annotations are collected during the test and posted to Phoenix as
* experiment evaluations after the test completes. The `name` is the
* Phoenix evaluation name; `score`, `label`, and `explanation` map to
* the standard Phoenix `EvaluationResult` fields.
*
* The annotation name `"pass"` is reserved — Phoenix eval tests always write
* a `pass` annotation derived from the test's assertion outcome, so a
* user-supplied annotation with that name would race / overwrite the
* built-in one. Such calls are silently ignored.
*/
export declare function logAnnotation(annotation: Annotation): void;
/**
* Run an evaluator object against the current test run and record the result.
*
* The evaluator may come from `@arizeai/phoenix-evals.createEvaluator`,
* `asExperimentEvaluator`, or any plain object with `{ name, evaluate }`.
* When `params` is omitted, the current test's `input`, recorded `output`,
* `expected`, `metadata`, and task `traceId` are supplied.
*/
export declare function evaluate<Params extends KVMap = EvaluationParams & KVMap, Result = EvaluationResult>(evaluator: Evaluator<Params, Result>, params?: Partial<Params> & KVMap): Promise<Result>;
/**
* Trace an evaluator function so its execution shows up as a separate
* `EVALUATOR` span in Phoenix and any `{ name, score }`-shaped return
* value is automatically captured as an annotation on the current run.
*
* The annotation name defaults to the traced function's name, falling
* back to `"evaluator"`.
*/
export declare function traceEvaluator<EvaluatorParams extends KVMap, EvaluatorResult>(fn: (params: EvaluatorParams) => EvaluatorResult | Promise<EvaluatorResult>, options?: {
name?: string;
}): (params: EvaluatorParams) => Promise<EvaluatorResult>;
/**
* Internal: persist all collected annotations for the run.
*
* Phoenix's `experiment_evaluations` endpoint is keyed by
* `(experiment_run_id, name)` so two annotations with the same name on
* the same run race each other. We collapse duplicates by name (last
* wins) up front, which makes the final state deterministic; the
* remaining writes target distinct names, so they post in parallel.
*/
export declare function flushAnnotations(runId: string | undefined, annotations: Annotation[], suite: SuiteState): Promise<void>;
//# sourceMappingURL=helpers.d.ts.map