Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic file generator #53

Open
tazarov opened this issue Jan 19, 2024 · 1 comment
Open

Generic file generator #53

tazarov opened this issue Jan 19, 2024 · 1 comment
Assignees
Milestone

Comments

@tazarov
Copy link
Contributor

tazarov commented Jan 19, 2024

Use LC mime router and python-magic to route files automatically:

from langchain_community.document_loaders.mime_router import MimeRouter
from langchain_community.document_loaders.text import TextLoader
from langchain_community.document_loaders.pdf import PDFLoader

# Create an instance of the MimeRouter
router = MimeRouter()

# Register loaders for specific MIME types
router.register_loader('text/plain', TextLoader)
router.register_loader('application/pdf', PDFLoader)

# Specify the path to the file
file_path = '/path/to/file.pdf'

# Determine the MIME type of the file
mime_type = 'application/pdf'  # You can use a library like python-magic to detect the MIME type

# Get the appropriate loader for the MIME type
loader_cls = router.get_loader(mime_type)

# Create an instance of the loader and load the file
loader = loader_cls(file_path)
document = loader.load()

# Process the loaded document as needed
content = document.content
# ...
@tazarov tazarov self-assigned this Jan 19, 2024
@tazarov tazarov modified the milestones: 0.0.5, 0.0.6 Jan 20, 2024
@tazarov tazarov modified the milestones: 0.0.6, 0.0.7 Jan 30, 2024
@tazarov
Copy link
Contributor Author

tazarov commented Feb 13, 2024

the use case for this is to specify a target dir and a glob pattern or just a series of file types to process.

Examples:

cdp file /target/dir --glob *.pdf --recursive
# or file types flags
cdp file /target/dir --pdf --word --recursive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant