mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-28 05:06:13 +01:00
🧹fix: Handle Abort Message Edge Cases (#1462)
* chore: bump langchain to v0.0.213 from v0.0.186 * fix: handle abort edge cases: - abort message server-side if response experienced error mid-generation - attempt to recover message if aborting resulted in error - if abortKey is not provided, use conversationId if it exists - if headers were already sent, send an Event stream message - issue warning for possible Google censor/filter refactor(streamResponse): for `sendError`, allow passing overrides so that error can include partial generation, improve typing for `sendMessage` * chore(MessageContent): remove eslint warning for unused `i`, rephrase unfinished message text * fix(useSSE): avoid invoking cancelHandler if the abort response was 404 * chore(TMessage): remove unnecessary, unused legacy message property `submitting` * chore(TMessage): remove unnecessary legacy message property `cancelled` * chore(abortMiddleware): remove unused `errorText` property to avoid confusion
This commit is contained in:
parent
f19f5dca8e
commit
379e470e38
19 changed files with 529 additions and 207 deletions
|
|
@ -35,7 +35,7 @@ const DisplayMessage = ({ text, isCreatedByUser, message, showCursor }: TDisplay
|
|||
return (
|
||||
<Container>
|
||||
{imageFiles &&
|
||||
imageFiles.map((file, i) => (
|
||||
imageFiles.map((file) => (
|
||||
<Image
|
||||
key={file.file_id}
|
||||
imagePath={file.preview ?? file.filepath ?? ''}
|
||||
|
|
@ -64,7 +64,7 @@ const DisplayMessage = ({ text, isCreatedByUser, message, showCursor }: TDisplay
|
|||
|
||||
// Unfinished Message Component
|
||||
const UnfinishedMessage = () => (
|
||||
<ErrorMessage text="This is an unfinished message. The AI may still be generating a response, it was aborted, or a censor was triggered. Refresh or visit later to see more updates." />
|
||||
<ErrorMessage text="The response is incomplete; it's either still processing, was cancelled, or censored. Refresh or try a different prompt." />
|
||||
);
|
||||
|
||||
// Content Component
|
||||
|
|
|
|||
|
|
@ -172,10 +172,6 @@ export default function ExportModal({ open, onOpenChange, conversation }) {
|
|||
fieldName: 'unfinished',
|
||||
fieldValues: entries.find((e) => e.fieldName == 'unfinished').fieldValues,
|
||||
},
|
||||
{
|
||||
fieldName: 'cancelled',
|
||||
fieldValues: entries.find((e) => e.fieldName == 'cancelled').fieldValues,
|
||||
},
|
||||
{
|
||||
fieldName: 'messageId',
|
||||
fieldValues: entries.find((e) => e.fieldName == 'messageId').fieldValues,
|
||||
|
|
@ -226,9 +222,6 @@ export default function ExportModal({ open, onOpenChange, conversation }) {
|
|||
if (message.unfinished) {
|
||||
data += '*(This is an unfinished message)*\n';
|
||||
}
|
||||
if (message.cancelled) {
|
||||
data += '*(This is a cancelled message)*\n';
|
||||
}
|
||||
data += '\n\n';
|
||||
}
|
||||
|
||||
|
|
@ -275,9 +268,6 @@ export default function ExportModal({ open, onOpenChange, conversation }) {
|
|||
if (message.unfinished) {
|
||||
data += '(This is an unfinished message)\n';
|
||||
}
|
||||
if (message.cancelled) {
|
||||
data += '(This is a cancelled message)\n';
|
||||
}
|
||||
data += '\n\n';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -217,7 +217,6 @@ export default function useChatHelpers(index = 0, paramId: string | undefined) {
|
|||
messageId: responseMessageId ?? `${isRegenerate ? messageId : fakeMessageId}_`,
|
||||
conversationId,
|
||||
unfinished: false,
|
||||
submitting: true,
|
||||
isCreatedByUser: false,
|
||||
isEdited: isEditOrContinue,
|
||||
error: false,
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
|||
messageId: message?.overrideParentMessageId + '_',
|
||||
plugin: plugin ?? null,
|
||||
plugins: plugins ?? [],
|
||||
submitting: true,
|
||||
// unfinished: true
|
||||
},
|
||||
]);
|
||||
|
|
@ -79,7 +78,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
|||
messageId: message?.messageId + '_',
|
||||
plugin: plugin ?? null,
|
||||
plugins: plugins ?? [],
|
||||
submitting: true,
|
||||
// unfinished: true
|
||||
},
|
||||
]);
|
||||
|
|
@ -136,7 +134,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
|||
...initialResponse,
|
||||
parentMessageId: message?.overrideParentMessageId ?? null,
|
||||
messageId: message?.overrideParentMessageId + '_',
|
||||
submitting: true,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
|
|
@ -147,7 +144,6 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
|||
...initialResponse,
|
||||
parentMessageId: message?.messageId,
|
||||
messageId: message?.messageId + '_',
|
||||
submitting: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
|
@ -238,6 +234,7 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
|||
const abortConversation = (conversationId = '', submission: TSubmission) => {
|
||||
console.log(submission);
|
||||
const { endpoint } = submission?.conversation || {};
|
||||
let res: Response;
|
||||
|
||||
fetch(`/api/ask/${endpoint}/abort`, {
|
||||
method: 'POST',
|
||||
|
|
@ -249,9 +246,15 @@ export default function useSSE(submission: TSubmission | null, index = 0) {
|
|||
abortKey: conversationId,
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((response) => {
|
||||
res = response;
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
console.log('aborted', data);
|
||||
if (res.status === 404) {
|
||||
return setIsSubmitting(false);
|
||||
}
|
||||
cancelHandler(data, submission);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue