Skip to content

Commit

Permalink
Update clear slash command to use HelpChatHandler to reinstate th…
Browse files Browse the repository at this point in the history
…e help menu (jupyterlab#846)

* Update `/clear' to use `Handler`

Builds the message in the help handler and then uses it after clearing chat.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Marchlak committed Oct 28, 2024
1 parent 4c048dd commit 3c8d609
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit 3c8d609

Please sign in to comment.