-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathbase.py
31 lines (23 loc) · 909 Bytes
/
base.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
import asyncio
import sys
import traceback
from beeai_framework.backend import AssistantMessage, SystemMessage, UserMessage
from beeai_framework.errors import FrameworkError
from beeai_framework.memory import UnconstrainedMemory
async def main() -> None:
memory = UnconstrainedMemory()
# Single Message
await memory.add(SystemMessage("You are a helpful assistant"))
# Multiple Messages
await memory.add_many([UserMessage("What can you do?"), AssistantMessage("Everything!")])
print(memory.is_empty()) # false
for message in memory.messages: # prints the text of all messages
print(message.text)
print(memory.as_read_only()) # returns a new read only instance
memory.reset() # removes all messages
if __name__ == "__main__":
try:
asyncio.run(main())
except FrameworkError as e:
traceback.print_exc()
sys.exit(e.explain())