File size: 984 Bytes
29c4d1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import List
import os

class DocumentLoader:
    def __init__(self, file_paths: List[str]):
        self.file_paths = file_paths

    def load_documents(self) -> List[str]:
        documents = []
        for file_path in self.file_paths:
            if os.path.exists(file_path):
                with open(file_path, 'r', encoding='utf-8') as file:
                    documents.append(file.read())
            else:
                raise FileNotFoundError(f"File not found: {file_path}")
        return documents

    def load_from_directory(self, directory_path: str) -> List[str]:
        documents = []
        for filename in os.listdir(directory_path):
            file_path = os.path.join(directory_path, filename)
            if os.path.isfile(file_path):
                documents.extend(self.load_documents([file_path]))
        return documents

    def load_pdf(self, pdf_path: str) -> str:
        raise NotImplementedError("PDF loading not implemented yet.")