UNPKG

@arizeai/phoenix-evals

Version:

A library for running evaluations for AI use cases

40 lines 1.92 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.generateClassification = generateClassification; const ai_1 = require("ai"); const zod_1 = require("zod"); const telemetry_1 = require("../telemetry"); /** * A function that leverages an llm to perform a classification */ async function generateClassification(args) { var _a, _b; const { labels, model, schemaName, schemaDescription, telemetry } = args, prompt = __rest(args, ["labels", "model", "schemaName", "schemaDescription", "telemetry"]); const experimental_telemetry = { isEnabled: (_a = telemetry === null || telemetry === void 0 ? void 0 : telemetry.isEnabled) !== null && _a !== void 0 ? _a : true, functionId: "generateClassification", tracer: (_b = telemetry === null || telemetry === void 0 ? void 0 : telemetry.tracer) !== null && _b !== void 0 ? _b : telemetry_1.tracer, }; const result = await (0, ai_1.generateObject)(Object.assign({ model, schemaName, schemaDescription, schema: zod_1.z.object({ explanation: zod_1.z.string(), // We place the explanation in hopes it uses reasoning to explain the label. label: zod_1.z.enum(labels), }), experimental_telemetry }, prompt)); return { label: result.object.label, explanation: result.object.explanation, }; } //# sourceMappingURL=generateClassification.js.map