UNPKG

@arizeai/phoenix-evals

Version:
30 lines 1.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatTemplate = formatTemplate; const mustache_1 = __importDefault(require("mustache")); const createTemplateVariablesProxy_1 = require("./createTemplateVariablesProxy"); /** * A function that applies a set of variables to a template (e.g. a prompt) * Uses the Mustache library to apply the variables to the template */ function formatTemplate(args) { const { template, variables } = args; const variablesProxy = (0, createTemplateVariablesProxy_1.createTemplateVariablesProxy)(variables); if (typeof template === "string") { return renderTemplateString(template, variablesProxy); } return template.map((message) => { if (message.content !== undefined && typeof message.content === "string") { return Object.assign(Object.assign({}, message), { content: renderTemplateString(message.content, variablesProxy) }); } return message; }); } function renderTemplateString(template, variables) { // Disable HTML escaping by providing a custom escape function that returns text as-is return mustache_1.default.render(template, variables, {}, { escape: (text) => text }); } //# sourceMappingURL=applyTemplate.js.map