llms.mdx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 Pipeline as 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 Pipeline as 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. config:
  41. model: 'gpt-3.5-turbo'
  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 Pipeline as 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. config:
  64. model: gpt-35-turbo
  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 Pipeline as 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. config:
  92. model: 'claude-instant-1'
  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 Pipeline as 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. config:
  118. model: large
  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 Pipeline as 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. config:
  140. model: 'orca-mini-3b-gguf2-q4_0.gguf'
  141. temperature: 0.5
  142. max_tokens: 1000
  143. top_p: 1
  144. stream: false
  145. embedder:
  146. provider: gpt4all
  147. ```
  148. </CodeGroup>
  149. ## JinaChat
  150. First, set `JINACHAT_API_KEY` in environment variable which you can obtain from [their platform](https://chat.jina.ai/api).
  151. Once you have the key, load the app using the config yaml file:
  152. <CodeGroup>
  153. ```python main.py
  154. import os
  155. from embedchain import Pipeline as App
  156. os.environ["JINACHAT_API_KEY"] = "xxx"
  157. # load llm configuration from config.yaml file
  158. app = App.from_config(yaml_path="config.yaml")
  159. ```
  160. ```yaml config.yaml
  161. llm:
  162. provider: jina
  163. config:
  164. temperature: 0.5
  165. max_tokens: 1000
  166. top_p: 1
  167. stream: false
  168. ```
  169. </CodeGroup>
  170. ## Hugging Face
  171. Install related dependencies using the following command:
  172. ```bash
  173. pip install --upgrade 'embedchain[huggingface_hub]'
  174. ```
  175. First, set `HUGGINGFACE_ACCESS_TOKEN` in environment variable which you can obtain from [their platform](https://huggingface.co/settings/tokens).
  176. Once you have the token, load the app using the config yaml file:
  177. <CodeGroup>
  178. ```python main.py
  179. import os
  180. from embedchain import Pipeline as App
  181. os.environ["HUGGINGFACE_ACCESS_TOKEN"] = "xxx"
  182. # load llm configuration from config.yaml file
  183. app = App.from_config(yaml_path="config.yaml")
  184. ```
  185. ```yaml config.yaml
  186. llm:
  187. provider: huggingface
  188. config:
  189. model: 'google/flan-t5-xxl'
  190. temperature: 0.5
  191. max_tokens: 1000
  192. top_p: 0.5
  193. stream: false
  194. ```
  195. </CodeGroup>
  196. ## Llama2
  197. 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).
  198. Once you have the token, load the app using the config yaml file:
  199. <CodeGroup>
  200. ```python main.py
  201. import os
  202. from embedchain import Pipeline as App
  203. os.environ["REPLICATE_API_TOKEN"] = "xxx"
  204. # load llm configuration from config.yaml file
  205. app = App.from_config(yaml_path="config.yaml")
  206. ```
  207. ```yaml config.yaml
  208. llm:
  209. provider: llama2
  210. config:
  211. model: 'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5'
  212. temperature: 0.5
  213. max_tokens: 1000
  214. top_p: 0.5
  215. stream: false
  216. ```
  217. </CodeGroup>
  218. ## Vertex AI
  219. 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:
  220. <CodeGroup>
  221. ```python main.py
  222. from embedchain import Pipeline as App
  223. # load llm configuration from config.yaml file
  224. app = App.from_config(yaml_path="config.yaml")
  225. ```
  226. ```yaml config.yaml
  227. llm:
  228. provider: vertexai
  229. config:
  230. model: 'chat-bison'
  231. temperature: 0.5
  232. top_p: 0.5
  233. ```
  234. </CodeGroup>
  235. <br/ >
  236. <Snippet file="missing-llm-tip.mdx" />