mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
c010ec8b71
- `.get_relevant_documents(query)` -> `.invoke(query)` - `.get_relevant_documents(query=query)` -> `.invoke(query)` - `.get_relevant_documents(query, callbacks=callbacks)` -> `.invoke(query, config={"callbacks": callbacks})` - `.get_relevant_documents(query, **kwargs)` -> `.invoke(query, **kwargs)` --------- Co-authored-by: Erick Friis <erick@langchain.dev>
42 lines
993 B
Python
42 lines
993 B
Python
"""Integration test for PubMed API Wrapper."""
|
|
from typing import List
|
|
|
|
import pytest
|
|
from langchain_core.documents import Document
|
|
|
|
from langchain_community.retrievers import PubMedRetriever
|
|
|
|
|
|
@pytest.fixture
|
|
def retriever() -> PubMedRetriever:
|
|
return PubMedRetriever()
|
|
|
|
|
|
def assert_docs(docs: List[Document]) -> None:
|
|
for doc in docs:
|
|
assert doc.metadata
|
|
assert set(doc.metadata) == {
|
|
"Copyright Information",
|
|
"uid",
|
|
"Title",
|
|
"Published",
|
|
}
|
|
|
|
|
|
def test_load_success(retriever: PubMedRetriever) -> None:
|
|
docs = retriever.invoke("chatgpt")
|
|
assert len(docs) == 3
|
|
assert_docs(docs)
|
|
|
|
|
|
def test_load_success_top_k_results(retriever: PubMedRetriever) -> None:
|
|
retriever.top_k_results = 2
|
|
docs = retriever.invoke("chatgpt")
|
|
assert len(docs) == 2
|
|
assert_docs(docs)
|
|
|
|
|
|
def test_load_no_result(retriever: PubMedRetriever) -> None:
|
|
docs = retriever.invoke("1605.08386WWW")
|
|
assert not docs
|