Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
merge.py31 linesDownload Raw Back to document_loaders
1from typing import AsyncIterator, Iterator, List2 3from langchain_core.documents import Document4 5from langchain_community.document_loaders.base import BaseLoader6 7 8class MergedDataLoader(BaseLoader):9    """Merge documents from a list of loaders"""10 11    def __init__(self, loaders: List):12        """Initialize with a list of loaders"""13        self.loaders = loaders14 15    def lazy_load(self) -> Iterator[Document]:16        """Lazy load docs from each individual loader."""17        for loader in self.loaders:18            # Check if lazy_load is implemented19            try:20                data = loader.lazy_load()21            except NotImplementedError:22                data = loader.load()23            for document in data:24                yield document25 26    async def alazy_load(self) -> AsyncIterator[Document]:27        """Lazy load docs from each individual loader."""28        for loader in self.loaders:29            async for document in loader.alazy_load():30                yield document31 
codekingpro/portable-devtools · Team Ai