From ee1d13678edd476916848c14abb98106afbbf05a Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 2 Aug 2023 14:39:41 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Docs=20Fixes=20[2=20one-liners,?= =?UTF-8?q?=20examples=20broken]=20(#8519)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description: 1)Map reduce example in docs is missing an important import statement. Figured other people would benefit from being able to copy 🍝 the code. 2)RefineDocumentsChain example also broken. ## Issue: None ## Dependencies: None. One liner. ## Tag maintainer: @baskaryan ## Twitter handle: I mean, it's a one line fix lol. But @will_thompson_k is my twitter handle. --- docs/snippets/modules/chains/popular/summarize.mdx | 1 + libs/langchain/langchain/chains/combine_documents/refine.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/snippets/modules/chains/popular/summarize.mdx b/docs/snippets/modules/chains/popular/summarize.mdx index 1a48b8e600..e77c327bd3 100644 --- a/docs/snippets/modules/chains/popular/summarize.mdx +++ b/docs/snippets/modules/chains/popular/summarize.mdx @@ -184,6 +184,7 @@ You can also use prompt with multi input. In this example, we will use a MapRedu ```python from langchain.chains.combine_documents.map_reduce import MapReduceDocumentsChain from langchain.chains.combine_documents.stuff import StuffDocumentsChain +from langchain.chains import ReduceDocumentsChain map_template_string = """Give the following python code information, generate a description that explains what the code does and also mention the time complexity. Code: diff --git a/libs/langchain/langchain/chains/combine_documents/refine.py b/libs/langchain/langchain/chains/combine_documents/refine.py index 76087a9877..025e264165 100644 --- a/libs/langchain/langchain/chains/combine_documents/refine.py +++ b/libs/langchain/langchain/chains/combine_documents/refine.py @@ -53,7 +53,7 @@ class RefineDocumentsChain(BaseCombineDocumentsChain): prompt = PromptTemplate.from_template( "Summarize this content: {context}" ) - llm_chain = LLMChain(llm=llm, prompt=prompt) + initial_llm_chain = LLMChain(llm=llm, prompt=prompt) initial_response_name = "prev_response" # The prompt here should take as an input variable the # `document_variable_name` as well as `initial_response_name` @@ -61,7 +61,7 @@ class RefineDocumentsChain(BaseCombineDocumentsChain): "Here's your first summary: {prev_response}. " "Now add to it based on the following context: {context}" ) - llm_chain_refine = LLMChain(llm=llm, prompt=prompt_refine) + refine_llm_chain = LLMChain(llm=llm, prompt=prompt_refine) chain = RefineDocumentsChain( initial_llm_chain=initial_llm_chain, refine_llm_chain=refine_llm_chain,