@arizeai/phoenix-evals
Version:
A library for running evaluations for AI use cases
53 lines • 3.1 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHallucinationEvaluator = createHallucinationEvaluator;
const default_templates_1 = require("../__generated__/default_templates");
const createClassificationEvaluator_1 = require("./createClassificationEvaluator");
/**
* Creates a hallucination evaluator function.
*
* This function returns an evaluator that detects whether an assistant's latest
* response contains claims that are not grounded in — unsupported by, or
* contradicting — the conversation. Unlike the faithfulness evaluator, which
* grounds a response against a specific provided context (e.g. retrieved
* documents), this grounds it against the conversation itself.
*
* @param args - The arguments for creating the hallucination evaluator.
* @param args.model - The model to use for classification.
* @param args.choices - The possible classification choices (defaults to hallucinated/grounded).
* @param args.promptTemplate - The prompt template to use (defaults to HALLUCINATION_CLASSIFICATION_EVALUATOR_CONFIG.template).
* @param args.telemetry - The telemetry to use for the evaluator.
*
* @returns An evaluator function that takes a {@link HallucinationEvaluationRecord} and returns a classification result
* indicating whether the response is grounded or hallucinated relative to the conversation.
*
* @example
* ```ts
* const evaluator = createHallucinationEvaluator({ model: openai("gpt-4o-mini") });
* const result = await evaluator.evaluate({
* input:
* "User: What's our refund window?\nTool (lookup_policy): Refunds: 30 days from delivery.\nAssistant: 30 days from delivery.\nUser: And for electronics?",
* output: "Electronics can be returned within 90 days.",
* });
* console.log(result.label); // "hallucinated"
* ```
*/
function createHallucinationEvaluator(args) {
const { choices = default_templates_1.HALLUCINATION_CLASSIFICATION_EVALUATOR_CONFIG.choices, promptTemplate = default_templates_1.HALLUCINATION_CLASSIFICATION_EVALUATOR_CONFIG.template, optimizationDirection = default_templates_1.HALLUCINATION_CLASSIFICATION_EVALUATOR_CONFIG.optimizationDirection, name = default_templates_1.HALLUCINATION_CLASSIFICATION_EVALUATOR_CONFIG.name } = args, rest = __rest(args, ["choices", "promptTemplate", "optimizationDirection", "name"]);
return (0, createClassificationEvaluator_1.createClassificationEvaluator)(Object.assign(Object.assign({}, rest), { promptTemplate,
choices,
optimizationDirection,
name }));
}
//# sourceMappingURL=createHallucinationEvaluator.js.map