From 57010cc60a4c7a9ad6293df240db8184316416a3 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Tue, 23 May 2023 20:40:01 -0700 Subject: [PATCH 1/3] update keys --- langchain/chains/combine_documents/stuff.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/langchain/chains/combine_documents/stuff.py b/langchain/chains/combine_documents/stuff.py index d39ce632c80b..3d22a630f7e1 100644 --- a/langchain/chains/combine_documents/stuff.py +++ b/langchain/chains/combine_documents/stuff.py @@ -34,6 +34,13 @@ class StuffDocumentsChain(BaseCombineDocumentsChain): document_separator: str = "\n\n" """The string with which to join the formatted documents""" + @property + def input_keys(self) -> List[str]: + extra_keys = [ + k for k in self.llm_chain.input_keys if k != self.document_variable_name + ] + return super().input_keys + extra_keys + class Config: """Configuration for this pydantic object.""" From c3ae28bd84f22fa414b7f1acb577d6a7435e5bc1 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Tue, 23 May 2023 20:42:52 -0700 Subject: [PATCH 2/3] cr --- tests/unit_tests/chains/test_combine_documents.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit_tests/chains/test_combine_documents.py b/tests/unit_tests/chains/test_combine_documents.py index 737725035218..5749dc76663f 100644 --- a/tests/unit_tests/chains/test_combine_documents.py +++ b/tests/unit_tests/chains/test_combine_documents.py @@ -10,7 +10,9 @@ _collapse_docs, _split_list_of_docs, ) +from langchain.chains.qa_with_sources import load_qa_with_sources_chain from langchain.docstore.document import Document +from tests.unit_tests.llms.fake_llm import FakeLLM def _fake_docs_len_func(docs: List[Document]) -> int: @@ -21,6 +23,11 @@ def _fake_combine_docs_func(docs: List[Document], **kwargs: Any) -> str: return "".join([d.page_content for d in docs]) +def test_multiple_input_keys(): + chain = load_qa_with_sources_chain(FakeLLM(), chain_type="stuff") + assert chain.input_keys == ["input_documents", "question"] + + def test__split_list_long_single_doc() -> None: """Test splitting of a long single doc.""" docs = [Document(page_content="foo" * 100)] From b489d5115059ae264f1266706241c08d99bb5e89 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Tue, 23 May 2023 21:52:23 -0700 Subject: [PATCH 3/3] cr --- tests/unit_tests/chains/test_combine_documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/chains/test_combine_documents.py b/tests/unit_tests/chains/test_combine_documents.py index 5749dc76663f..87014c8709ec 100644 --- a/tests/unit_tests/chains/test_combine_documents.py +++ b/tests/unit_tests/chains/test_combine_documents.py @@ -23,7 +23,7 @@ def _fake_combine_docs_func(docs: List[Document], **kwargs: Any) -> str: return "".join([d.page_content for d in docs]) -def test_multiple_input_keys(): +def test_multiple_input_keys() -> None: chain = load_qa_with_sources_chain(FakeLLM(), chain_type="stuff") assert chain.input_keys == ["input_documents", "question"]