interface_types.mdx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ---
  2. title: '🤝 Interface types'
  3. ---
  4. ## Interface Types
  5. The embedchain app exposes the following methods.
  6. ### Query Interface
  7. - This interface is like a question answering bot. It takes a question and gets the answer. It does not maintain context about the previous chats.❓
  8. - To use this, call `.query()` function to get the answer for any query.
  9. ```python
  10. print(naval_chat_bot.query("What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?"))
  11. # answer: Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.
  12. ```
  13. ### Chat Interface
  14. - This interface is chat interface where it remembers previous conversation. Right now it remembers 5 conversation by default. 💬
  15. - To use this, call `.chat` function to get the answer for any query.
  16. ```python
  17. print(naval_chat_bot.chat("How to be happy in life?"))
  18. # answer: The most important trick to being happy is to realize happiness is a skill you develop and a choice you make. You choose to be happy, and then you work at it. It's just like building muscles or succeeding at your job. It's about recognizing the abundance and gifts around you at all times.
  19. print(naval_chat_bot.chat("who is naval ravikant?"))
  20. # answer: Naval Ravikant is an Indian-American entrepreneur and investor.
  21. print(naval_chat_bot.chat("what did the author say about happiness?"))
  22. # answer: The author, Naval Ravikant, believes that happiness is a choice you make and a skill you develop. He compares the mind to the body, stating that just as the body can be molded and changed, so can the mind. He emphasizes the importance of being present in the moment and not getting caught up in regrets of the past or worries about the future. By being present and grateful for where you are, you can experience true happiness.
  23. ```
  24. #### Dry Run
  25. Dry Run is an option in the `query` and `chat` methods that allows the user to not send their constructed prompt to the LLM, to save money. It's used for [testing](/advanced/testing#dry-run).
  26. ### Stream Response
  27. - You can add config to your query method to stream responses like ChatGPT does. You would require a downstream handler to render the chunk in your desirable format. Supports both OpenAI model and OpenSourceApp. 📊
  28. - To use this, instantiate a `QueryConfig` or `ChatConfig` object with `stream=True`. Then pass it to the `.chat()` or `.query()` method. The following example iterates through the chunks and prints them as they appear.
  29. ```python
  30. app = App()
  31. query_config = QueryConfig(stream = True)
  32. resp = app.query("What unique capacity does Naval argue humans possess when it comes to understanding explanations or concepts?", query_config)
  33. for chunk in resp:
  34. print(chunk, end="", flush=True)
  35. # answer: Naval argues that humans possess the unique capacity to understand explanations or concepts to the maximum extent possible in this physical reality.
  36. ```
  37. ### Other Methods
  38. #### Reset
  39. Resets the database and deletes all embeddings. Irreversible. Requires reinitialization afterwards.
  40. ```python
  41. app.reset()
  42. ```
  43. #### Count
  44. Counts the number of embeddings (chunks) in the database.
  45. ```python
  46. print(app.count())
  47. # returns: 481
  48. ```