directory.mdx 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ---
  2. title: '📁 Directory/Folder'
  3. ---
  4. To use an entire directory as data source, just add `data_type` as `directory` and pass in the path of the local directory.
  5. ### Without customization
  6. ```python
  7. import os
  8. from embedchain import App
  9. os.environ["OPENAI_API_KEY"] = "sk-xxx"
  10. app = App()
  11. app.add("./elon-musk", data_type="directory")
  12. response = app.query("list all files")
  13. print(response)
  14. # Answer: Files are elon-musk-1.txt, elon-musk-2.pdf.
  15. ```
  16. ### Customization
  17. ```python
  18. import os
  19. from embedchain import App
  20. from embedchain.loaders.directory_loader import DirectoryLoader
  21. os.environ["OPENAI_API_KEY"] = "sk-xxx"
  22. lconfig = {
  23. "recursive": True,
  24. "extensions": [".txt"]
  25. }
  26. loader = DirectoryLoader(config=lconfig)
  27. app = App()
  28. app.add("./elon-musk", loader=loader)
  29. response = app.query("what are all the files related to?")
  30. print(response)
  31. # Answer: The files are related to Elon Musk.
  32. ```