Skip to content

Commit

Permalink
Clear both chat history and conversation memory
Browse files Browse the repository at this point in the history
(1) Updated `clear.py` to clear chat history and display the help command again.
(2) Updated `base.py` to remove conversation memory when chat history is cleared.
  • Loading branch information
srdas committed Jun 19, 2024
1 parent 02d1966 commit c992b6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/jupyter-ai/jupyter_ai/chat_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ def get_llm_chain(self):
if not lm_provider or not lm_provider_params:
return None

if curr_lm_id != next_lm_id:
if len(self._chat_history) <= 2: # Check if chat history has been cleared, then reinitialize the llm chain
self.log.info("Clear conversation memory, re-initializing the llm chain.")
self.create_llm_chain(lm_provider, lm_provider_params)
elif curr_lm_id != next_lm_id:
self.log.info(
f"Switching chat language model from {curr_lm_id} to {next_lm_id}."
)
Expand Down
5 changes: 3 additions & 2 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +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())

tmp_chat_history = self._chat_history[0]
self._chat_history.clear()

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

Expand Down

0 comments on commit c992b6c

Please sign in to comment.