UNPKG

parea-ai

Version:

Client SDK library to connect to Parea AI.

41 lines (40 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EvaluationHandler = void 0; const helpers_1 = require("../helpers"); /** * Handles the evaluation of trace logs using multiple evaluation functions. */ class EvaluationHandler { /** * Creates an instance of EvaluationHandler. * @param evalFuncs - An array of evaluation functions to be executed. * @param traceManger - The TraceManager instance for managing trace data. */ constructor(evalFuncs, traceManger) { this.evalFuncs = evalFuncs; this.traceManger = traceManger; } /** * Runs all evaluation functions on the provided trace log. * @param traceLog - The trace log to be evaluated. * @returns A promise that resolves to an array of EvaluationResult objects. * @throws Will log errors to the trace manager and console if an evaluation function fails. */ async runEvaluations(traceLog) { const scores = []; for (const func of this.evalFuncs) { try { const result = await func(traceLog); (0, helpers_1.processEvaluationResult)(func.name, result, scores); } catch (error) { const msg = `Error occurred calling evaluation function '${func.name} for trace ${traceLog.trace_name}: trace_id: ${traceLog.trace_id}', ${error.toString()}`; this.traceManger.insertTraceData({ error: msg, status: 'error' }, traceLog.trace_id); console.error(msg, error); } } return scores; } } exports.EvaluationHandler = EvaluationHandler;