jupyter-ai icon indicating copy to clipboard operation
jupyter-ai copied to clipboard

Add ability to delete messages + start new chat session

Open michaelchia opened this issue 1 year ago • 0 comments
trafficstars

(Draft: partially implemented. Dependent on https://github.com/jupyterlab/jupyter-ai/pull/938 https://github.com/jupyterlab/jupyter-ai/pull/943 https://github.com/jupyterlab/jupyter-ai/pull/944)

Description

  1. Ability to delete a partial set of messages (all messages after a specific human message). Effectively backtracks to a previous chat history state.
  2. Ability to start a new chat. Same as '/clear' with LLM memory reset

Fixes https://github.com/jupyterlab/jupyter-ai/issues/616 (comment requesting for the "New Chat" button)

Demo

Delete message

https://github.com/user-attachments/assets/c0172e6f-5d3b-4c9e-955e-0eaa6d8fa6b1

Start new chat

https://github.com/user-attachments/assets/429d7342-789d-41f3-a0c5-1592c157a340

Implemenation summary

Delete message

  • ChatMessageDelete component created for each human message. Similar to ChatMessageMenu for agent messages.
    • ChatHandler object added as a prop to ChatMessages as it needs to be propagated to ChatMessageHeader then to the ChatMessageDelete component.
    • Consequently PendingMessages now also has to add the ChatHandler prop since it required by the ChatMessageHeader component even though it is unused.
  • Add an optional 'target' parameter to ClearMessage, which is the human message ID to delete at.
  • Create a new request type (in addition of ChatRequest) called ClearRequest which is exactly same schema as ClearMessage.
    • This reuses/overloads the ChatHandler.sendMessage to send a new type of message.
    • RootChatHandler.on_message now has to detect and process the new ClearRequest type
      • will broadcast a ClearMessage with the same 'target' as the request.
      • RootChatHandler.broadcast_message now responsible for clearing chat_history and llm_chat_history on receiving a ClearMessage.
      • /clear no longer responsible for clearing of the memory, only will broadcast the ClearMessage and let RootChatHandler.broadcast_message handle the rest.
      • I think RootChatHandler should be responsible for clearing the history as part of overall history management as it is already responsible for adding to the chat_history.
    • tbh ClearRequest looks a bit awkward as is more like the existing 'Message' (has a type parameter) than a 'Request'. Let me know if there is better design for ClearRequest.

New Chat

  • '+' button on top that sends a ClearRequest without any 'target' parameter.
  • RootChatHandler

TODO

  • Implement delete messages from the global BoundedChatHistory object. Pending https://github.com/jupyterlab/jupyter-ai/pull/943.
  • Add the help message using the BaseChatHandler method. Pending https://github.com/jupyterlab/jupyter-ai/pull/938.

michaelchia avatar Aug 12 '24 17:08 michaelchia