jupyter-ai
jupyter-ai copied to clipboard
Add ability to delete messages + start new chat session
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
- Ability to delete a partial set of messages (all messages after a specific human message). Effectively backtracks to a previous chat history state.
- 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
ChatMessageDeletecomponent created for each human message. Similar toChatMessageMenufor agent messages.ChatHandlerobject added as a prop toChatMessagesas it needs to be propagated toChatMessageHeaderthen to theChatMessageDeletecomponent.- Consequently
PendingMessagesnow also has to add theChatHandlerprop since it required by theChatMessageHeadercomponent 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) calledClearRequestwhich is exactly same schema as ClearMessage.- This reuses/overloads the
ChatHandler.sendMessageto send a new type of message. RootChatHandler.on_messagenow has to detect and process the newClearRequesttype- will broadcast a
ClearMessagewith the same 'target' as the request. RootChatHandler.broadcast_messagenow responsible for clearingchat_historyandllm_chat_historyon receiving aClearMessage.- /clear no longer responsible for clearing of the memory, only will broadcast the
ClearMessageand letRootChatHandler.broadcast_messagehandle the rest. - I think
RootChatHandlershould be responsible for clearing the history as part of overall history management as it is already responsible for adding to thechat_history.
- will broadcast a
- tbh
ClearRequestlooks 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 forClearRequest.
- This reuses/overloads the
New Chat
- '+' button on top that sends a
ClearRequestwithout any 'target' parameter. RootChatHandler
TODO
- Implement delete messages from the global
BoundedChatHistoryobject. Pending https://github.com/jupyterlab/jupyter-ai/pull/943. - Add the help message using the
BaseChatHandlermethod. Pending https://github.com/jupyterlab/jupyter-ai/pull/938.