llms.mdx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. </CardGroup>
  12. ## OpenAI
  13. 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).
  14. Once you have obtained the key, you can use it like this:
  15. ```python
  16. import os
  17. from mem0 import Memory
  18. os.environ['OPENAI_API_KEY'] = 'xxx'
  19. config = {
  20. "llm": {
  21. "provider": "openai",
  22. "config": {
  23. "model": "gpt-4o",
  24. "temperature": 0.2,
  25. "max_tokens": 1500,
  26. }
  27. }
  28. }
  29. m = Memory.from_config(config)
  30. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  31. ```
  32. ## Groq
  33. [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.
  34. 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.
  35. ```python
  36. import os
  37. from mem0 import Memory
  38. os.environ['GROQ_API_KEY'] = 'xxx'
  39. config = {
  40. "llm": {
  41. "provider": "groq",
  42. "config": {
  43. "model": "mixtral-8x7b-32768",
  44. "temperature": 0.1,
  45. "max_tokens": 1000,
  46. }
  47. }
  48. }
  49. m = Memory.from_config(config)
  50. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  51. ```
  52. ## TogetherAI
  53. 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).
  54. Once you have obtained the key, you can use it like this:
  55. ```python
  56. import os
  57. from mem0 import Memory
  58. os.environ['TOGETHER_API_KEY'] = 'xxx'
  59. config = {
  60. "llm": {
  61. "provider": "togetherai",
  62. "config": {
  63. "model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
  64. "temperature": 0.2,
  65. "max_tokens": 1500,
  66. }
  67. }
  68. }
  69. m = Memory.from_config(config)
  70. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  71. ```
  72. ## AWS Bedrock
  73. ### Setup
  74. - 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).
  75. - 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)
  76. - You will have to export `AWS_REGION`, `AWS_ACCESS_KEY`, and `AWS_SECRET_ACCESS_KEY` to set environment variables.
  77. ```python
  78. import os
  79. from mem0 import Memory
  80. os.environ['AWS_REGION'] = 'us-east-1'
  81. os.environ["AWS_ACCESS_KEY"] = "xx"
  82. os.environ["AWS_SECRET_ACCESS_KEY"] = "xx"
  83. config = {
  84. "llm": {
  85. "provider": "aws_bedrock",
  86. "config": {
  87. "model": "arn:aws:bedrock:us-east-1:123456789012:model/your-model-name",
  88. "temperature": 0.2,
  89. "max_tokens": 1500,
  90. }
  91. }
  92. }
  93. m = Memory.from_config(config)
  94. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  95. ```