llms.mdx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. ---
  2. title: 🤖 Overview
  3. ---
  4. ## Overview
  5. Mem0 includes built-in support for various popular large language models. Memory can utilize the LLM provided by the user, ensuring efficient use for specific needs.
  6. <CardGroup cols={4}>
  7. <Card title="OpenAI" href="#openai"></Card>
  8. <Card title="Groq" href="#groq"></Card>
  9. <Card title="Together" href="#together"></Card>
  10. <Card title="AWS Bedrock" href="#aws_bedrock"></Card>
  11. <Card title="Litellm" href="#litellm"></Card>
  12. <Card title="Google AI" href="#google-ai"></Card>
  13. <Card title="Anthropic" href="#anthropic"></Card>
  14. </CardGroup>
  15. ## OpenAI
  16. 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).
  17. Once you have obtained the key, you can use it like this:
  18. ```python
  19. import os
  20. from mem0 import Memory
  21. os.environ["OPENAI_API_KEY"] = "your-api-key"
  22. config = {
  23. "llm": {
  24. "provider": "openai",
  25. "config": {
  26. "model": "gpt-4o",
  27. "temperature": 0.2,
  28. "max_tokens": 1500,
  29. }
  30. }
  31. }
  32. m = Memory.from_config(config)
  33. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  34. ```
  35. ## Groq
  36. [Groq](https://groq.com/) is the creator of the world's first Language Processing Unit (LPU), providing exceptional speed performance for AI workloads running on their LPU Inference Engine.
  37. In order to use LLMs from Groq, go to their [platform](https://console.groq.com/keys) and get the API key. Set the API key as `GROQ_API_KEY` environment variable to use the model as given below in the example.
  38. ```python
  39. import os
  40. from mem0 import Memory
  41. os.environ["GROQ_API_KEY"] = "your-api-key"
  42. config = {
  43. "llm": {
  44. "provider": "groq",
  45. "config": {
  46. "model": "mixtral-8x7b-32768",
  47. "temperature": 0.1,
  48. "max_tokens": 1000,
  49. }
  50. }
  51. }
  52. m = Memory.from_config(config)
  53. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  54. ```
  55. ## TogetherAI
  56. To use TogetherAI LLM models, you have to set the `TOGETHER_API_KEY` environment variable. You can obtain the TogetherAI API key from their [Account settings page](https://api.together.xyz/settings/api-keys).
  57. Once you have obtained the key, you can use it like this:
  58. ```python
  59. import os
  60. from mem0 import Memory
  61. os.environ["TOGETHER_API_KEY"] = "your-api-key"
  62. config = {
  63. "llm": {
  64. "provider": "togetherai",
  65. "config": {
  66. "model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
  67. "temperature": 0.2,
  68. "max_tokens": 1500,
  69. }
  70. }
  71. }
  72. m = Memory.from_config(config)
  73. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  74. ```
  75. ## AWS Bedrock
  76. ### Setup
  77. - Before using the AWS Bedrock LLM, make sure you have the appropriate model access from [Bedrock Console](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess).
  78. - You will also need to authenticate the `boto3` client by using a method in the [AWS documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#configuring-credentials)
  79. - You will have to export `AWS_REGION`, `AWS_ACCESS_KEY`, and `AWS_SECRET_ACCESS_KEY` to set environment variables.
  80. ```python
  81. import os
  82. from mem0 import Memory
  83. os.environ['AWS_REGION'] = 'us-east-1'
  84. os.environ["AWS_ACCESS_KEY"] = "xx"
  85. os.environ["AWS_SECRET_ACCESS_KEY"] = "xx"
  86. config = {
  87. "llm": {
  88. "provider": "aws_bedrock",
  89. "config": {
  90. "model": "arn:aws:bedrock:us-east-1:123456789012:model/your-model-name",
  91. "temperature": 0.2,
  92. "max_tokens": 1500,
  93. }
  94. }
  95. }
  96. m = Memory.from_config(config)
  97. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  98. ```
  99. ## Litellm
  100. [Litellm](https://litellm.vercel.app/docs/) is compatible with over 100 large language models (LLMs), all using a standardized input/output format. You can explore the [available models]((https://litellm.vercel.app/docs/providers)) to use with Litellm. Ensure you set the `API_KEY` for the model you choose to use.
  101. ```python
  102. import os
  103. from mem0 import Memory
  104. os.environ["OPENAI_API_KEY"] = "your-api-key"
  105. config = {
  106. "llm": {
  107. "provider": "litellm",
  108. "config": {
  109. "model": "gpt-3.5-turbo",
  110. "temperature": 0.2,
  111. "max_tokens": 1500,
  112. }
  113. }
  114. }
  115. m = Memory.from_config(config)
  116. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  117. ```
  118. ## Google AI
  119. 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)
  120. Once you have obtained the key, you can use it like this:
  121. ```python
  122. import os
  123. from mem0 import Memory
  124. os.environ["GEMINI_API_KEY"] = "your-api-key"
  125. config = {
  126. "llm": {
  127. "provider": "litellm",
  128. "config": {
  129. "model": "gemini/gemini-pro",
  130. "temperature": 0.2,
  131. "max_tokens": 1500,
  132. }
  133. }
  134. }
  135. m = Memory.from_config(config)
  136. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  137. ```
  138. ## Anthropic
  139. 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).
  140. ```python
  141. import os
  142. from mem0 import Memory
  143. os.environ["ANTHROPIC_API_KEY"] = "your-api-key"
  144. config = {
  145. "llm": {
  146. "provider": "litellm",
  147. "config": {
  148. "model": "claude-3-opus-20240229",
  149. "temperature": 0.1,
  150. "max_tokens": 2000,
  151. }
  152. }
  153. }
  154. m = Memory.from_config(config)
  155. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  156. ```