app_types.mdx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ---
  2. title: '📱 App types'
  3. ---
  4. ## App Types
  5. We have three types of App.
  6. ### App
  7. ```python
  8. from embedchain import App
  9. app = App()
  10. ```
  11. - `App` uses OpenAI's model, so these are paid models. 💸 You will be charged for embedding model usage and LLM usage.
  12. - `App` uses OpenAI's embedding model to create embeddings for chunks and ChatGPT API as LLM to get answer given the relevant docs. Make sure that you have an OpenAI account and an API key. If you have don't have an API key, you can create one by visiting [this link](https://platform.openai.com/account/api-keys).
  13. - `App` is opinionated. It uses the best embedding model and LLM on the market.
  14. - Once you have the API key, set it in an environment variable called `OPENAI_API_KEY`
  15. ```python
  16. import os
  17. os.environ["OPENAI_API_KEY"] = "sk-xxxx"
  18. ```
  19. ### Llama2App
  20. ```python
  21. import os
  22. from embedchain import Llama2App
  23. os.environ['REPLICATE_API_TOKEN'] = "REPLICATE API TOKEN"
  24. zuck_bot = Llama2App()
  25. # Embed your data
  26. zuck_bot.add("youtube_video", "https://www.youtube.com/watch?v=Ff4fRgnuFgQ")
  27. zuck_bot.add("web_page", "https://en.wikipedia.org/wiki/Mark_Zuckerberg")
  28. # Nice, your bot is ready now. Start asking questions to your bot.
  29. zuck_bot.query("Who is Mark Zuckerberg?")
  30. # Answer: Mark Zuckerberg is an American internet entrepreneur and business magnate. He is the co-founder and CEO of Facebook. Born in 1984, he dropped out of Harvard University to focus on his social media platform, which has since grown to become one of the largest and most influential technology companies in the world.
  31. # Enable web search for your bot
  32. zuck_bot.online = True # enable internet access for the bot
  33. zuck_bot.query("Who owns the new threads app and when it was founded?")
  34. # Answer: Based on the context provided, the new Threads app is owned by Meta, the parent company of Facebook, Instagram, and WhatsApp.
  35. ```
  36. - `Llama2App` uses Replicate's LLM model, so these are paid models. You can get the `REPLICATE_API_TOKEN` by registering on [their website](https://replicate.com/account).
  37. - `Llama2App` uses OpenAI's embedding model to create embeddings for chunks. Make sure that you have an OpenAI account and an API key. If you have don't have an API key, you can create one by visiting [this link](https://platform.openai.com/account/api-keys).
  38. ### OpenSourceApp
  39. ```python
  40. from embedchain import OpenSourceApp
  41. app = OpenSourceApp()
  42. ```
  43. - `OpenSourceApp` uses open source embedding and LLM model. It uses `all-MiniLM-L6-v2` from Sentence Transformers library as the embedding model and `gpt4all` as the LLM.
  44. - Here there is no need to setup any api keys. You just need to install embedchain package and these will get automatically installed. 📦
  45. - Once you have imported and instantiated the app, every functionality from here onwards is the same for either type of app. 📚
  46. - `OpenSourceApp` is opinionated. It uses the best open source embedding model and LLM on the market.
  47. ### CustomApp
  48. ```python
  49. from embedchain import CustomApp
  50. from embedchain.config import CustomAppConfig
  51. from embedchain.models import Providers, EmbeddingFunctions
  52. config = CustomAppConfig(embedding_fn=EmbeddingFunctions.OPENAI, provider=Providers.OPENAI)
  53. app = CustomApp(config)
  54. ```
  55. - `CustomApp` is not opinionated.
  56. - Configuration required. It's for advanced users who want to mix and match different embedding models and LLMs. Configuration required.
  57. - while it's doing that, it's still providing abstractions through `Providers`.
  58. - paid and free/open source providers included.
  59. - Once you have imported and instantiated the app, every functionality from here onwards is the same for either type of app. 📚
  60. - Following providers are available for an LLM
  61. - OPENAI
  62. - ANTHPROPIC
  63. - VERTEX_AI
  64. - GPT4ALL
  65. - AZURE_OPENAI
  66. - Following embedding functions are available for an embedding function
  67. - OPENAI
  68. - HUGGING_FACE
  69. - VERTEX_AI
  70. - GPT4ALL
  71. - AZURE_OPENAI
  72. ### PersonApp
  73. ```python
  74. from embedchain import PersonApp
  75. naval_chat_bot = PersonApp("name_of_person_or_character") #Like "Yoda"
  76. ```
  77. - `PersonApp` uses OpenAI's model, so these are paid models. 💸 You will be charged for embedding model usage and LLM usage.
  78. - `PersonApp` uses OpenAI's embedding model to create embeddings for chunks and ChatGPT API as LLM to get answer given the relevant docs. Make sure that you have an OpenAI account and an API key. If you have don't have an API key, you can create one by visiting [this link](https://platform.openai.com/account/api-keys).
  79. - Once you have the API key, set it in an environment variable called `OPENAI_API_KEY`
  80. ```python
  81. import os
  82. os.environ["OPENAI_API_KEY"] = "sk-xxxx"
  83. ```
  84. #### Compatibility with other apps
  85. - If there is any other app instance in your script or app, you can change the import as
  86. ```python
  87. from embedchain import App as EmbedChainApp
  88. from embedchain import OpenSourceApp as EmbedChainOSApp
  89. from embedchain import PersonApp as EmbedChainPersonApp
  90. # or
  91. from embedchain import App as ECApp
  92. from embedchain import OpenSourceApp as ECOSApp
  93. from embedchain import PersonApp as ECPApp
  94. ```