UNPKG

@arizeai/phoenix-client

Version:
59 lines 2.5 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDatasetExamples = getDatasetExamples; const tiny_invariant_1 = __importDefault(require("tiny-invariant")); const client_1 = require("../client"); const getDatasetInfoByName_1 = require("./getDatasetInfoByName"); /** * Get examples from a dataset * @param dataset - Dataset selector (ID, name, version ID, or splits) * @returns Dataset examples */ async function getDatasetExamples({ client: _client, dataset: datasetSelector, }) { var _a; const client = _client || (0, client_1.createClient)(); let datasetId; if ("datasetName" in datasetSelector) { const datasetInfo = await (0, getDatasetInfoByName_1.getDatasetInfoByName)({ client, datasetName: datasetSelector.datasetName, }); datasetId = datasetInfo.id; } else { datasetId = datasetSelector.datasetId; } const { versionId, splits } = datasetSelector; const response = await client.GET("/v1/datasets/{id}/examples", { params: { path: { id: datasetId, }, query: Object.assign(Object.assign({}, (versionId ? { version_id: versionId } : {})), (splits ? { split: splits } : {})), }, }); (0, tiny_invariant_1.default)((_a = response.data) === null || _a === void 0 ? void 0 : _a.data, "Failed to get dataset examples"); const examplesData = response.data.data; return { versionId: examplesData.version_id, examples: examplesData.examples.map((_a) => { var { node_id, updated_at } = _a, example = __rest(_a, ["node_id", "updated_at"]); return (Object.assign(Object.assign({}, example), { nodeId: node_id, updatedAt: new Date(updated_at) })); }), }; } //# sourceMappingURL=getDatasetExamples.js.map