UNPKG

@arizeai/phoenix-evals

Version:
67 lines 2.13 kB
import type { EvaluationResult } from "../types/index.js"; /** * Converts an unknown value to an {@link EvaluationResult}. * * This function provides a flexible way to normalize various return types from * evaluator functions into a standardized `EvaluationResult` format. It handles * multiple input types: * * - **Numbers**: Converted to `{ score: number }` * - **Strings**: Converted to `{ label: string }` * - **Objects**: Extracts `score`, `label`, and `explanation` properties if present * - **Other types**: Returns an empty `EvaluationResult` object * * This is particularly useful when creating evaluators from functions that may * return different types, ensuring consistent evaluation result formatting. * * @param result - The value to convert to an EvaluationResult. Can be: * - A number (converted to score) * - A string (converted to label) * - An object with optional `score`, `label`, and/or `explanation` properties * - Any other value (returns empty object) * * @returns An {@link EvaluationResult} object with extracted properties * * @example * Convert a number to an EvaluationResult: * ```typescript * const result = toEvaluationResult(0.95); * // Returns: { score: 0.95 } * ``` * * @example * Convert a string to an EvaluationResult: * ```typescript * const result = toEvaluationResult("correct"); * // Returns: { label: "correct" } * ``` * * @example * Convert an object with all properties: * ```typescript * const result = toEvaluationResult({ * score: 0.9, * label: "high", * explanation: "High quality output" * }); * // Returns: { score: 0.9, label: "high", explanation: "High quality output" } * ``` * * @example * Convert an object with partial properties: * ```typescript * const result = toEvaluationResult({ score: 0.8 }); * // Returns: { score: 0.8 } * ``` * * @example * Handle null or undefined: * ```typescript * const result = toEvaluationResult(null); * // Returns: {} * ``` * * @public */ export declare function toEvaluationResult(result: unknown): EvaluationResult; //# sourceMappingURL=toEvaluationResult.d.ts.map