From 9fdbefd889c5e6a3124bcca596c497940ed1e4e7 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 24 Apr 2024 15:28:07 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20stop=20loading=20when=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/activation/activate.ts | 15 ++++---- extensions/vscode/src/webviewProtocol.ts | 2 ++ gui/src/hooks/useChatHandler.ts | 37 ++++++++++++-------- gui/src/redux/slices/stateSlice.ts | 4 +++ gui/src/util/ide.ts | 5 +++ 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index 53fff620b..cf248110d 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -6,7 +6,6 @@ import { VsCodeExtension } from "../extension/vscodeExtension"; import registerQuickFixProvider from "../lang-server/codeActions"; import { getExtensionVersion } from "../util/util"; import { getExtensionUri } from "../util/vscode"; -import { showTutorial } from "../webviewProtocol"; import { setupInlineTips } from "./inlineTips"; export async function activateExtension(context: vscode.ExtensionContext) { @@ -19,12 +18,14 @@ export async function activateExtension(context: vscode.ExtensionContext) { const vscodeExtension = new VsCodeExtension(context); - showTutorial(); - vscode.commands.executeCommand( - "markdown.showPreview", - vscode.Uri.file(path.join(getExtensionUri().fsPath, "media", "welcome.md")), - ); - migrate("showWelcome_1", () => {}); + migrate("showWelcome_1", () => { + vscode.commands.executeCommand( + "markdown.showPreview", + vscode.Uri.file( + path.join(getExtensionUri().fsPath, "media", "welcome.md"), + ), + ); + }); // Load Continue configuration if (!context.globalState.get("hasBeenInstalled")) { diff --git a/extensions/vscode/src/webviewProtocol.ts b/extensions/vscode/src/webviewProtocol.ts index f31ac7a7c..f337ca448 100644 --- a/extensions/vscode/src/webviewProtocol.ts +++ b/extensions/vscode/src/webviewProtocol.ts @@ -107,6 +107,8 @@ export class VsCodeWebviewProtocol { respond(response || {}); } } catch (e: any) { + respond({ done: true, error: e }); + console.error( "Error handling webview message: " + JSON.stringify({ msg }, null, 2), diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index 39439680c..4fd91d147 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -20,6 +20,7 @@ import resolveEditorContent from "../components/mainInput/resolveInput"; import { defaultModelSelector } from "../redux/selectors/modelSelectors"; import { addPromptCompletionPair, + clearLastResponse, initNewActiveMessage, resubmitAtIndex, setInactive, @@ -52,23 +53,31 @@ function useChatHandler(dispatch: Dispatch) { async function _streamNormalInput(messages: ChatMessage[]) { const abortController = new AbortController(); const cancelToken = abortController.signal; - const gen = llmStreamChat(defaultModel.title, cancelToken, messages); - let next = await gen.next(); - while (!next.done) { - if (!activeRef.current) { - abortController.abort(); - break; + try { + const gen = llmStreamChat(defaultModel.title, cancelToken, messages); + let next = await gen.next(); + + while (!next.done) { + if (!activeRef.current) { + abortController.abort(); + break; + } + dispatch( + streamUpdate(stripImages((next.value as ChatMessage).content)), + ); + next = await gen.next(); } - dispatch(streamUpdate(stripImages((next.value as ChatMessage).content))); - next = await gen.next(); - } - let returnVal = next.value as LLMReturnValue; - if (returnVal) { - dispatch( - addPromptCompletionPair([[returnVal?.prompt, returnVal?.completion]]), - ); + let returnVal = next.value as LLMReturnValue; + if (returnVal) { + dispatch( + addPromptCompletionPair([[returnVal?.prompt, returnVal?.completion]]), + ); + } + } catch (e) { + // If there's an error, we should clear the response so there aren't two input boxes + dispatch(clearLastResponse()); } } diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 3bc7d6c5d..06d07231d 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -186,6 +186,9 @@ export const stateSlice = createSlice({ setActive: (state) => { state.active = true; }, + clearLastResponse: (state) => { + state.history = state.history.slice(0, -2); + }, setContextItemsAtIndex: ( state, { @@ -492,5 +495,6 @@ export const { setEditingContextItemAtIndex, initNewActiveMessage, setMessageAtIndex, + clearLastResponse, } = stateSlice.actions; export default stateSlice.reducer; diff --git a/gui/src/util/ide.ts b/gui/src/util/ide.ts index 28e7557fc..6d03c5c36 100644 --- a/gui/src/util/ide.ts +++ b/gui/src/util/ide.ts @@ -170,6 +170,11 @@ export async function* llmStreamChat( yield { role: "user", content: next.value }; next = await gen.next(); } + + if (next.value.error) { + throw new Error(next.value.error); + } + return { prompt: next.value.content?.prompt, completion: next.value.content?.completion,