llms.mdx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. _Coming soon_
  50. ## Anthropic
  51. 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).
  52. <CodeGroup>
  53. ```python main.py
  54. import os
  55. from embedchain import App
  56. os.environ["ANTHROPIC_API_KEY"] = "xxx"
  57. # load llm configuration from config.yaml file
  58. app = App.from_config(yaml_path="config.yaml")
  59. ```
  60. ```yaml config.yaml
  61. llm:
  62. provider: anthropic
  63. model: 'claude-instant-1'
  64. config:
  65. temperature: 0.5
  66. max_tokens: 1000
  67. top_p: 1
  68. stream: false
  69. ```
  70. </CodeGroup>
  71. ## Cohere
  72. Install related dependencies using the following command:
  73. ```bash
  74. pip install --upgrade 'embedchain[cohere]'
  75. ```
  76. Set the `COHERE_API_KEY` as environment variable which you can find on their [Account settings page](https://dashboard.cohere.com/api-keys).
  77. Once you have the API key, you are all set to use it with Embedchain.
  78. <CodeGroup>
  79. ```python main.py
  80. import os
  81. from embedchain import App
  82. os.environ["COHERE_API_KEY"] = "xxx"
  83. # load llm configuration from config.yaml file
  84. app = App.from_config(yaml_path="config.yaml")
  85. ```
  86. ```yaml config.yaml
  87. llm:
  88. provider: cohere
  89. model: large
  90. config:
  91. temperature: 0.5
  92. max_tokens: 1000
  93. top_p: 1
  94. ```
  95. </CodeGroup>
  96. ## GPT4ALL
  97. Install related dependencies using the following command:
  98. ```bash
  99. pip install --upgrade 'embedchain[opensource]'
  100. ```
  101. 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:
  102. <CodeGroup>
  103. ```python main.py
  104. from embedchain import App
  105. # load llm configuration from config.yaml file
  106. app = App.from_config(yaml_path="config.yaml")
  107. ```
  108. ```yaml config.yaml
  109. llm:
  110. provider: gpt4all
  111. model: 'orca-mini-3b.ggmlv3.q4_0.bin'
  112. config:
  113. temperature: 0.5
  114. max_tokens: 1000
  115. top_p: 1
  116. stream: false
  117. embedder:
  118. provider: gpt4all
  119. config:
  120. model: 'all-MiniLM-L6-v2'
  121. ```
  122. </CodeGroup>
  123. ## JinaChat
  124. First, set `JINACHAT_API_KEY` in environment variable which you can obtain from [their platform](https://chat.jina.ai/api).
  125. Once you have the key, load the app using the config yaml file:
  126. <CodeGroup>
  127. ```python main.py
  128. import os
  129. from embedchain import App
  130. os.environ["JINACHAT_API_KEY"] = "xxx"
  131. # load llm configuration from config.yaml file
  132. app = App.from_config(yaml_path="config.yaml")
  133. ```
  134. ```yaml config.yaml
  135. llm:
  136. provider: jina
  137. config:
  138. temperature: 0.5
  139. max_tokens: 1000
  140. top_p: 1
  141. stream: false
  142. ```
  143. </CodeGroup>
  144. ## Hugging Face
  145. Install related dependencies using the following command:
  146. ```bash
  147. pip install --upgrade 'embedchain[huggingface_hub]'
  148. ```
  149. First, set `HUGGINGFACE_ACCESS_TOKEN` in environment variable which you can obtain from [their platform](https://huggingface.co/settings/tokens).
  150. Once you have the token, load the app using the config yaml file:
  151. <CodeGroup>
  152. ```python main.py
  153. import os
  154. from embedchain import App
  155. os.environ["HUGGINGFACE_ACCESS_TOKEN"] = "xxx"
  156. # load llm configuration from config.yaml file
  157. app = App.from_config(yaml_path="config.yaml")
  158. ```
  159. ```yaml config.yaml
  160. llm:
  161. provider: huggingface
  162. model: 'google/flan-t5-xxl'
  163. config:
  164. temperature: 0.5
  165. max_tokens: 1000
  166. top_p: 0.5
  167. stream: false
  168. ```
  169. </CodeGroup>
  170. ## Llama2
  171. 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).
  172. Once you have the token, load the app using the config yaml file:
  173. <CodeGroup>
  174. ```python main.py
  175. import os
  176. from embedchain import App
  177. os.environ["REPLICATE_API_TOKEN"] = "xxx"
  178. # load llm configuration from config.yaml file
  179. app = App.from_config(yaml_path="config.yaml")
  180. ```
  181. ```yaml config.yaml
  182. llm:
  183. provider: llama2
  184. model: 'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5'
  185. config:
  186. temperature: 0.5
  187. max_tokens: 1000
  188. top_p: 0.5
  189. stream: false
  190. ```
  191. </CodeGroup>
  192. ## Vertex AI
  193. 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:
  194. <CodeGroup>
  195. ```python main.py
  196. from embedchain import App
  197. # load llm configuration from config.yaml file
  198. app = App.from_config(yaml_path="config.yaml")
  199. ```
  200. ```yaml config.yaml
  201. llm:
  202. provider: vertexai
  203. model: 'chat-bison'
  204. config:
  205. temperature: 0.5
  206. top_p: 0.5
  207. ```
  208. </CodeGroup>
  209. <br/ >
  210. <Snippet file="missing-llm-tip.mdx" />