UNPKG

@arizeai/phoenix-client

Version:

A client for the Phoenix API

44 lines 1.63 kB
import { createClient } from "../client.js"; import invariant from "tiny-invariant"; const DEFAULT_PAGE_SIZE = 100; /** * A function that gets all the runs (e.g. the results) of a experiment */ export async function getExperimentRuns({ client: _client, experimentId, pageSize = DEFAULT_PAGE_SIZE, }) { const client = _client || createClient(); // Validate that the parameter is an integer and exit early invariant(Number.isInteger(pageSize) && pageSize > 0, "pageSize must be a positive integer greater than 0"); const runs = []; let cursor = null; do { const res = await client.GET("/v1/experiments/{experiment_id}/runs", { params: { path: { experiment_id: experimentId, }, query: { cursor, limit: pageSize, }, }, }); // NB: older versions of phoenix simply don't respond with a cursor and fetch all cursor = res.data?.next_cursor || null; const data = res.data?.data; invariant(data, "Failed to fetch runs"); runs.push(...data.map((run) => ({ id: run.id, traceId: run.trace_id || null, experimentId: run.experiment_id, datasetExampleId: run.dataset_example_id, startTime: new Date(run.start_time), endTime: new Date(run.end_time), output: run.output, error: run.error || null, }))); } while (cursor != null); return { runs, }; } //# sourceMappingURL=getExperimentRuns.js.map