From f91b9b6201687e0c25f45575eaeef68f89db33ed Mon Sep 17 00:00:00 2001 From: Rodrigo Vega Moreno Date: Thu, 14 Sep 2023 21:37:15 -0600 Subject: [PATCH 1/2] Changed the `_get_relevant_documents` function to avoid using the deprecated `predict_and_parse` method --- libs/langchain/langchain/retrievers/self_query/base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/langchain/langchain/retrievers/self_query/base.py b/libs/langchain/langchain/retrievers/self_query/base.py index 2a7d53277bcba..107183f1658c3 100644 --- a/libs/langchain/langchain/retrievers/self_query/base.py +++ b/libs/langchain/langchain/retrievers/self_query/base.py @@ -116,10 +116,12 @@ def _get_relevant_documents( inputs = self.llm_chain.prep_inputs({"query": query}) structured_query = cast( StructuredQuery, - self.llm_chain.predict_and_parse( - callbacks=run_manager.get_child(), **inputs - ), + self.llm_chain.predict(callbacks=run_manager.get_child(), **inputs), ) + if self.llm_chain.prompt.output_parser is not None: + structured_query = self.llm_chain.prompt.output_parser.parse( + structured_query + ) if self.verbose: print(structured_query) new_query, new_kwargs = self.structured_query_translator.visit_structured_query( From 1ececb2bf23ab100b194742689d712304e9bf562 Mon Sep 17 00:00:00 2001 From: Rodrigo Vega Moreno Date: Thu, 14 Sep 2023 22:21:48 -0600 Subject: [PATCH 2/2] Remove "predict_and_parse" from LLMRouterChain --- libs/langchain/langchain/chains/router/llm_router.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/chains/router/llm_router.py b/libs/langchain/langchain/chains/router/llm_router.py index 74dcf6c0721cf..2dad6aa0bc639 100644 --- a/libs/langchain/langchain/chains/router/llm_router.py +++ b/libs/langchain/langchain/chains/router/llm_router.py @@ -55,8 +55,10 @@ def _call( callbacks = _run_manager.get_child() output = cast( Dict[str, Any], - self.llm_chain.predict_and_parse(callbacks=callbacks, **inputs), + self.llm_chain.predict(callbacks=callbacks, **inputs), ) + if self.llm_chain.prompt.output_parser is not None: + output = self.llm_chain.prompt.output_parser.parse(output) return output async def _acall( @@ -68,8 +70,10 @@ async def _acall( callbacks = _run_manager.get_child() output = cast( Dict[str, Any], - await self.llm_chain.apredict_and_parse(callbacks=callbacks, **inputs), + await self.llm_chain.apredict(callbacks=callbacks, **inputs), ) + if self.llm_chain.prompt.output_parser is not None: + output = self.llm_chain.prompt.output_parser.parse(output) return output @classmethod