@arizeai/phoenix-client
Version:
A client for the Phoenix API
29 lines • 1.19 kB
JavaScript
import { createClient } from "../client.js";
import { createDataset } from "./createDataset.js";
import { getDatasetInfoByName } from "./getDatasetInfoByName.js";
/**
* Given the parameters to create a dataset, this function will either
* retrieve an existing dataset by name or create a new one with the provided parameters.
*
* This is useful in cases where you would like to re-run a pipeline like:
* - ensure dataset exists
* - create a task
* - run experiment
* - evaluate experiment
* without having to create a new dataset each time.
*/
export async function createOrGetDataset({ name, description, examples, client: _client, }) {
const client = _client || createClient();
// start by fetching an existing dataset by name, catching any errors that occur
try {
const dataset = await getDatasetInfoByName({ datasetName: name, client });
return {
datasetId: dataset.id,
};
}
catch {
// If the dataset doesn't exist, create it, falling back to the error handling inside createDataset
return await createDataset({ name, description, examples, client });
}
}
//# sourceMappingURL=createOrGetDataset.js.map