Add a Delete Message button to the StepContainer (#1790)

* Add a delete button

* add a delete message action to the GUI

* Fix off by one error

* format

* This index should be less than length

* Update to trash icon
This commit is contained in:
Josh Vera 2024-07-22 18:39:49 -04:00 • committed by GitHub
parent fe4a987ef2
commit 087ec6ccaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 1 deletions

View file

@ -3,6 +3,7 @@ import {
BarsArrowDownIcon,
HandThumbDownIcon,
HandThumbUpIcon,
TrashIcon,
} from "@heroicons/react/24/outline";
import { ChatHistoryItem } from "core";
import { stripImages } from "core/llm/countTokens";
@ -206,6 +207,16 @@ function StepContainer(props: StepContainerProps) {
/>
</HeaderButtonWithText>
)}
<HeaderButtonWithText text="Delete Message">
<TrashIcon
color={lightGray}
width="1.2em"
height="1.2em"
onClick={() => {
props.onDelete();
}}
/>
</HeaderButtonWithText>
</div>
)}
</div>

View file

@ -42,6 +42,7 @@ import {
clearLastResponse,
newSession,
setInactive,
deleteMessage,
} from "../redux/slices/stateSlice";
import {
setDialogEntryOn,
@ -503,7 +504,7 @@ function GUI() {
"*",
);
}}
onDelete={() => {}}
onDelete={() => {dispatch(deleteMessage(index))}}
/>
</TimelineItem>
</div>

View file

@ -244,6 +244,23 @@ export const stateSlice = createSlice({
// state.contextItems = [];
state.active = true;
},
deleteMessage: (state, action: PayloadAction<number>) => {
const index = action.payload + 1;
if (index >= 0 && index < state.history.length) {
// Delete the current message
state.history.splice(index, 1);
// If the next message is an assistant message, delete it too
if (
index < state.history.length &&
state.history[index].message.role === "assistant"
) {
state.history.splice(index, 1);
}
}
},
initNewActiveMessage: (
state,
{
@ -500,5 +517,6 @@ export const {
clearLastResponse,
consumeMainEditorContent,
setSelectedProfileId,
deleteMessage,
} = stateSlice.actions;
export default stateSlice.reducer;