llms.mdx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ---
  2. title: 🤖 Large language models (LLMs)
  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. </CardGroup>
  11. ## OpenAI
  12. 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).
  13. Once you have obtained the key, you can use it like this:
  14. ```python
  15. import os
  16. from mem0 import Memory
  17. os.environ['OPENAI_API_KEY'] = 'xxx'
  18. config = {
  19. "llm": {
  20. "provider": "openai",
  21. "config": {
  22. "model": "gpt-4o",
  23. "temperature": 0.2,
  24. "max_tokens": 1500,
  25. }
  26. }
  27. }
  28. m = Memory.from_config(config)
  29. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  30. ```
  31. ## Groq
  32. [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.
  33. 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.
  34. ```python
  35. import os
  36. from mem0 import Memory
  37. os.environ['GROQ_API_KEY'] = 'xxx'
  38. config = {
  39. "llm": {
  40. "provider": "groq",
  41. "config": {
  42. "model": "mixtral-8x7b-32768",
  43. "temperature": 0.1,
  44. "max_tokens": 1000,
  45. }
  46. }
  47. }
  48. m = Memory.from_config(config)
  49. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  50. ```
  51. ## TogetherAI
  52. 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).
  53. Once you have obtained the key, you can use it like this:
  54. ```python
  55. import os
  56. from mem0 import Memory
  57. os.environ['TOGETHER_API_KEY'] = 'xxx'
  58. config = {
  59. "llm": {
  60. "provider": "togetherai",
  61. "config": {
  62. "model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
  63. "temperature": 0.2,
  64. "max_tokens": 1500,
  65. }
  66. }
  67. }
  68. m = Memory.from_config(config)
  69. m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
  70. ```