langchain: update use of predict_and_parse in LLMChainFilter (#21389)

Following https://github.com/langchain-ai/langchain/pull/20130

Removes deprecation warnings in docs here:
https://python.langchain.com/docs/modules/data_connection/retrievers/contextual_compression/

Tested using the same docs notebook + existing integration test.
pull/21427/head
ccurme 4 weeks ago committed by GitHub
parent dd70f2f473
commit 3c31bd0ed0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -47,9 +47,10 @@ class LLMChainFilter(BaseDocumentCompressor):
filtered_docs = [] filtered_docs = []
for doc in documents: for doc in documents:
_input = self.get_input(query, doc) _input = self.get_input(query, doc)
include_doc = self.llm_chain.predict_and_parse( output_dict = self.llm_chain.invoke(_input, config={"callbacks": callbacks})
**_input, callbacks=callbacks output = output_dict[self.llm_chain.output_key]
) if self.llm_chain.prompt.output_parser is not None:
include_doc = self.llm_chain.prompt.output_parser.parse(output)
if include_doc: if include_doc:
filtered_docs.append(doc) filtered_docs.append(doc)
return filtered_docs return filtered_docs

Loading…
Cancel
Save