From f841ccd5b645dd49b91c4f1d9e25d6b83d5383be Mon Sep 17 00:00:00 2001 From: Konstantin Krestnikov Date: Tue, 8 Oct 2024 16:32:38 +0300 Subject: [PATCH] Fixing CI --- .../utilities/yandex_search.py | 2 +- .../chains/combine_documents/conditional.py | 47 ------------------- .../chains/conversational_retrieval/base.py | 2 +- 3 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 libs/langchain/langchain/chains/combine_documents/conditional.py diff --git a/libs/community/langchain_community/utilities/yandex_search.py b/libs/community/langchain_community/utilities/yandex_search.py index becef194388af..68a460176c0c0 100644 --- a/libs/community/langchain_community/utilities/yandex_search.py +++ b/libs/community/langchain_community/utilities/yandex_search.py @@ -65,7 +65,7 @@ def base_params(self) -> Dict: class Config: """Configuration for this pydantic object.""" - extra = Extra.forbid + extra = 'forbid' @root_validator(pre=True) def validate_environment(cls, values: Dict) -> Dict: diff --git a/libs/langchain/langchain/chains/combine_documents/conditional.py b/libs/langchain/langchain/chains/combine_documents/conditional.py deleted file mode 100644 index d1bf44030fe87..0000000000000 --- a/libs/langchain/langchain/chains/combine_documents/conditional.py +++ /dev/null @@ -1,47 +0,0 @@ -from typing import Any, List, Tuple - -from langchain.chains import MapReduceDocumentsChain, StuffDocumentsChain -from langchain.chains.combine_documents.base import BaseCombineDocumentsChain -from langchain.pydantic_v1 import Extra -from langchain.schema import Document - - -class ConditionalDocumentsChain(BaseCombineDocumentsChain): - """ - Цепь, которая выполняет StuffDocumentsChain, - если размер документов меньше max_length, - если же размер больше, то выполняет MapReduceDocumentsChain - """ - - stuff_chain: StuffDocumentsChain - map_reduce_chain: MapReduceDocumentsChain - # Размер указывается в токенах - max_length: int = 2000 - - class Config: - """Configuration for this pydantic object.""" - - extra = Extra.forbid - arbitrary_types_allowed = True - - def combine_docs(self, docs: List[Document], **kwargs: Any) -> Tuple[str, dict]: - current_chain = self.current_chain(docs, **kwargs) - return current_chain.combine_docs(docs, **kwargs) - - async def acombine_docs( - self, docs: List[Document], **kwargs: Any - ) -> Tuple[str, dict]: - current_chain = self.current_chain(docs, **kwargs) - return await current_chain.acombine_docs(docs, **kwargs) - - @property - def _chain_type(self) -> str: - return "conditional_documents_chain" - - def current_chain( - self, docs: List[Document], **kwargs: Any - ) -> BaseCombineDocumentsChain: - prompt_length = self.stuff_chain.prompt_length(docs, **kwargs) - if prompt_length is None or prompt_length > self.max_length: - return self.map_reduce_chain - return self.stuff_chain diff --git a/libs/langchain/langchain/chains/conversational_retrieval/base.py b/libs/langchain/langchain/chains/conversational_retrieval/base.py index 4fa714510abbd..0c983fdc5ad1e 100644 --- a/libs/langchain/langchain/chains/conversational_retrieval/base.py +++ b/libs/langchain/langchain/chains/conversational_retrieval/base.py @@ -145,7 +145,7 @@ def _call( get_chat_history = self.get_chat_history or _get_chat_history chat_history_str = get_chat_history(inputs["chat_history"]) - if chat_history_str and not self.disable_question_generator: + if chat_history_str: callbacks = _run_manager.get_child() new_question = self.question_generator.run( question=question, chat_history=chat_history_str, callbacks=callbacks