-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mem0.py
More file actions
52 lines (43 loc) · 1.17 KB
/
Copy pathtest_mem0.py
File metadata and controls
52 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from dotenv import load_dotenv
from mem0 import MemoryClient
import logging
import json
load_dotenv()
user_name = 'David'
mem0 = MemoryClient()
def add_memory():
messages_formatted = [
{ "role": "user",
"content": "I really like Linkin Park."
},
{
"role": "assistant",
"content": "That is a good choice."
},
{
"role": "user",
"content": "I think so too."
},
{
"role": "assistant",
"content": "What is your favorite song by them?"
},
]
mem0.add(messages_formatted, user_id="David")
def get_memory_by_query():
mem0 = MemoryClient()
query = "What are {user_name}'s preferences?"
results = mem0.search(query, user_id=user_name)
memories = [
{
"memory": result["memory"],
"updated_at": result["updated_at"]
}
for result in results
]
memories_str = json.dumps(memories)
print(f"Memories: {memories_str}")
return memories_str
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
get_memory_by_query()