blob: 85ce6f821913cb0d98379f708ca2d2313d2d1736 (
plain) (
blame)
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
|
from supermemory import Supermemory
client = Supermemory()
USER_ID = "dhravya"
conversation = [
{"role": "assistant", "content": "Hello, how are you doing?"},
{"role": "user", "content": "Hello! I am Dhravya. I am 20 years old. I love to code!"},
{"role": "user", "content": "Can I go to the club?"},
]
# Get user profile + relevant memories for context
profile = client.profile(container_tag=USER_ID, q=conversation[-1]["content"])
static = "\n".join(profile.profile.static)
dynamic = "\n".join(profile.profile.dynamic)
memories = "\n".join(r.get("memory", "") for r in profile.search_results.results)
context = f"""Static profile:
{static}
Dynamic profile:
{dynamic}
Relevant memories:
{memories}"""
# Build messages with memory-enriched context
messages = [{"role": "system", "content": f"User context:\n{context}"}, *conversation]
# response = llm.chat(messages=messages)
# Store conversation for future context
client.add(
content="\n".join(f"{m['role']}: {m['content']}" for m in conversation),
container_tag=USER_ID,
)
|