Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[patch]: Fix rollup warning #5929

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions langchain-core/src/prompts/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import mustache from "mustache";
import { MessageContent } from "../messages/index.js";
import type { InputValues } from "../utils/types/index.js";

// Use unescaped HTML
// https://github.com/janl/mustache.js?tab=readme-ov-file#variables
mustache.escape = (text) => text;
function configureMustache() {
// Use unescaped HTML
// https://github.com/janl/mustache.js?tab=readme-ov-file#variables
mustache.escape = (text) => text;
}

/**
* Type that specifies the format of a template.
Expand Down Expand Up @@ -99,6 +101,7 @@ const mustacheTemplateToNodes = (
});

export const parseMustache = (template: string) => {
configureMustache();
const parsed = mustache.parse(template);
return mustacheTemplateToNodes(parsed);
};
Expand All @@ -115,8 +118,10 @@ export const interpolateFString = (template: string, values: InputValues) =>
return res + node.text;
}, "");

export const interpolateMustache = (template: string, values: InputValues) =>
mustache.render(template, values);
export const interpolateMustache = (template: string, values: InputValues) => {
configureMustache();
return mustache.render(template, values);
};

/**
* Type that represents a function that takes a template string and a set
Expand Down