UNPKG

@synthart/synthlite

Version:

A fast, lightweight Gen AI powered synthetic data generator written in TypeScript. 🌞

72 lines (71 loc) 3.08 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SynthLiteCLI = void 0; const core_1 = require("./core"); const common_1 = require("./common"); const cli_1 = require("./core/cli"); class SynthLiteCLI { /** * Private constructor to prevent direct instantiation. */ constructor() { } /** * Sets up the SynthLite CLI. * @returns void */ setup() { return __awaiter(this, void 0, void 0, function* () { common_1.printer.printBanner(); const options = yield cli_1.CLI.getOptions(); common_1.printer.setVerbose(options.verbose); common_1.Config.assertAIConfig(); core_1.SynthliteEmitter.getInstance().addOnDataGeneratedSaveFileListener(options); return options; }); } /** * Generates the dataset. * @param options The CLI options created by the user * @param dataset The dataset to generate * @returns void */ generateDataset(options, dataset) { return __awaiter(this, void 0, void 0, function* () { common_1.printer.success(`Generating dataset of rows: ${options.rows}.`); yield dataset.generate(parseInt(options.rows)); common_1.printer.success(`Dataset saved to: ${options.output}!`); common_1.printer.success("SynthLite run completed successfully! ⚡️"); }); } /** * Runs the SynthLite CLI. ⚡️ * @returns Promise<void> */ run() { return __awaiter(this, void 0, void 0, function* () { try { const options = yield this.setup(); common_1.printer.info("Parsing schema and constructing dataset."); const dataset = yield core_1.SynthliteDataset.fromSchemaFile(options.schema); const generateStartTime = performance.now(); yield this.generateDataset(options, dataset); const totalTimeInSeconds = (performance.now() - generateStartTime) / 1000; common_1.printer.success(`Dataset for schema '${options.schema}' generated in ${totalTimeInSeconds} seconds.`); } catch (error) { common_1.printer.error(`Unexpected Failure: ${error.message}`); process.exit(1); } }); } } exports.SynthLiteCLI = SynthLiteCLI;