llms.mdx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. ---
  2. title: 🤖 Large language models (LLMs)
  3. ---
  4. ## Overview
  5. Embedchain comes with built-in support for various popular large language models. We handle the complexity of integrating these models for you, allowing you to easily customize your language model interactions through a user-friendly interface.
  6. <CardGroup cols={4}>
  7. <Card title="OpenAI" href="#openai"></Card>
  8. <Card title="Azure OpenAI" href="#azure-openai"></Card>
  9. <Card title="Anthropic" href="#anthropic"></Card>
  10. <Card title="Cohere" href="#cohere"></Card>
  11. <Card title="GPT4All" href="#gpt4all"></Card>
  12. <Card title="JinaChat" href="#jinachat"></Card>
  13. <Card title="Hugging Face" href="#hugging-face"></Card>
  14. <Card title="Llama2" href="#llama2"></Card>
  15. <Card title="Vertex AI" href="#vertex-ai"></Card>
  16. </CardGroup>
  17. ## OpenAI
  18. To use OpenAI LLM models, you have to set the `OPENAI_API_KEY` environment variable. You can obtain the OpenAI API key from the [OpenAI Platform](https://platform.openai.com/account/api-keys).
  19. Once you have obtained the key, you can use it like this:
  20. ```python
  21. import os
  22. from embedchain import App
  23. os.environ['OPENAI_API_KEY'] = 'xxx'
  24. app = App()
  25. app.add("https://en.wikipedia.org/wiki/OpenAI")
  26. app.query("What is OpenAI?")
  27. ```
  28. If you are looking to configure the different parameters of the LLM, you can do so by loading the app using a [yaml config](https://github.com/embedchain/embedchain/blob/main/configs/chroma.yaml) file.
  29. <CodeGroup>
  30. ```python main.py
  31. import os
  32. from embedchain import App
  33. os.environ['OPENAI_API_KEY'] = 'xxx'
  34. # load llm configuration from config.yaml file
  35. app = App.from_config(yaml_path="config.yaml")
  36. ```
  37. ```yaml config.yaml
  38. llm:
  39. provider: openai
  40. model: 'gpt-3.5-turbo'
  41. config:
  42. temperature: 0.5
  43. max_tokens: 1000
  44. top_p: 1
  45. stream: false
  46. ```
  47. </CodeGroup>
  48. ## Azure OpenAI
  49. To use Azure OpenAI model, you have to set some of the azure openai related environment variables as given in the code block below:
  50. <CodeGroup>
  51. ```python main.py
  52. import os
  53. from embedchain import App
  54. os.environ["OPENAI_API_TYPE"] = "azure"
  55. os.environ["OPENAI_API_BASE"] = "https://xxx.openai.azure.com/"
  56. os.environ["OPENAI_API_KEY"] = "xxx"
  57. os.environ["OPENAI_API_VERSION"] = "xxx"
  58. app = App.from_config(yaml_path="config.yaml")
  59. ```
  60. ```yaml config.yaml
  61. llm:
  62. provider: azure_openai
  63. model: gpt-35-turbo
  64. config:
  65. deployment_name: your_llm_deployment_name
  66. temperature: 0.5
  67. max_tokens: 1000
  68. top_p: 1
  69. stream: false
  70. embedder:
  71. provider: azure_openai
  72. config:
  73. model: text-embedding-ada-002
  74. deployment_name: you_embedding_model_deployment_name
  75. ```
  76. </CodeGroup>
  77. You can find the list of models and deployment name on the [Azure OpenAI Platform](https://oai.azure.com/portal).
  78. ## Anthropic
  79. To use anthropic's model, please set the `ANTHROPIC_API_KEY` which you find on their [Account Settings Page](https://console.anthropic.com/account/keys).
  80. <CodeGroup>
  81. ```python main.py
  82. import os
  83. from embedchain import App
  84. os.environ["ANTHROPIC_API_KEY"] = "xxx"
  85. # load llm configuration from config.yaml file
  86. app = App.from_config(yaml_path="config.yaml")
  87. ```
  88. ```yaml config.yaml
  89. llm:
  90. provider: anthropic
  91. model: 'claude-instant-1'
  92. config:
  93. temperature: 0.5
  94. max_tokens: 1000
  95. top_p: 1
  96. stream: false
  97. ```
  98. </CodeGroup>
  99. ## Cohere
  100. Install related dependencies using the following command:
  101. ```bash
  102. pip install --upgrade 'embedchain[cohere]'
  103. ```
  104. Set the `COHERE_API_KEY` as environment variable which you can find on their [Account settings page](https://dashboard.cohere.com/api-keys).
  105. Once you have the API key, you are all set to use it with Embedchain.
  106. <CodeGroup>
  107. ```python main.py
  108. import os
  109. from embedchain import App
  110. os.environ["COHERE_API_KEY"] = "xxx"
  111. # load llm configuration from config.yaml file
  112. app = App.from_config(yaml_path="config.yaml")
  113. ```
  114. ```yaml config.yaml
  115. llm:
  116. provider: cohere
  117. model: large
  118. config:
  119. temperature: 0.5
  120. max_tokens: 1000
  121. top_p: 1
  122. ```
  123. </CodeGroup>
  124. ## GPT4ALL
  125. Install related dependencies using the following command:
  126. ```bash
  127. pip install --upgrade 'embedchain[opensource]'
  128. ```
  129. GPT4all is a free-to-use, locally running, privacy-aware chatbot. No GPU or internet required. You can use this with Embedchain using the following code:
  130. <CodeGroup>
  131. ```python main.py
  132. from embedchain import App
  133. # load llm configuration from config.yaml file
  134. app = App.from_config(yaml_path="config.yaml")
  135. ```
  136. ```yaml config.yaml
  137. llm:
  138. provider: gpt4all
  139. model: 'orca-mini-3b.ggmlv3.q4_0.bin'
  140. config:
  141. temperature: 0.5
  142. max_tokens: 1000
  143. top_p: 1
  144. stream: false
  145. embedder:
  146. provider: gpt4all
  147. config:
  148. model: 'all-MiniLM-L6-v2'
  149. ```
  150. </CodeGroup>
  151. ## JinaChat
  152. First, set `JINACHAT_API_KEY` in environment variable which you can obtain from [their platform](https://chat.jina.ai/api).
  153. Once you have the key, load the app using the config yaml file:
  154. <CodeGroup>
  155. ```python main.py
  156. import os
  157. from embedchain import App
  158. os.environ["JINACHAT_API_KEY"] = "xxx"
  159. # load llm configuration from config.yaml file
  160. app = App.from_config(yaml_path="config.yaml")
  161. ```
  162. ```yaml config.yaml
  163. llm:
  164. provider: jina
  165. config:
  166. temperature: 0.5
  167. max_tokens: 1000
  168. top_p: 1
  169. stream: false
  170. ```
  171. </CodeGroup>
  172. ## Hugging Face
  173. Install related dependencies using the following command:
  174. ```bash
  175. pip install --upgrade 'embedchain[huggingface_hub]'
  176. ```
  177. First, set `HUGGINGFACE_ACCESS_TOKEN` in environment variable which you can obtain from [their platform](https://huggingface.co/settings/tokens).
  178. Once you have the token, load the app using the config yaml file:
  179. <CodeGroup>
  180. ```python main.py
  181. import os
  182. from embedchain import App
  183. os.environ["HUGGINGFACE_ACCESS_TOKEN"] = "xxx"
  184. # load llm configuration from config.yaml file
  185. app = App.from_config(yaml_path="config.yaml")
  186. ```
  187. ```yaml config.yaml
  188. llm:
  189. provider: huggingface
  190. model: 'google/flan-t5-xxl'
  191. config:
  192. temperature: 0.5
  193. max_tokens: 1000
  194. top_p: 0.5
  195. stream: false
  196. ```
  197. </CodeGroup>
  198. ## Llama2
  199. Llama2 is integrated through [Replicate](https://replicate.com/). Set `REPLICATE_API_TOKEN` in environment variable which you can obtain from [their platform](https://replicate.com/account/api-tokens).
  200. Once you have the token, load the app using the config yaml file:
  201. <CodeGroup>
  202. ```python main.py
  203. import os
  204. from embedchain import App
  205. os.environ["REPLICATE_API_TOKEN"] = "xxx"
  206. # load llm configuration from config.yaml file
  207. app = App.from_config(yaml_path="config.yaml")
  208. ```
  209. ```yaml config.yaml
  210. llm:
  211. provider: llama2
  212. model: 'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5'
  213. config:
  214. temperature: 0.5
  215. max_tokens: 1000
  216. top_p: 0.5
  217. stream: false
  218. ```
  219. </CodeGroup>
  220. ## Vertex AI
  221. Setup Google Cloud Platform application credentials by following the instruction on [GCP](https://cloud.google.com/docs/authentication/external/set-up-adc). Once setup is done, use the following code to create an app using VertexAI as provider:
  222. <CodeGroup>
  223. ```python main.py
  224. from embedchain import App
  225. # load llm configuration from config.yaml file
  226. app = App.from_config(yaml_path="config.yaml")
  227. ```
  228. ```yaml config.yaml
  229. llm:
  230. provider: vertexai
  231. model: 'chat-bison'
  232. config:
  233. temperature: 0.5
  234. top_p: 0.5
  235. ```
  236. </CodeGroup>
  237. <br/ >
  238. <Snippet file="missing-llm-tip.mdx" />