Skip to content

Commit

Permalink
Remove cleared_message_ids (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchia authored Oct 21, 2024
1 parent b3a5f8c commit 9630742
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions packages/jupyter-ai/jupyter_ai/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ def pending_messages(self) -> List[PendingMessage]:
def pending_messages(self, new_pending_messages):
self.settings["pending_messages"] = new_pending_messages

@property
def cleared_message_ids(self) -> Set[str]:
"""Set of `HumanChatMessage.id` that were cleared via `ClearRequest`."""
if "cleared_message_ids" not in self.settings:
self.settings["cleared_message_ids"] = set()
return self.settings["cleared_message_ids"]

def initialize(self):
self.log.debug("Initializing websocket connection %s", self.request.path)

Expand Down Expand Up @@ -233,7 +226,9 @@ def broadcast_message(self, message: Message):
# do not broadcast agent messages that are replying to cleared human message
if (
isinstance(message, (AgentChatMessage, AgentStreamMessage))
and message.reply_to in self.cleared_message_ids
and message.reply_to
and message.reply_to
not in [m.id for m in self.chat_history if isinstance(m, HumanChatMessage)]
):
return

Expand Down Expand Up @@ -325,10 +320,6 @@ def on_clear_request(self, request: ClearRequest):

# if no target, clear all messages
if not target:
for msg in self.chat_history:
if msg.type == "human":
self.cleared_message_ids.add(msg.id)

self.chat_history.clear()
self.pending_messages.clear()
self.llm_chat_memory.clear()
Expand All @@ -337,7 +328,6 @@ def on_clear_request(self, request: ClearRequest):
return

# otherwise, clear a single message
self.cleared_message_ids.add(target)
for msg in self.chat_history[::-1]:
# interrupt the single message
if msg.type == "agent-stream" and getattr(msg, "reply_to", None) == target:
Expand Down

0 comments on commit 9630742

Please sign in to comment.