Skip to content

Commit

Permalink
v2.4.30
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Aug 28, 2024
1 parent 3a39189 commit f4d55e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions cookbook/assistants/clear_memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from phi.assistant import Assistant
from phi.llm.openai import OpenAIChat
from phi.utils.log import logger

assistant = Assistant(llm=OpenAIChat(model="gpt-4o"))
# -*- Print a response to the cli
assistant.print_response("Share a 1 line joke")

# -*- Print the assistant memory
logger.info("*** Assistant Memory ***")
logger.info(assistant.memory.to_dict())

# -*- Clear the assistant memory
logger.info("Clearing the assistant memory...")
assistant.memory.clear()
logger.info("*** Assistant Memory ***")
logger.info(assistant.memory.to_dict())
10 changes: 9 additions & 1 deletion phi/memory/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AssistantMemory(BaseModel):

def to_dict(self) -> Dict[str, Any]:
_memory_dict = self.model_dump(
exclude_none=True, exclude={"db", "updating", "memories", "classifier", "manager"}
exclude_none=True, exclude={"db", "updating", "memories", "classifier", "manager", "retrieval"}
)
if self.memories:
_memory_dict["memories"] = [memory.to_dict() for memory in self.memories]
Expand Down Expand Up @@ -220,3 +220,11 @@ def get_memories_for_system_prompt(self) -> Optional[str]:
memory_str += "\n</memory_from_previous_interactions>"

return memory_str

def clear(self) -> None:
"""Clears the assistant memory"""
self.chat_history = []
self.llm_messages = []
self.references = []
self.memories = None
logger.debug("Assistant Memory cleared")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.4.29"
version = "2.4.30"
description = "Memory, knowledge and tools for LLMs."
requires-python = ">=3.7"
readme = "README.md"
Expand Down

0 comments on commit f4d55e9

Please sign in to comment.