llms.mdx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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="Google AI" href="#google-ai"></Card>
  9. <Card title="Azure OpenAI" href="#azure-openai"></Card>
  10. <Card title="Anthropic" href="#anthropic"></Card>
  11. <Card title="Cohere" href="#cohere"></Card>
  12. <Card title="GPT4All" href="#gpt4all"></Card>
  13. <Card title="JinaChat" href="#jinachat"></Card>
  14. <Card title="Hugging Face" href="#hugging-face"></Card>
  15. <Card title="Llama2" href="#llama2"></Card>
  16. <Card title="Vertex AI" href="#vertex-ai"></Card>
  17. </CardGroup>
  18. ## OpenAI
  19. 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).
  20. Once you have obtained the key, you can use it like this:
  21. ```python
  22. import os
  23. from embedchain import Pipeline as App
  24. os.environ['OPENAI_API_KEY'] = 'xxx'
  25. app = App()
  26. app.add("https://en.wikipedia.org/wiki/OpenAI")
  27. app.query("What is OpenAI?")
  28. ```
  29. 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.
  30. <CodeGroup>
  31. ```python main.py
  32. import os
  33. from embedchain import Pipeline as App
  34. os.environ['OPENAI_API_KEY'] = 'xxx'
  35. # load llm configuration from config.yaml file
  36. app = App.from_config(config_path="config.yaml")
  37. ```
  38. ```yaml config.yaml
  39. llm:
  40. provider: openai
  41. config:
  42. model: 'gpt-3.5-turbo'
  43. temperature: 0.5
  44. max_tokens: 1000
  45. top_p: 1
  46. stream: false
  47. ```
  48. </CodeGroup>
  49. ## Google AI
  50. To use Google AI model, you have to set the `GOOGLE_API_KEY` environment variable. You can obtain the Google API key from the [Google Maker Suite](https://makersuite.google.com/app/apikey)
  51. <CodeGroup>
  52. ```python main.py
  53. import os
  54. from embedchain import Pipeline as App
  55. os.environ["OPENAI_API_KEY"] = "sk-xxxx"
  56. os.environ["GOOGLE_API_KEY"] = "xxx"
  57. app = App.from_config(config_path="config.yaml")
  58. app.add("https://www.forbes.com/profile/elon-musk")
  59. response = app.query("What is the net worth of Elon Musk?")
  60. if app.llm.config.stream: # if stream is enabled, response is a generator
  61. for chunk in response:
  62. print(chunk)
  63. else:
  64. print(response)
  65. ```
  66. ```yaml config.yaml
  67. llm:
  68. provider: google
  69. config:
  70. model: gemini-pro
  71. max_tokens: 1000
  72. temperature: 0.5
  73. top_p: 1
  74. stream: false
  75. ```
  76. </CodeGroup>
  77. ## Azure OpenAI
  78. To use Azure OpenAI model, you have to set some of the azure openai related environment variables as given in the code block below:
  79. <CodeGroup>
  80. ```python main.py
  81. import os
  82. from embedchain import Pipeline as App
  83. os.environ["OPENAI_API_TYPE"] = "azure"
  84. os.environ["OPENAI_API_BASE"] = "https://xxx.openai.azure.com/"
  85. os.environ["OPENAI_API_KEY"] = "xxx"
  86. os.environ["OPENAI_API_VERSION"] = "xxx"
  87. app = App.from_config(config_path="config.yaml")
  88. ```
  89. ```yaml config.yaml
  90. llm:
  91. provider: azure_openai
  92. config:
  93. model: gpt-35-turbo
  94. deployment_name: your_llm_deployment_name
  95. temperature: 0.5
  96. max_tokens: 1000
  97. top_p: 1
  98. stream: false
  99. embedder:
  100. provider: azure_openai
  101. config:
  102. model: text-embedding-ada-002
  103. deployment_name: you_embedding_model_deployment_name
  104. ```
  105. </CodeGroup>
  106. You can find the list of models and deployment name on the [Azure OpenAI Platform](https://oai.azure.com/portal).
  107. ## Anthropic
  108. 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).
  109. <CodeGroup>
  110. ```python main.py
  111. import os
  112. from embedchain import Pipeline as App
  113. os.environ["ANTHROPIC_API_KEY"] = "xxx"
  114. # load llm configuration from config.yaml file
  115. app = App.from_config(config_path="config.yaml")
  116. ```
  117. ```yaml config.yaml
  118. llm:
  119. provider: anthropic
  120. config:
  121. model: 'claude-instant-1'
  122. temperature: 0.5
  123. max_tokens: 1000
  124. top_p: 1
  125. stream: false
  126. ```
  127. </CodeGroup>
  128. ## Cohere
  129. Install related dependencies using the following command:
  130. ```bash
  131. pip install --upgrade 'embedchain[cohere]'
  132. ```
  133. Set the `COHERE_API_KEY` as environment variable which you can find on their [Account settings page](https://dashboard.cohere.com/api-keys).
  134. Once you have the API key, you are all set to use it with Embedchain.
  135. <CodeGroup>
  136. ```python main.py
  137. import os
  138. from embedchain import Pipeline as App
  139. os.environ["COHERE_API_KEY"] = "xxx"
  140. # load llm configuration from config.yaml file
  141. app = App.from_config(config_path="config.yaml")
  142. ```
  143. ```yaml config.yaml
  144. llm:
  145. provider: cohere
  146. config:
  147. model: large
  148. temperature: 0.5
  149. max_tokens: 1000
  150. top_p: 1
  151. ```
  152. </CodeGroup>
  153. ## GPT4ALL
  154. Install related dependencies using the following command:
  155. ```bash
  156. pip install --upgrade 'embedchain[opensource]'
  157. ```
  158. 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:
  159. <CodeGroup>
  160. ```python main.py
  161. from embedchain import Pipeline as App
  162. # load llm configuration from config.yaml file
  163. app = App.from_config(config_path="config.yaml")
  164. ```
  165. ```yaml config.yaml
  166. llm:
  167. provider: gpt4all
  168. config:
  169. model: 'orca-mini-3b-gguf2-q4_0.gguf'
  170. temperature: 0.5
  171. max_tokens: 1000
  172. top_p: 1
  173. stream: false
  174. embedder:
  175. provider: gpt4all
  176. ```
  177. </CodeGroup>
  178. ## JinaChat
  179. First, set `JINACHAT_API_KEY` in environment variable which you can obtain from [their platform](https://chat.jina.ai/api).
  180. Once you have the key, load the app using the config yaml file:
  181. <CodeGroup>
  182. ```python main.py
  183. import os
  184. from embedchain import Pipeline as App
  185. os.environ["JINACHAT_API_KEY"] = "xxx"
  186. # load llm configuration from config.yaml file
  187. app = App.from_config(config_path="config.yaml")
  188. ```
  189. ```yaml config.yaml
  190. llm:
  191. provider: jina
  192. config:
  193. temperature: 0.5
  194. max_tokens: 1000
  195. top_p: 1
  196. stream: false
  197. ```
  198. </CodeGroup>
  199. ## Hugging Face
  200. Install related dependencies using the following command:
  201. ```bash
  202. pip install --upgrade 'embedchain[huggingface-hub]'
  203. ```
  204. First, set `HUGGINGFACE_ACCESS_TOKEN` in environment variable which you can obtain from [their platform](https://huggingface.co/settings/tokens).
  205. Once you have the token, load the app using the config yaml file:
  206. <CodeGroup>
  207. ```python main.py
  208. import os
  209. from embedchain import Pipeline as App
  210. os.environ["HUGGINGFACE_ACCESS_TOKEN"] = "xxx"
  211. # load llm configuration from config.yaml file
  212. app = App.from_config(config_path="config.yaml")
  213. ```
  214. ```yaml config.yaml
  215. llm:
  216. provider: huggingface
  217. config:
  218. model: 'google/flan-t5-xxl'
  219. temperature: 0.5
  220. max_tokens: 1000
  221. top_p: 0.5
  222. stream: false
  223. ```
  224. </CodeGroup>
  225. ## Llama2
  226. 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).
  227. Once you have the token, load the app using the config yaml file:
  228. <CodeGroup>
  229. ```python main.py
  230. import os
  231. from embedchain import Pipeline as App
  232. os.environ["REPLICATE_API_TOKEN"] = "xxx"
  233. # load llm configuration from config.yaml file
  234. app = App.from_config(config_path="config.yaml")
  235. ```
  236. ```yaml config.yaml
  237. llm:
  238. provider: llama2
  239. config:
  240. model: 'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5'
  241. temperature: 0.5
  242. max_tokens: 1000
  243. top_p: 0.5
  244. stream: false
  245. ```
  246. </CodeGroup>
  247. ## Vertex AI
  248. 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:
  249. <CodeGroup>
  250. ```python main.py
  251. from embedchain import Pipeline as App
  252. # load llm configuration from config.yaml file
  253. app = App.from_config(config_path="config.yaml")
  254. ```
  255. ```yaml config.yaml
  256. llm:
  257. provider: vertexai
  258. config:
  259. model: 'chat-bison'
  260. temperature: 0.5
  261. top_p: 0.5
  262. ```
  263. </CodeGroup>
  264. <br/ >
  265. <Snippet file="missing-llm-tip.mdx" />