UNPKG

@arizeai/phoenix-client

Version:

A client for the Phoenix API

53 lines 2.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.appendDatasetExamples = appendDatasetExamples; const client_1 = require("../client"); const getDatasetInfo_1 = require("./getDatasetInfo"); const tiny_invariant_1 = __importDefault(require("tiny-invariant")); /** * Append examples to an existing dataset * @experimental this interface may change in the future */ async function appendDatasetExamples({ client: _client, dataset, examples, }) { var _a; const client = _client || (0, client_1.createClient)(); const inputs = examples.map((example) => example.input); const outputs = examples.map((example) => { var _a; return (_a = example.output) !== null && _a !== void 0 ? _a : {}; }); // Treat null as an empty object const metadata = examples.map((example) => { var _a; return (_a = example.metadata) !== null && _a !== void 0 ? _a : {}; }); const splits = examples.map((example) => example.splits !== undefined ? example.splits : null); let datasetName; if ("datasetName" in dataset) { datasetName = dataset.datasetName; } else { const datasetInfo = await (0, getDatasetInfo_1.getDatasetInfo)({ client, dataset, }); datasetName = datasetInfo.name; } const appendResponse = await client.POST("/v1/datasets/upload", { params: { query: { sync: true, }, }, body: { name: datasetName, action: "append", inputs, outputs, metadata, splits, }, }); (0, tiny_invariant_1.default)((_a = appendResponse.data) === null || _a === void 0 ? void 0 : _a.data, "Failed to append dataset examples"); const datasetId = appendResponse.data.data.dataset_id; return { datasetId, }; } //# sourceMappingURL=appendDatasetExamples.js.map