@arizeai/phoenix-client
Version:
A client for the Phoenix API
51 lines • 2.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExperimentRuns = getExperimentRuns;
const client_1 = require("../client");
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
const DEFAULT_PAGE_SIZE = 100;
/**
* A function that gets all the runs (e.g. the results) of a experiment
*/
async function getExperimentRuns({ client: _client, experimentId, pageSize = DEFAULT_PAGE_SIZE, }) {
var _a, _b;
const client = _client || (0, client_1.createClient)();
// Validate that the parameter is an integer and exit early
(0, tiny_invariant_1.default)(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 = ((_a = res.data) === null || _a === void 0 ? void 0 : _a.next_cursor) || null;
const data = (_b = res.data) === null || _b === void 0 ? void 0 : _b.data;
(0, tiny_invariant_1.default)(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