agsamantha/node_modules/langchain/dist/chains/combine_documents/base.js
2024-10-02 15:15:21 -05:00

12 lines
693 B
JavaScript

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);
}