llms.mdx 8.3 KB

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