mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-19 21:33:31 -04:00
3943759a90
### Summary Adds a loader for rich text files. Requires `unstructured>=0.5.12`. ### Testing The following test uses the example RTF file from the [`unstructured` repo](https://github.com/Unstructured-IO/unstructured/tree/main/example-docs). ```python from langchain.document_loaders import UnstructuredRTFLoader loader = UnstructuredRTFLoader("fake-doc.rtf", mode="elements") docs = loader.load() docs[0].page_content ```
29 lines
966 B
Python
29 lines
966 B
Python
"""Loader that loads rich text files."""
|
|
from typing import Any, List
|
|
|
|
from langchain.document_loaders.unstructured import (
|
|
UnstructuredFileLoader,
|
|
satisfies_min_unstructured_version,
|
|
)
|
|
|
|
|
|
class UnstructuredRTFLoader(UnstructuredFileLoader):
|
|
"""Loader that uses unstructured to load rtf files."""
|
|
|
|
def __init__(
|
|
self, file_path: str, mode: str = "single", **unstructured_kwargs: Any
|
|
):
|
|
min_unstructured_version = "0.5.12"
|
|
if not satisfies_min_unstructured_version(min_unstructured_version):
|
|
raise ValueError(
|
|
"Partitioning rtf files is only supported in "
|
|
f"unstructured>={min_unstructured_version}."
|
|
)
|
|
|
|
super().__init__(file_path=file_path, mode=mode, **unstructured_kwargs)
|
|
|
|
def _get_elements(self) -> List:
|
|
from unstructured.partition.rtf import partition_rtf
|
|
|
|
return partition_rtf(filename=self.file_path, **self.unstructured_kwargs)
|