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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to SelfQueryRetriever and LLMRouterChain deprecation warning #10617

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libs/langchain/langchain/chains/router/llm_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal of deprecating predict_and_parse is actually to avoid storing the output parser on the prompt. Instead, can you update to store on the llm_chain instead?

return output

async def _acall(
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions libs/langchain/langchain/retrievers/self_query/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading