Skip to content

Commit

Permalink
Update /clear' to use Handler`
Browse files Browse the repository at this point in the history
Builds the message in the help handler and then uses it after clearing chat.
  • Loading branch information
srdas committed Jun 20, 2024
1 parent 90a4c2d commit c46f93c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import List

from jupyter_ai.models import ChatMessage, ClearMessage

from .base import BaseChatHandler, SlashCommandRoutingType

from jupyter_ai.chat_handlers.help import build_help_message

class ClearChatHandler(BaseChatHandler):
"""Clear the chat panel and show the help menu"""
Expand All @@ -19,15 +17,20 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

async def process_message(self, _):
tmp_chat_history = self._chat_history[0]
self._chat_history.clear()
for handler in self._root_chat_handlers.values():
if not handler:
continue

# Clear chat
handler.broadcast_message(ClearMessage())
self._chat_history.clear()

self._chat_history = [tmp_chat_history]
self.reply(tmp_chat_history.body)
# Build /help message and reinstate it in chat
chat_handlers = handler.chat_handlers
persona = self.config_manager.persona
lm_provider = self.config_manager.lm_provider
unsupported_slash_commands = (lm_provider.unsupported_slash_commands if lm_provider else set())
msg = build_help_message(chat_handlers, persona, unsupported_slash_commands)
self.reply(msg.body)

break
break

0 comments on commit c46f93c

Please sign in to comment.