UNPKG

@future-agi/sdk

Version:

We help GenAI teams maintain high-accuracy for their Models in production.

199 lines 7.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatasetTableUtils = exports.DataTypeUtils = exports.ModelTypes = exports.SourceChoices = exports.DataTypeChoices = void 0; exports.createColumn = createColumn; exports.createCell = createCell; exports.createRow = createRow; const uuid_1 = require("uuid"); // Data type choices for dataset columns var DataTypeChoices; (function (DataTypeChoices) { DataTypeChoices["TEXT"] = "text"; DataTypeChoices["BOOLEAN"] = "boolean"; DataTypeChoices["INTEGER"] = "integer"; DataTypeChoices["FLOAT"] = "float"; DataTypeChoices["JSON"] = "json"; DataTypeChoices["ARRAY"] = "array"; DataTypeChoices["IMAGE"] = "image"; DataTypeChoices["DATETIME"] = "datetime"; DataTypeChoices["AUDIO"] = "audio"; })(DataTypeChoices || (exports.DataTypeChoices = DataTypeChoices = {})); // Source choices for dataset columns var SourceChoices; (function (SourceChoices) { SourceChoices["EVALUATION"] = "evaluation"; SourceChoices["EVALUATION_TAGS"] = "evaluation_tags"; SourceChoices["EVALUATION_REASON"] = "evaluation_reason"; SourceChoices["RUN_PROMPT"] = "run_prompt"; SourceChoices["EXPERIMENT"] = "experiment"; SourceChoices["OPTIMISATION"] = "optimisation"; SourceChoices["EXPERIMENT_EVALUATION"] = "experiment_evaluation"; SourceChoices["EXPERIMENT_EVALUATION_TAGS"] = "experiment_evaluation_tags"; SourceChoices["OPTIMISATION_EVALUATION"] = "optimisation_evaluation"; SourceChoices["ANNOTATION_LABEL"] = "annotation_label"; SourceChoices["OPTIMISATION_EVALUATION_TAGS"] = "optimisation_evaluation_tags"; SourceChoices["EXTRACTED_JSON"] = "extracted_json"; SourceChoices["CLASSIFICATION"] = "classification"; SourceChoices["EXTRACTED_ENTITIES"] = "extracted_entities"; SourceChoices["API_CALL"] = "api_call"; SourceChoices["PYTHON_CODE"] = "python_code"; SourceChoices["VECTOR_DB"] = "vector_db"; SourceChoices["CONDITIONAL"] = "conditional"; SourceChoices["OTHERS"] = "OTHERS"; })(SourceChoices || (exports.SourceChoices = SourceChoices = {})); var ModelTypes; (function (ModelTypes) { ModelTypes["GENERATIVE_LLM"] = "GenerativeLLM"; ModelTypes["GENERATIVE_IMAGE"] = "GenerativeImage"; })(ModelTypes || (exports.ModelTypes = ModelTypes = {})); // Utility functions for data types exports.DataTypeUtils = { getJavaScriptType(dataType) { const typeMapping = { [DataTypeChoices.TEXT]: 'string', [DataTypeChoices.BOOLEAN]: 'boolean', [DataTypeChoices.INTEGER]: 'number', [DataTypeChoices.FLOAT]: 'number', [DataTypeChoices.JSON]: 'object', [DataTypeChoices.ARRAY]: 'object', [DataTypeChoices.IMAGE]: 'string', [DataTypeChoices.AUDIO]: 'string', [DataTypeChoices.DATETIME]: 'string', }; return typeMapping[dataType] || 'string'; }, getSourceChoices() { return Object.values(SourceChoices).map(source => ({ value: source, displayName: source.replace(/_/g, ' ').toLowerCase() .split(' ') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(' ') })); } }; // Column creation helper function createColumn(options) { var _a; if (!((_a = options.name) === null || _a === void 0 ? void 0 : _a.trim())) { throw new Error("Column name cannot be empty"); } if (options.name.length > 255) { throw new Error("Column name too long (max 255 characters)"); } return { id: (0, uuid_1.v4)(), name: options.name.trim(), dataType: options.dataType, source: options.source || SourceChoices.OTHERS, sourceId: options.sourceId, metadata: options.metadata || {}, isFrozen: options.isFrozen || false, isVisible: options.isVisible !== false, evalTags: options.evalTags || [], averageScore: options.averageScore, orderIndex: options.orderIndex || 0, }; } // Cell creation helper function createCell(options) { if (options.value != null && String(options.value).length > 65535) { throw new Error("Cell value too long (max 65535 characters)"); } return { columnId: options.columnId, rowId: options.rowId, columnName: options.columnName, value: options.value, valueInfos: options.valueInfos || [], metadata: options.metadata || {}, status: options.status, failureReason: options.failureReason, }; } // Row creation helper function createRow(options) { if (!options.cells || options.cells.length === 0) { throw new Error("Row must have at least one cell"); } if (options.order != null && options.order < 0) { throw new Error("Row order must be non-negative"); } const rowId = (0, uuid_1.v4)(); // Ensure each cell has rowId; generate columnId if missing const updatedCells = options.cells.map(cell => (Object.assign(Object.assign({}, cell), { rowId: cell.rowId || rowId, columnId: cell.columnId || (0, uuid_1.v4)() }))); return { id: rowId, order: options.order || 0, cells: updatedCells, }; } // Dataset table utilities exports.DatasetTableUtils = { /** * Convert dataset table to JSON format */ toJson(table) { return JSON.stringify(table, null, 2); }, /** * Convert dataset table to CSV format */ toCsv(table) { if (!table.columns.length || !table.rows.length) { return ''; } // Create header const headers = table.columns.map(col => col.name); const csvLines = [headers.join(',')]; // Add data rows for (const row of table.rows) { const rowData = table.columns.map(col => { const cell = row.cells.find(c => c.columnId === col.id); const value = (cell === null || cell === void 0 ? void 0 : cell.value) || ''; // Escape CSV values const stringValue = String(value); return stringValue.includes(',') || stringValue.includes('"') || stringValue.includes('\n') ? `"${stringValue.replace(/"/g, '""')}"` : stringValue; }); csvLines.push(rowData.join(',')); } return csvLines.join('\n'); }, /** * Convert value based on data type */ convertValue(value, dataType) { if (value == null) return null; try { switch (dataType) { case DataTypeChoices.BOOLEAN: if (typeof value === 'boolean') return value; return String(value).toLowerCase() === 'true'; case DataTypeChoices.INTEGER: return parseInt(String(value), 10); case DataTypeChoices.FLOAT: return parseFloat(String(value)); case DataTypeChoices.JSON: return typeof value === 'string' ? JSON.parse(value) : value; case DataTypeChoices.ARRAY: return Array.isArray(value) ? value : [value]; case DataTypeChoices.DATETIME: return new Date(String(value)).toISOString(); case DataTypeChoices.TEXT: case DataTypeChoices.IMAGE: case DataTypeChoices.AUDIO: default: return String(value); } } catch (error) { console.warn(`Failed to convert value "${value}" to ${dataType}:`, error); return String(value); } } }; //# sourceMappingURL=types.js.map