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:
parent
fe4a987ef2
commit
087ec6ccaa
3 changed files with 31 additions and 1 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue