Skip to content

Commit

Permalink
Update chat handling
Browse files Browse the repository at this point in the history
(1) Make sure to use the `chat_history` prefix in the filename if none is supplied and not use a blank string on double `<Enter>`

(2) When using `/clear` clear the entire chat but show the help menu.
  • Loading branch information
srdas authored and dlqqq committed Jun 12, 2024
1 parent 81e647d commit 83ca89e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from .base import BaseChatHandler, SlashCommandRoutingType


class ClearChatHandler(BaseChatHandler):
"""Clear the chat panel and show the help menu"""
id = "clear"
name = "Clear chat messages"
help = "Clear the chat window"
Expand All @@ -17,10 +17,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())
break

self._chat_history = [tmp_chat_history]
self.reply(tmp_chat_history.body)

break
4 changes: 2 additions & 2 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async def process_message(self, message: HumanChatMessage):
markdown_content = "\n\n".join(
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"
args = self.parse_args(message)
chat_filename = args.path[0] if (args.path and args.path[0]!="") else "chat_history" # Handles both empty args and double tap <Enter> 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:
Expand Down

0 comments on commit 83ca89e

Please sign in to comment.