agsamantha/node_modules/langchain/dist/chains/combine_documents/base.js

13 lines
693 B
JavaScript
Raw Normal View History

2024-10-02 20:15:21 +00:00
import { PromptTemplate } from "@langchain/core/prompts";
export const DEFAULT_DOCUMENT_SEPARATOR = "\n\n";
export const DOCUMENTS_KEY = "context";
export const INTERMEDIATE_STEPS_KEY = "intermediate_steps";
export const DEFAULT_DOCUMENT_PROMPT =
/* #__PURE__ */ PromptTemplate.fromTemplate("{page_content}");
export async function formatDocuments({ documentPrompt, documentSeparator, documents, config, }) {
const formattedDocs = await Promise.all(documents.map((document) => documentPrompt
.withConfig({ runName: "document_formatter" })
.invoke({ ...document.metadata, page_content: document.pageContent }, config)));
return formattedDocs.join(documentSeparator);
}