mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 00:46:42 +08:00
Fix: regenerate chat message does not truncate history (#17087)
This commit is contained in:
@@ -26,7 +26,6 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { useTranslate } from './common-hooks';
|
||||
import { useSetPaginationParams } from './route-hook';
|
||||
import { useSaveSetting } from './use-user-setting-request';
|
||||
@@ -714,12 +713,14 @@ export const useRegenerateMessage = ({
|
||||
if (message.id) {
|
||||
removeMessagesAfterCurrentMessage(message.id);
|
||||
const index = messages.findIndex((x) => x.id === message.id);
|
||||
let nextMessages;
|
||||
if (index !== -1) {
|
||||
nextMessages = messages.slice(0, index);
|
||||
}
|
||||
// Always pass the truncated history explicitly, even when it is
|
||||
// empty (regenerating the first question), so the backend can
|
||||
// overwrite the session with it via pass_all_history_messages.
|
||||
const nextMessages = index !== -1 ? messages.slice(0, index) : [];
|
||||
sendMessage({
|
||||
message: { ...message, id: uuid() },
|
||||
// Keep the original id so the question/answer pair id stays
|
||||
// consistent between local state and the persisted session.
|
||||
message: { ...message },
|
||||
messages: nextMessages,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,10 +102,10 @@ export const useSendMessage = (controller: AbortController) => {
|
||||
{
|
||||
chat_id: chatId,
|
||||
session_id: sessionId,
|
||||
// An explicitly provided list is authoritative, even when empty
|
||||
// (e.g. regenerating the first question must truncate history).
|
||||
messages: [
|
||||
...(Array.isArray(messages) && messages?.length > 0
|
||||
? messages
|
||||
: (derivedMessages ?? [])),
|
||||
...(Array.isArray(messages) ? messages : (derivedMessages ?? [])),
|
||||
message,
|
||||
],
|
||||
pass_all_history_messages: true,
|
||||
@@ -171,7 +171,9 @@ export const useSendMessage = (controller: AbortController) => {
|
||||
setValue('');
|
||||
sendMessage({
|
||||
currentConversationId: targetConversationId,
|
||||
messages: currentMessages,
|
||||
// For an existing conversation currentMessages is empty; fall back
|
||||
// to derivedMessages instead of sending an empty history.
|
||||
messages: currentMessages.length > 0 ? currentMessages : undefined,
|
||||
message: {
|
||||
id,
|
||||
content: value.trim(),
|
||||
|
||||
Reference in New Issue
Block a user