mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
36c59e0c25
It makes sense to use `arxiv` as another source of the documents for downloading. - Added the `arxiv` document_loader, based on the `utilities/arxiv.py:ArxivAPIWrapper` - added tests - added an example notebook - sorted `__all__` in `__init__.py` (otherwise it is hard to find a class in the very long list)
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
from typing import List
|
|
|
|
from langchain.document_loaders.arxiv import ArxivLoader
|
|
from langchain.schema import Document
|
|
|
|
|
|
def assert_docs(docs: List[Document]) -> None:
|
|
for doc in docs:
|
|
assert doc.page_content
|
|
assert doc.metadata
|
|
assert set(doc.metadata) == {"Published", "Title", "Authors", "Summary"}
|
|
|
|
|
|
def test_load_success() -> None:
|
|
"""Test that returns one document"""
|
|
loader = ArxivLoader(query="1605.08386", load_max_docs=2)
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
print(docs[0].metadata)
|
|
print(docs[0].page_content)
|
|
assert_docs(docs)
|
|
|
|
|
|
def test_load_returns_no_result() -> None:
|
|
"""Test that returns no docs"""
|
|
loader = ArxivLoader(query="1605.08386WWW", load_max_docs=2)
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == 0
|
|
|
|
|
|
def test_load_returns_limited_docs() -> None:
|
|
"""Test that returns several docs"""
|
|
expected_docs = 2
|
|
loader = ArxivLoader(query="ChatGPT", load_max_docs=expected_docs)
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == expected_docs
|
|
assert_docs(docs)
|
|
|
|
|
|
def test_load_returns_full_set_of_metadata() -> None:
|
|
"""Test that returns several docs"""
|
|
loader = ArxivLoader(query="ChatGPT", load_max_docs=1, load_all_available_meta=True)
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
for doc in docs:
|
|
assert doc.page_content
|
|
assert doc.metadata
|
|
assert set(doc.metadata).issuperset(
|
|
{"Published", "Title", "Authors", "Summary"}
|
|
)
|
|
print(doc.metadata)
|
|
assert len(set(doc.metadata)) > 4
|