UNPKG

@arizeai/phoenix-client

Version:
121 lines 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PROGRESS_PREFIX = void 0; exports.logTaskSummary = logTaskSummary; exports.logEvalSummary = logEvalSummary; exports.logLinks = logLinks; exports.logExperimentResumeSummary = logExperimentResumeSummary; exports.logEvalResumeSummary = logEvalResumeSummary; /** * Progress line prefixes used in experiment run output. * e.g. "[start] Tasks (3 examples × 1 repetition)" */ exports.PROGRESS_PREFIX = { start: "[start] ", progress: "[progress] ", completed: "[completed] ", }; /** * Log a task summary table. * Outputs a header + a single-row table keyed as "summary". */ function logTaskSummary(logger, { nExamples, repetitions, nRuns, nErrors, }) { logger.info(""); logger.info("Task Summary"); const row = { examples: nExamples }; if (repetitions > 1) row.repetitions = repetitions; row.runs = nRuns; if (nErrors > 0) row.errors = nErrors; logger.table({ summary: row }); } /** * Log an evaluation summary table, keyed by evaluator name. * Aggregates scores and labels per evaluator. */ function logEvalSummary(logger, evalRuns) { var _a, _b; logger.info(""); logger.info("Evaluation Summary"); const byEvaluator = new Map(); for (const ev of evalRuns) { const list = (_a = byEvaluator.get(ev.name)) !== null && _a !== void 0 ? _a : []; list.push(ev); byEvaluator.set(ev.name, list); } const tableObj = {}; for (const [name, evs] of byEvaluator.entries()) { const scores = evs.flatMap((ev) => { var _a; return ((_a = ev.result) === null || _a === void 0 ? void 0 : _a.score) != null ? [ev.result.score] : []; }); const labels = evs.flatMap((ev) => { var _a; return ((_a = ev.result) === null || _a === void 0 ? void 0 : _a.label) != null ? [ev.result.label] : []; }); const errors = evs.filter((ev) => ev.error != null); const row = { runs: evs.length }; if (errors.length > 0) row.errors = errors.length; if (scores.length > 0) { row.scores = scores.length; row["avg score"] = Number((scores.reduce((a, b) => a + b, 0) / scores.length).toFixed(3)); } if (labels.length > 0) { row.labels = labels.length; const counts = {}; for (const label of labels) counts[label] = ((_b = counts[label]) !== null && _b !== void 0 ? _b : 0) + 1; const topLabels = Object.entries(counts) .sort((a, b) => b[1] - a[1]) .slice(0, 2); if (topLabels[0]) row["label 1"] = `${topLabels[0][0]} (${topLabels[0][1]})`; if (topLabels[1]) row["label 2"] = `${topLabels[1][0]} (${topLabels[1][1]})`; } tableObj[name] = row; } logger.table(tableObj); } /** * Log a padded "Links" block. * Labels are padded to align URLs. No-ops when links is empty. */ function logLinks(logger, links) { if (links.length === 0) return; const maxLen = Math.max(...links.map((link) => link.label.length)); logger.info(""); logger.info("Links"); for (const { label, url } of links) { logger.info(` ${label.padEnd(maxLen)} ${url}`); } logger.info(""); } /** * Log experiment resume summary table. * Outputs a header + a single-row table keyed as "summary". */ function logExperimentResumeSummary(logger, { experimentId, processed, completed, failed, }) { logger.info("Experiment Resume Summary"); logger.table({ summary: { "experiment id": experimentId, processed, completed, failed, }, }); } /** * Log evaluation resume summary table. * Outputs a header + a single-row table keyed as "summary". */ function logEvalResumeSummary(logger, { experimentId, processed, completed, failed, }) { logger.info("Evaluation Resume Summary"); logger.table({ summary: { "experiment id": experimentId, processed, completed, failed, }, }); } //# sourceMappingURL=logging.js.map