-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathquickstart.py
61 lines (47 loc) · 1.27 KB
/
quickstart.py
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
53
54
55
56
57
58
59
60
61
from rich import print
from memobase import MemoBaseClient, ChatBlob
PROJECT_URL = "http://localhost:8019"
PROJECT_TOKEN = "secret"
client = MemoBaseClient(
project_url=PROJECT_URL,
api_key=PROJECT_TOKEN,
)
assert client.ping(), "Your Memobase server is not running"
messages = [
{
"role": "user",
"content": "Hello, I'm Gus",
"created_at": "2025-01-14",
},
{
"role": "assistant",
"content": "Hi, nice to meet you, Gus!",
"alias": "HerAI",
},
]
blob = ChatBlob(messages=messages)
uid = client.add_user()
u = client.get_user(uid)
bid = u.insert(blob)
print("User ID is", uid)
print("Blob ID is", bid)
print("Start processing...")
u.flush()
print("\n--------------\nBelow is your profile:")
print(u.profile(need_json=True))
print("\n--------------\nYou can use Memobase Event to recent details of the user:")
for e in u.event():
print("📅", e.created_at.astimezone().strftime("%Y-%m-%d %H:%M:%S"))
for i in e.event_data.profile_delta:
print(
"-", i.attributes["topic"], i.attributes["sub_topic"], i.content, sep="::"
)
print(
"\n--------------\nYou can use Memobase Context to get a memory prompt and insert it into your prompt:"
)
print(
f"""```
{u.context()}
```
"""
)