Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
onedrive_file.py35 linesDownload Raw Back to document_loaders
1from __future__ import annotations2 3import tempfile4from typing import TYPE_CHECKING, List5 6from langchain_core.documents import Document7from pydantic import BaseModel, ConfigDict, Field8 9from langchain_community.document_loaders.base import BaseLoader10from langchain_community.document_loaders.unstructured import UnstructuredFileLoader11 12if TYPE_CHECKING:13    from O365.drive import File14 15CHUNK_SIZE = 1024 * 1024 * 516 17 18class OneDriveFileLoader(BaseLoader, BaseModel):19    """Load a file from `Microsoft OneDrive`."""20 21    file: File = Field(...)22    """The file to load."""23 24    model_config = ConfigDict(25        arbitrary_types_allowed=True,26    )27 28    def load(self) -> List[Document]:29        """Load Documents"""30        with tempfile.TemporaryDirectory() as temp_dir:31            file_path = f"{temp_dir}/{self.file.name}"32            self.file.download(to_path=temp_dir, chunk_size=CHUNK_SIZE)33            loader = UnstructuredFileLoader(file_path)34            return loader.load()35 
codekingpro/portable-devtools · Team Ai