Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

update keys for chain #5164

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions libs/langchain/langchain/chains/combine_documents/stuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def get_default_document_variable_name(cls, values: Dict) -> Dict:
)
return values

@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

def _get_inputs(self, docs: List[Document], **kwargs: Any) -> dict:
"""Construct inputs from kwargs and docs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
_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 langchain.schema import format_document
from tests.unit_tests.llms.fake_llm import FakeLLM


def _fake_docs_len_func(docs: List[Document]) -> int:
Expand All @@ -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() -> None:
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)]
Expand Down