Merge pull request #3010 from continuedev/dallin/5xx
Dont clear non-empty messages on error
This commit is contained in:
commit
38e123bfac
5 changed files with 95 additions and 88 deletions
56
core/core.ts
56
core/core.ts
|
|
@ -535,33 +535,39 @@ export class Core {
|
|||
}
|
||||
}, 100);
|
||||
|
||||
for await (const content of slashCommand.run({
|
||||
input,
|
||||
history,
|
||||
llm,
|
||||
contextItems,
|
||||
params,
|
||||
ide,
|
||||
addContextItem: (item) => {
|
||||
void messenger.request("addContextItem", {
|
||||
item,
|
||||
historyIndex,
|
||||
});
|
||||
},
|
||||
selectedCode,
|
||||
config,
|
||||
fetch: (url, init) =>
|
||||
fetchwithRequestOptions(url, init, config.requestOptions),
|
||||
})) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
break;
|
||||
}
|
||||
if (content) {
|
||||
yield { content };
|
||||
try {
|
||||
for await (const content of slashCommand.run({
|
||||
input,
|
||||
history,
|
||||
llm,
|
||||
contextItems,
|
||||
params,
|
||||
ide,
|
||||
addContextItem: (item) => {
|
||||
void messenger.request("addContextItem", {
|
||||
item,
|
||||
historyIndex,
|
||||
});
|
||||
},
|
||||
selectedCode,
|
||||
config,
|
||||
fetch: (url, init) =>
|
||||
fetchwithRequestOptions(url, init, config.requestOptions),
|
||||
})) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
clearInterval(checkActiveInterval);
|
||||
break;
|
||||
}
|
||||
if (content) {
|
||||
yield { content };
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
clearInterval(checkActiveInterval);
|
||||
}
|
||||
clearInterval(checkActiveInterval);
|
||||
yield { done: true, content: "" };
|
||||
}
|
||||
on("command/run", (msg) =>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ class Anthropic extends BaseLLM {
|
|||
|
||||
public convertMessages(msgs: ChatMessage[]): any[] {
|
||||
// should be public for use within VertexAI
|
||||
const filteredmessages = msgs.filter((m) => m.role !== "system");
|
||||
const filteredmessages = msgs.filter(
|
||||
(m) => m.role !== "system" && !!m.content,
|
||||
);
|
||||
const lastTwoUserMsgIndices = filteredmessages
|
||||
.map((msg, index) => (msg.role === "user" ? index : -1))
|
||||
.filter((index) => index !== -1)
|
||||
|
|
@ -149,7 +151,9 @@ class Anthropic extends BaseLLM {
|
|||
}
|
||||
|
||||
for await (const value of streamSse(response)) {
|
||||
if (value.type == "message_start") {console.log(value);}
|
||||
if (value.type == "message_start") {
|
||||
console.log(value);
|
||||
}
|
||||
if (value.delta?.text) {
|
||||
yield { role: "assistant", content: value.delta.text };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
|||
import {
|
||||
abortStream,
|
||||
addPromptCompletionPair,
|
||||
clearLastResponse,
|
||||
clearLastEmptyResponse,
|
||||
initNewActiveMessage,
|
||||
resubmitAtIndex,
|
||||
setCurCheckpointIndex,
|
||||
|
|
@ -71,35 +71,27 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) {
|
|||
}, [active]);
|
||||
|
||||
async function _streamNormalInput(messages: ChatMessage[]) {
|
||||
try {
|
||||
if (!defaultModel) {
|
||||
throw new Error("Default model not defined");
|
||||
if (!defaultModel) {
|
||||
throw new Error("Default model not defined");
|
||||
}
|
||||
const gen = ideMessenger.llmStreamChat(
|
||||
defaultModel.title,
|
||||
streamAborter.signal,
|
||||
messages,
|
||||
);
|
||||
let next = await gen.next();
|
||||
while (!next.done) {
|
||||
if (!activeRef.current) {
|
||||
dispatch(abortStream());
|
||||
break;
|
||||
}
|
||||
const gen = ideMessenger.llmStreamChat(
|
||||
defaultModel.title,
|
||||
streamAborter.signal,
|
||||
messages,
|
||||
);
|
||||
let next = await gen.next();
|
||||
dispatch(streamUpdate(stripImages((next.value as ChatMessage).content)));
|
||||
next = await gen.next();
|
||||
}
|
||||
|
||||
while (!next.done) {
|
||||
if (!activeRef.current) {
|
||||
dispatch(abortStream());
|
||||
break;
|
||||
}
|
||||
dispatch(
|
||||
streamUpdate(stripImages((next.value as ChatMessage).content)),
|
||||
);
|
||||
next = await gen.next();
|
||||
}
|
||||
|
||||
let returnVal = next.value as PromptLog;
|
||||
if (returnVal) {
|
||||
dispatch(addPromptCompletionPair([returnVal]));
|
||||
}
|
||||
} catch (e) {
|
||||
// If there's an error, we should clear the response so there aren't two input boxes
|
||||
dispatch(clearLastResponse());
|
||||
let returnVal = next.value as PromptLog;
|
||||
if (returnVal) {
|
||||
dispatch(addPromptCompletionPair([returnVal]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,29 +141,35 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) {
|
|||
}
|
||||
}, 100);
|
||||
|
||||
for await (const update of ideMessenger.streamRequest(
|
||||
"command/run",
|
||||
{
|
||||
input,
|
||||
history: messages,
|
||||
modelTitle,
|
||||
slashCommandName: slashCommand.name,
|
||||
contextItems,
|
||||
params: slashCommand.params,
|
||||
historyIndex,
|
||||
selectedCode,
|
||||
},
|
||||
streamAborter.signal,
|
||||
)) {
|
||||
if (!activeRef.current) {
|
||||
dispatch(abortStream());
|
||||
break;
|
||||
}
|
||||
if (typeof update === "string") {
|
||||
dispatch(streamUpdate(update));
|
||||
try {
|
||||
for await (const update of ideMessenger.streamRequest(
|
||||
"command/run",
|
||||
{
|
||||
input,
|
||||
history: messages,
|
||||
modelTitle,
|
||||
slashCommandName: slashCommand.name,
|
||||
contextItems,
|
||||
params: slashCommand.params,
|
||||
historyIndex,
|
||||
selectedCode,
|
||||
},
|
||||
streamAborter.signal,
|
||||
)) {
|
||||
if (!activeRef.current) {
|
||||
dispatch(abortStream());
|
||||
clearInterval(checkActiveInterval);
|
||||
break;
|
||||
}
|
||||
if (typeof update === "string") {
|
||||
dispatch(streamUpdate(update));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
clearInterval(checkActiveInterval);
|
||||
}
|
||||
clearInterval(checkActiveInterval);
|
||||
}
|
||||
|
||||
async function streamResponse(
|
||||
|
|
@ -320,6 +318,7 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) {
|
|||
);
|
||||
}
|
||||
} catch (e: any) {
|
||||
dispatch(clearLastEmptyResponse());
|
||||
console.debug("Error streaming response: ", e);
|
||||
ideMessenger.post("showToast", [
|
||||
"error",
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import { useTutorialCard } from "../../hooks/useTutorialCard";
|
|||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { defaultModelSelector } from "../../redux/selectors/modelSelectors";
|
||||
import {
|
||||
clearLastResponse,
|
||||
clearLastEmptyResponse,
|
||||
newSession,
|
||||
setInactive,
|
||||
} from "../../redux/slices/stateSlice";
|
||||
|
|
@ -400,12 +400,7 @@ export function Chat() {
|
|||
<StopButton
|
||||
onClick={() => {
|
||||
dispatch(setInactive());
|
||||
if (
|
||||
state.history[state.history.length - 1]?.message.content
|
||||
.length === 0
|
||||
) {
|
||||
dispatch(clearLastResponse());
|
||||
}
|
||||
dispatch(clearLastEmptyResponse());
|
||||
}}
|
||||
>
|
||||
{getMetaKeyLabel()} ⌫ Cancel
|
||||
|
|
|
|||
|
|
@ -144,13 +144,16 @@ export const stateSlice = createSlice({
|
|||
state.context.isGathering = payload.isGathering;
|
||||
state.context.gatheringMessage = payload.gatheringMessage;
|
||||
},
|
||||
clearLastResponse: (state) => {
|
||||
clearLastEmptyResponse: (state) => {
|
||||
if (state.history.length < 2) {
|
||||
return;
|
||||
}
|
||||
state.mainEditorContent =
|
||||
state.history[state.history.length - 2].editorState;
|
||||
state.history = state.history.slice(0, -2);
|
||||
// Only clear in the case of an empty message
|
||||
if (!state.history[state.history.length - 1]?.message.content.length) {
|
||||
state.mainEditorContent =
|
||||
state.history[state.history.length - 2].editorState;
|
||||
state.history = state.history.slice(0, -2);
|
||||
}
|
||||
},
|
||||
consumeMainEditorContent: (state) => {
|
||||
state.mainEditorContent = undefined;
|
||||
|
|
@ -464,7 +467,7 @@ export const {
|
|||
setActive,
|
||||
initNewActiveMessage,
|
||||
setMessageAtIndex,
|
||||
clearLastResponse,
|
||||
clearLastEmptyResponse,
|
||||
consumeMainEditorContent,
|
||||
setSelectedProfileId,
|
||||
deleteMessage,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue