mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-11 03:38:02 +00:00
fix: a reply rewritten by an action button still shows its old text (#32172)
Pressing an action button whose function rewrites the reply, as the action docs describe, stored the new text with the chat but the chat kept showing the old reply, right away and after a reload. The reply now shows the new text, and its thinking and tool call sections stay visible. The action gets the reply as one text, so when the reply had text both before and after a tool call, all of it is replaced by the new text, shown after the tool calls. Fixes #32023
This commit is contained in:
parent
1579af28a0
commit
200036f6a6
2 changed files with 28 additions and 1 deletions
|
|
@ -71,7 +71,11 @@
|
|||
import { AudioQueue } from '$lib/utils/audio';
|
||||
import { RealtimeCall, getBridgeTurnState, type BridgeSubmission } from '$lib/utils/realtime';
|
||||
import { createTemporaryChatId, isTemporaryChatId } from '$lib/utils/chatId';
|
||||
import { applyResponseStreamEvent, getOutputText } from './Messages/structuredOutput';
|
||||
import {
|
||||
applyResponseStreamEvent,
|
||||
getOutputText,
|
||||
setOutputText
|
||||
} from './Messages/structuredOutput';
|
||||
|
||||
import {
|
||||
archiveChatById,
|
||||
|
|
@ -2999,6 +3003,9 @@
|
|||
...(history.messages[message.id].content !== message.content
|
||||
? { originalContent: history.messages[message.id].content }
|
||||
: {}),
|
||||
...(typeof message.content === 'string' && history.messages[message.id].output?.length
|
||||
? { output: setOutputText(history.messages[message.id].output, message.content) }
|
||||
: {}),
|
||||
...message
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -710,3 +710,23 @@ export function replaceOutputMessageText(
|
|||
|
||||
return replaced ? nextOutput : output;
|
||||
}
|
||||
|
||||
export function setOutputText(output: OutputItem[], text: string): OutputItem[] {
|
||||
if (text === getOutputText(output)) {
|
||||
return output;
|
||||
}
|
||||
|
||||
const lastMessage = output.filter((item) => item?.type === 'message').at(-1);
|
||||
if (!lastMessage) {
|
||||
return [
|
||||
...output,
|
||||
{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text }] }
|
||||
];
|
||||
}
|
||||
|
||||
return output.map((item) =>
|
||||
item?.type === 'message'
|
||||
? { ...item, content: item === lastMessage ? [{ type: 'output_text', text }] : [] }
|
||||
: item
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue