app_types.mdx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 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("https://www.youtube.com/watch?v=Ff4fRgnuFgQ")
  27. zuck_bot.add("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 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. - extra dependencies are required for this app type. Install them with `pip install --upgrade embedchain[opensource]`.
  48. ### CustomApp
  49. ```python
  50. from embedchain import CustomApp
  51. from embedchain.config import (CustomAppConfig, ElasticsearchDBConfig,
  52. EmbedderConfig, LlmConfig)
  53. from embedchain.embedder.vertexai import VertexAiEmbedder
  54. from embedchain.llm.vertex_ai import VertexAiLlm
  55. from embedchain.models import EmbeddingFunctions, Providers
  56. from embedchain.vectordb.elasticsearch import Elasticsearch
  57. # short
  58. app = CustomApp(llm=VertexAiLlm(), db=Elasticsearch(), embedder=VertexAiEmbedder())
  59. # with configs
  60. app = CustomApp(
  61. config=CustomAppConfig(log_level="INFO"),
  62. llm=VertexAiLlm(config=LlmConfig(number_documents=5)),
  63. db=Elasticsearch(config=ElasticsearchDBConfig(es_url="...")),
  64. embedder=VertexAiEmbedder(config=EmbedderConfig()),
  65. )
  66. ```
  67. - `CustomApp` is not opinionated.
  68. - Configuration required. It's for advanced users who want to mix and match different embedding models and LLMs.
  69. - while it's doing that, it's still providing abstractions by allowing you to import Classes from `embedchain.llm`, `embedchain.vectordb`, and `embedchain.embedder`.
  70. - paid and free/open source providers included.
  71. - Once you have imported and instantiated the app, every functionality from here onwards is the same for either type of app. 📚
  72. - Following providers are available for an LLM
  73. - OPENAI
  74. - ANTHPROPIC
  75. - VERTEX_AI
  76. - GPT4ALL
  77. - AZURE_OPENAI
  78. - LLAMA2
  79. - Following embedding functions are available for an embedding function
  80. - OPENAI
  81. - HUGGING_FACE
  82. - VERTEX_AI
  83. - GPT4ALL
  84. - AZURE_OPENAI
  85. ### PersonApp
  86. ```python
  87. from embedchain import PersonApp
  88. naval_chat_bot = PersonApp("name_of_person_or_character") #Like "Yoda"
  89. ```
  90. - `PersonApp` uses OpenAI's model, so these are paid models. 💸 You will be charged for embedding model usage and LLM usage.
  91. - `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 don't have an API key, you can create one by visiting [this link](https://platform.openai.com/account/api-keys).
  92. - Once you have the API key, set it in an environment variable called `OPENAI_API_KEY`
  93. ```python
  94. import os
  95. os.environ["OPENAI_API_KEY"] = "sk-xxxx"
  96. ```
  97. #### Compatibility with other apps
  98. - If there is any other app instance in your script or app, you can change the import as
  99. ```python
  100. from embedchain import App as EmbedChainApp
  101. from embedchain import OpenSourceApp as EmbedChainOSApp
  102. from embedchain import PersonApp as EmbedChainPersonApp
  103. # or
  104. from embedchain import App as ECApp
  105. from embedchain import OpenSourceApp as ECOSApp
  106. from embedchain import PersonApp as ECPApp
  107. ```