UNPKG

@arizeai/phoenix-evals

Version:
50 lines 2.85 kB
"use strict"; 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.createDocumentRelevanceEvaluator = createDocumentRelevanceEvaluator; const default_templates_1 = require("../__generated__/default_templates"); const createClassificationEvaluator_1 = require("./createClassificationEvaluator"); /** * Creates a document relevance evaluator function. * * This function returns an evaluator that determines whether a given document text * is relevant to a provided input question. The evaluator uses a classification model * and a prompt template to make its determination. * * @param args - The arguments for creating the document relevance evaluator. * @param args.model - The model to use for classification. * @param args.choices - The possible classification choices (defaults to DOCUMENT_RELEVANCE_CHOICES). * @param args.promptTemplate - The prompt template to use (defaults to DOCUMENT_RELEVANCE_TEMPLATE). * @param args.telemetry - The telemetry to use for the evaluator. * * @returns An evaluator function that takes a {@link DocumentRelevanceExample} and returns a classification result * indicating whether the document is relevant to the input question. * * @example * ```ts * const evaluator = createDocumentRelevanceEvaluator({ model: openai("gpt-4o-mini") }); * const result = await evaluator.evaluate({ * input: "What is the capital of France?", * documentText: "Paris is the capital and most populous city of France.", * }); * console.log(result.label); // "relevant" or "unrelated" * ``` */ function createDocumentRelevanceEvaluator(args) { const { choices = default_templates_1.DOCUMENT_RELEVANCE_CLASSIFICATION_EVALUATOR_CONFIG.choices, promptTemplate = default_templates_1.DOCUMENT_RELEVANCE_CLASSIFICATION_EVALUATOR_CONFIG.template, optimizationDirection = default_templates_1.DOCUMENT_RELEVANCE_CLASSIFICATION_EVALUATOR_CONFIG.optimizationDirection, name = default_templates_1.DOCUMENT_RELEVANCE_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=createDocumentRelevanceEvaluator.js.map