From 92a688c7a8c1fe1ace3426fe2be521b9f5d55afb Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 6 Dec 2024 17:58:34 -0800 Subject: [PATCH 1/2] cancelStream --- gui/src/pages/gui/Chat.tsx | 3 ++- gui/src/redux/thunks/cancelStream.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gui/src/redux/thunks/cancelStream.ts diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 8545813bc..851a6f13b 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -57,6 +57,7 @@ import { setShowDialog, } from "../../redux/slices/uiSlice"; import { RootState } from "../../redux/store"; +import { cancelStream } from "../../redux/thunks/cancelStream"; import { exitEditMode } from "../../redux/thunks/exitEditMode"; import { streamResponseThunk } from "../../redux/thunks/streamResponse"; import { @@ -203,7 +204,7 @@ export function Chat() { isMetaEquivalentKeyPressed(e) && !e.shiftKey ) { - // dispatch(cancelGeneration()); TODO!!! + dispatch(cancelStream()); } }; window.addEventListener("keydown", listener); diff --git a/gui/src/redux/thunks/cancelStream.ts b/gui/src/redux/thunks/cancelStream.ts new file mode 100644 index 000000000..0f1a6aeca --- /dev/null +++ b/gui/src/redux/thunks/cancelStream.ts @@ -0,0 +1,14 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { setInactive } from "../slices/sessionSlice"; +import { ThunkApiType } from "../store"; + +export const cancelStream = createAsyncThunk( + "chat/cancelStream", + async (messages, { dispatch, extra, getState }) => { + dispatch(setInactive()); + + // If the assistant message is empty, then remove it and the user message, placing the user input in the main text box + // TODO: Waiting until next release + // dispatch(clearLastEmptyResponse()); + }, +); From 1520d0815a4737228b729906cdb9d72851fbf63a Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 6 Dec 2024 18:04:02 -0800 Subject: [PATCH 2/2] abortStream() --- gui/src/redux/thunks/cancelStream.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui/src/redux/thunks/cancelStream.ts b/gui/src/redux/thunks/cancelStream.ts index 0f1a6aeca..dc23c04a6 100644 --- a/gui/src/redux/thunks/cancelStream.ts +++ b/gui/src/redux/thunks/cancelStream.ts @@ -1,11 +1,12 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; -import { setInactive } from "../slices/sessionSlice"; +import { abortStream, setInactive } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; export const cancelStream = createAsyncThunk( "chat/cancelStream", async (messages, { dispatch, extra, getState }) => { dispatch(setInactive()); + dispatch(abortStream()); // If the assistant message is empty, then remove it and the user message, placing the user input in the main text box // TODO: Waiting until next release