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

Clear both chat history and conversation memory when /clear is applied #842

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 6 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,12 @@ 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]
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
self._chat_history.clear()

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

Expand Down
Loading