From c46f93c6aa876b7b2c1b205156431bcfb95777fd Mon Sep 17 00:00:00 2001 From: Sanjiv Das Date: Thu, 20 Jun 2024 11:48:46 -0700 Subject: [PATCH] Update `/clear' to use `Handler` Builds the message in the help handler and then uses it after clearing chat. --- .../jupyter_ai/chat_handlers/clear.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py index 51526801b..9fbebd7ee 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py @@ -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""" @@ -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 \ No newline at end of file