diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py index 0555abfca..51526801b 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py @@ -6,6 +6,8 @@ class ClearChatHandler(BaseChatHandler): + """Clear the chat panel and show the help menu""" + id = "clear" name = "Clear chat messages" help = "Clear the chat window" @@ -17,10 +19,15 @@ 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 handler.broadcast_message(ClearMessage()) + + self._chat_history = [tmp_chat_history] + self.reply(tmp_chat_history.body) + break diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py index 3bde63018..ec3f1e53a 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/export.py @@ -35,7 +35,9 @@ async def process_message(self, message: HumanChatMessage): self.chat_message_to_markdown(msg) for msg in self._chat_history ) args = self.parse_args(message) - chat_filename = args.path[0] if args.path else "chat_history" + chat_filename = ( + args.path[0] if (args.path and args.path[0] != "") else "chat_history" + ) # Handles both empty args and double tap key chat_filename = f"{chat_filename}-{datetime.now():%Y-%m-%d-%H-%M}.md" chat_file = os.path.join(self.root_dir, chat_filename) with open(chat_file, "w") as chat_history: