discourse.mdx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ---
  2. title: '🗨️ Discourse'
  3. ---
  4. You can now easily load data from your community built with [Discourse](https://discourse.org/).
  5. ## Example
  6. 1. Setup the Discourse Loader with your community url.
  7. ```Python
  8. from embedchain.loaders.discourse import DiscourseLoader
  9. dicourse_loader = DiscourseLoader(config={"domain": "https://community.openai.com"})
  10. ```
  11. 2. Once you setup the loader, you can create an app and load data using the above discourse loader
  12. ```Python
  13. import os
  14. from embedchain.pipeline import Pipeline as App
  15. os.environ["OPENAI_API_KEY"] = "sk-xxx"
  16. app = App()
  17. app.add("openai after:2023-10-1", data_type="discourse", loader=dicourse_loader)
  18. question = "Where can I find the OpenAI API status page?"
  19. app.query(question)
  20. # Answer: You can find the OpenAI API status page at https:/status.openai.com/.
  21. ```
  22. NOTE: The `add` function of the app will accept any executable search query to load data. Refer [Discourse API Docs](https://docs.discourse.org/#tag/Search) to learn more about search queries.
  23. 3. We automatically create a chunker to chunk your discourse data, however if you wish to provide your own chunker class. Here is how you can do that:
  24. ```Python
  25. from embedchain.chunkers.discourse import DiscourseChunker
  26. from embedchain.config.add_config import ChunkerConfig
  27. discourse_chunker_config = ChunkerConfig(chunk_size=1000, chunk_overlap=0, length_function=len)
  28. discourse_chunker = DiscourseChunker(config=discourse_chunker_config)
  29. app.add("openai", data_type='discourse', loader=dicourse_loader, chunker=discourse_chunker)
  30. ```