Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update clear slash command to use HelpChatHandler to reinstate the help menu #846

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List

from jupyter_ai.chat_handlers.help import build_help_message
from jupyter_ai.models import ChatMessage, ClearMessage

from .base import BaseChatHandler, SlashCommandRoutingType
Expand All @@ -19,15 +20,22 @@ 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 = [tmp_chat_history]
self.reply(tmp_chat_history.body)
self._chat_history.clear()

# 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
Loading