UNPKG

@arizeai/phoenix-evals

Version:
19 lines (17 loc) 528 B
import type { AnyFn, EvaluatorFn } from "../types"; import { isPromise } from "../utils/typeUtils"; import { toEvaluationResult } from "./toEvaluationResult"; /** * A function that converts a generic function into an evaluator function */ export function asEvaluatorFn<RecordType extends Record<string, unknown>>( fn: AnyFn ): EvaluatorFn<RecordType> { return async (...args) => { let result = fn(...args); if (isPromise(result)) { result = await result; } return toEvaluationResult(result); }; }