Skip to content

Commit

Permalink
feat(bridge/python): memory clear method
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed May 23, 2023
1 parent ab7e2a9 commit 3b77d64
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bridges/python/src/sdk/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ def __init__(self, options):
'memory',
options.name + '.json'
)

def clear(self) -> None:
if self.default_memory:
self.write(self.default_memory)
else:
raise ValueError(f'You cannot clear the memory "{self.name}" as it belongs to another skill')
47 changes: 47 additions & 0 deletions skills/utilities/timekeeper/src/actions/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO: find better way to import SDK modules
from bridges.python.src.sdk.leon import leon
from bridges.python.src.sdk.memory import Memory
from bridges.python.src.sdk.aurora.button import Button


Expand All @@ -13,6 +14,52 @@ def run(params):

###

other_skill_memory = Memory({
'name': 'productivity:todo_list:db'
})
todo_lists = other_skill_memory.read()
print('todo_lists', todo_lists)

posts_memory = Memory({ 'name': 'posts', 'default_memory': [] })
posts_memory.write([
{
'id': 0,
'title': 'Hello world',
'content': 'This is a test post',
'author': {
'name': 'Louis'
}
},
{
'id': 1,
'title': 'Hello world 2',
'content': 'This is a test post 2',
'author': {
'name': 'Louis'
}
}
])
posts = posts_memory.read()
print('posts', posts)

posts = posts_memory.write([
*posts,
{
'id': 2,
'title': 'Hello world 3',
'content': 'This is a test post 3',
'author': {
'name': 'Louis'
}
}
])

found_post = next((post for post in posts if post['id'] == 2), None)

print('found_post', found_post)

###

button = Button({'text': 'Hello world from action skill'})

leon.answer({'widget': button})
Expand Down

0 comments on commit 3b77d64

Please sign in to comment.