UNPKG

parea-ai

Version:

Client SDK library to connect to Parea AI.

78 lines (77 loc) 3.15 kB
import { ExperimentOptions, ExperimentResult, RunOptions, TracedFunction, TrialResult } from './types'; import { Parea } from '../client'; import { EvaluationResult, ExperimentStatus } from '../types'; /** * Represents an experiment that can be run with multiple trials. * @template T - The type of the dataset elements * @template R - The type of the result returned by the traced function */ export declare class Experiment<T extends Record<string, any>, R> { private name; private dataset; private func; private options; runName: string; private state; private runner; private p; private successRate; private errors; private logs; /** * Creates a new Experiment instance. * @param name The name of the experiment. * @param dataset The dataset to be used for the experiment. * @param func The function to be executed for each trial. * @param options Additional options for the experiment. * @param parea The Parea client instance. */ constructor(name: string, dataset: string | T[], func: TracedFunction<T, R>, options: ExperimentOptions, parea: Parea); /** * Runs the experiment and returns the results. * @param runNameOrOptions run name as a string or {runName?, prefix?}. If prefix is provided, it will be prepended to the final run name. * @example * ```typescript * run(); * run("myRunName"); * run({ prefix: "substep" }); * run({ runName: "myRunName", prefix: "substep" }) * ``` * @returns A promise that resolves to the experiment results. * @throws Error if the experiment fails to run. */ run(runNameOrOptions?: string | RunOptions | undefined): Promise<ExperimentResult<T, R>>; /** * Gets the current state of the experiment. * @returns The current experiment status. */ getState(): ExperimentStatus; /** * Determines the overall state of the experiment based on trial results. * @param results An array of trial results. * @returns The determined experiment status. */ determineState(results: TrialResult<any, any>[]): ExperimentStatus; /** * Calculates dataset-level statistics based on evaluation functions. * @returns A promise that resolves to an array of evaluation results or null. */ getDatasetLevelStats(): Promise<EvaluationResult[] | null>; /** * Determines the dataset to be used for the experiment. * @param dataset The input dataset, either as a string (collection name) or an array of data. * @returns A promise that resolves to the array of dataset elements. * @throws Error if the specified collection is not found. */ determineDataset(dataset: string | T[]): Promise<T[]>; /** * Logs the results of the experiment. * @param experimentUUID The UUID of the experiment. */ logExperimentResults(experimentUUID: string): Promise<void>; /** * Set Dataset name as metadata is using dataset * @param dataset The input dataset, either as a string (collection name) or an array of data. */ private trySetDataset; }