Skip to content

Commit

Permalink
[simple] added test case and improve self class return type annotation (
Browse files Browse the repository at this point in the history
langchain-ai#3773)

a simple follow up of langchain-ai#3748
- added test case
- improve annotation when function return type is class itself.
  • Loading branch information
skcoirz authored and samching committed May 1, 2023
1 parent e7c6142 commit 64a132e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion langchain/retrievers/document_compressors/chain_extract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""DocumentFilter that uses an LLM chain to extract the relevant parts of documents."""
from __future__ import annotations

from typing import Any, Callable, Dict, Optional, Sequence

from langchain import LLMChain, PromptTemplate
Expand Down Expand Up @@ -70,7 +72,7 @@ def from_llm(
prompt: Optional[PromptTemplate] = None,
get_input: Optional[Callable[[str, Document], str]] = None,
llm_chain_kwargs: Optional[dict] = None,
) -> "LLMChainExtractor":
) -> LLMChainExtractor:
"""Initialize from LLM."""
_prompt = prompt if prompt is not None else _get_default_chain_prompt()
_get_input = get_input if get_input is not None else default_get_input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
from langchain.schema import Document


def test_llm_construction_with_kwargs() -> None:
llm_chain_kwargs = {"verbose": True}
compressor = LLMChainExtractor.from_llm(
ChatOpenAI(), llm_chain_kwargs=llm_chain_kwargs
)
assert compressor.llm_chain.verbose is True


def test_llm_chain_extractor() -> None:
texts = [
"The Roman Empire followed the Roman Republic.",
Expand Down

0 comments on commit 64a132e

Please sign in to comment.