mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
ed789be8f4
- chat models, messages - documents - agentaction/finish - baseretriever,document - stroutputparser - more messages - basemessage - format_document - baseoutputparser --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
28 lines
672 B
Python
28 lines
672 B
Python
from string import Formatter
|
|
from typing import List
|
|
|
|
from langchain_core.documents import Document
|
|
|
|
document_template = """
|
|
PASSAGE: {page_content}
|
|
METADATA: {metadata}
|
|
"""
|
|
|
|
|
|
def combine_documents(documents: List[Document]) -> str:
|
|
"""
|
|
Combine a list of documents into a single string that might be passed further down
|
|
to a language model.
|
|
:param documents: list of documents to combine
|
|
:return:
|
|
"""
|
|
formatter = Formatter()
|
|
return "\n\n".join(
|
|
formatter.format(
|
|
document_template,
|
|
page_content=document.page_content,
|
|
metadata=document.metadata,
|
|
)
|
|
for document in documents
|
|
)
|