2024-03-06 14:16:49 +00:00
|
|
|
from typing import Any, Iterator, List, Optional
|
2023-12-11 21:53:30 +00:00
|
|
|
|
|
|
|
from langchain_core.documents import Document
|
|
|
|
|
|
|
|
from langchain_community.document_loaders.base import BaseLoader
|
|
|
|
from langchain_community.utilities.arxiv import ArxivAPIWrapper
|
|
|
|
|
|
|
|
|
|
|
|
class ArxivLoader(BaseLoader):
|
|
|
|
"""Load a query result from `Arxiv`.
|
|
|
|
|
|
|
|
The loader converts the original PDF format into the text.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Supports all arguments of `ArxivAPIWrapper`.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self, query: str, doc_content_chars_max: Optional[int] = None, **kwargs: Any
|
|
|
|
):
|
|
|
|
self.query = query
|
|
|
|
self.client = ArxivAPIWrapper(
|
|
|
|
doc_content_chars_max=doc_content_chars_max, **kwargs
|
|
|
|
)
|
|
|
|
|
2024-03-06 14:16:49 +00:00
|
|
|
def lazy_load(self) -> Iterator[Document]:
|
|
|
|
yield from self.client.lazy_load(self.query)
|
2023-12-22 21:14:22 +00:00
|
|
|
|
|
|
|
def get_summaries_as_docs(self) -> List[Document]:
|
|
|
|
return self.client.get_summaries_as_docs(self.query)
|