Source code for langchain_community.document_loaders.onedrive_file

from __future__ import annotations

import tempfile
from typing import TYPE_CHECKING, List

from langchain_core.documents import Document
from langchain_core.pydantic_v1 import BaseModel, Field

from langchain_community.document_loaders.base import BaseLoader
from langchain_community.document_loaders.unstructured import UnstructuredFileLoader

if TYPE_CHECKING:
    from O365.drive import File

CHUNK_SIZE = 1024 * 1024 * 5


[docs]class OneDriveFileLoader(BaseLoader, BaseModel): """从`Microsoft OneDrive`加载一个文件。""" file: File = Field(...) """需要加载的文件。""" class Config: arbitrary_types_allowed = True """允许任意类型。这对于文件类型是必需的。默认值为True。 请参阅https://pydantic-docs.helpmanual.io/usage/types/#arbitrary-types-allowed"""
[docs] def load(self) -> List[Document]: """加载文档""" with tempfile.TemporaryDirectory() as temp_dir: file_path = f"{temp_dir}/{self.file.name}" self.file.download(to_path=temp_dir, chunk_size=CHUNK_SIZE) loader = UnstructuredFileLoader(file_path) return loader.load()