🐛 stop loading when error
This commit is contained in:
parent
646b19c4bf
commit
9fdbefd889
5 changed files with 42 additions and 21 deletions
|
|
@ -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")) {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue