mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-28 23:07:11 +00:00
This PR upgrades langchain-community to pydantic 2.
* Most of this PR was auto-generated using code mods with gritql
(https://github.com/eyurtsev/migrate-pydantic/tree/main)
* Subsequently, some code was fixed manually due to accommodate
differences between pydantic 1 and 2
Breaking Changes:
- Use TEXTEMBED_API_KEY and TEXTEMBEB_API_URL for env variables for text
embed integrations:
cbea780492
Other changes:
- Added pydantic_settings as a required dependency for community. This
may be removed if we have enough time to convert the dependency into an
optional one.
---------
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
35 lines
992 B
Python
35 lines
992 B
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
from typing import TYPE_CHECKING, List
|
|
|
|
from langchain_core.documents import Document
|
|
from pydantic import BaseModel, ConfigDict, 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
|
|
|
|
|
|
class OneDriveFileLoader(BaseLoader, BaseModel):
|
|
"""Load a file from `Microsoft OneDrive`."""
|
|
|
|
file: File = Field(...)
|
|
"""The file to load."""
|
|
|
|
model_config = ConfigDict(
|
|
arbitrary_types_allowed=True,
|
|
)
|
|
|
|
def load(self) -> List[Document]:
|
|
"""Load Documents"""
|
|
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()
|