diff --git a/gui/src/components/gui/StepContainer.tsx b/gui/src/components/gui/StepContainer.tsx
index 402975382..2885656ef 100644
--- a/gui/src/components/gui/StepContainer.tsx
+++ b/gui/src/components/gui/StepContainer.tsx
@@ -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) {
/>
)}
+
+ {
+ props.onDelete();
+ }}
+ />
+
)}
diff --git a/gui/src/pages/gui.tsx b/gui/src/pages/gui.tsx
index b5f2f2f62..a4ce15937 100644
--- a/gui/src/pages/gui.tsx
+++ b/gui/src/pages/gui.tsx
@@ -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))}}
/>
diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts
index 59192e7f3..83064677d 100644
--- a/gui/src/redux/slices/stateSlice.ts
+++ b/gui/src/redux/slices/stateSlice.ts
@@ -244,6 +244,23 @@ export const stateSlice = createSlice({
// state.contextItems = [];
state.active = true;
},
+ deleteMessage: (state, action: PayloadAction) => {
+ 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;