Skip to content

Commit ff7bd1a

Browse files
Update chat handling to clear chat and show help; small fix to /export (#826)
* Update chat handling (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. * [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>
1 parent 81e647d commit ff7bd1a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77

88
class ClearChatHandler(BaseChatHandler):
9+
"""Clear the chat panel and show the help menu"""
10+
911
id = "clear"
1012
name = "Clear chat messages"
1113
help = "Clear the chat window"
@@ -17,10 +19,15 @@ def __init__(self, *args, **kwargs):
1719
super().__init__(*args, **kwargs)
1820

1921
async def process_message(self, _):
22+
tmp_chat_history = self._chat_history[0]
2023
self._chat_history.clear()
2124
for handler in self._root_chat_handlers.values():
2225
if not handler:
2326
continue
2427

2528
handler.broadcast_message(ClearMessage())
29+
30+
self._chat_history = [tmp_chat_history]
31+
self.reply(tmp_chat_history.body)
32+
2633
break

packages/jupyter-ai/jupyter_ai/chat_handlers/export.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ async def process_message(self, message: HumanChatMessage):
3535
self.chat_message_to_markdown(msg) for msg in self._chat_history
3636
)
3737
args = self.parse_args(message)
38-
chat_filename = args.path[0] if args.path else "chat_history"
38+
chat_filename = (
39+
args.path[0] if (args.path and args.path[0] != "") else "chat_history"
40+
) # Handles both empty args and double tap <Enter> key
3941
chat_filename = f"{chat_filename}-{datetime.now():%Y-%m-%d-%H-%M}.md"
4042
chat_file = os.path.join(self.root_dir, chat_filename)
4143
with open(chat_file, "w") as chat_history:

0 commit comments

Comments
 (0)