mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-21 14:43:07 +00:00
wip
This commit is contained in:
@@ -14,6 +14,19 @@ from langchain.chains.combine_documents.reduce import ReduceDocumentsChain
|
||||
from langchain.chains.llm import LLMChain
|
||||
|
||||
|
||||
def create_map_reduce_documents_chain(mapdocument_input_key: str) -> Runnable:
|
||||
# The chain we'll apply to each individual document.
|
||||
# Returns a summary of the document.
|
||||
map_chain = map_prompt | llm | StrOutputParser()
|
||||
|
||||
# A wrapper chain to keep the original Document metadata
|
||||
map_as_doc_chain = (
|
||||
RunnableParallel({"doc": RunnablePassthrough(), "content": map_chain})
|
||||
| (lambda x: Document(page_content=x["content"],
|
||||
metadata=x["doc"].metadata))
|
||||
).with_config(run_name="Summarize (return doc)")
|
||||
|
||||
|
||||
class MapReduceDocumentsChain(BaseCombineDocumentsChain):
|
||||
"""Combining documents by mapping a chain over them, then combining results.
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ def create_stuff_documents_chain(
|
||||
llm: LanguageModelLike,
|
||||
prompt: BasePromptTemplate,
|
||||
output_parser: BaseOutputParser,
|
||||
document_input_key: str,
|
||||
*,
|
||||
document_input_key: str,
|
||||
document_prompt: Optional[BasePromptTemplate] = None,
|
||||
document_separator: str = "\n\n",
|
||||
output_key: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user