mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
refac
This commit is contained in:
parent
ef455fcef9
commit
495296346e
1 changed files with 27 additions and 20 deletions
|
|
@ -1896,31 +1896,38 @@
|
|||
return;
|
||||
}
|
||||
|
||||
const ttsSplitOn = $config?.audio?.tts?.split_on ?? 'punctuation';
|
||||
const messageContentParts = getMessageContentParts(
|
||||
getOutputText(message?.output) || removeAllDetails(message?.content ?? ''),
|
||||
$config?.audio?.tts?.split_on ?? 'punctuation'
|
||||
ttsSplitOn
|
||||
);
|
||||
if (!final) {
|
||||
messageContentParts.pop();
|
||||
}
|
||||
|
||||
const nextContentPart = messageContentParts.at(-1) ?? '';
|
||||
if (!nextContentPart || (!final && nextContentPart === message.lastSentence)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!final) {
|
||||
message.lastSentence = nextContentPart;
|
||||
}
|
||||
|
||||
eventTarget.dispatchEvent(
|
||||
new CustomEvent('chat', {
|
||||
detail: {
|
||||
id: message.id,
|
||||
content: nextContentPart
|
||||
}
|
||||
})
|
||||
const sentContentPartCount = message.ttsSentContentPartCount ?? 0;
|
||||
const nextContentParts = (final ? messageContentParts : messageContentParts.slice(0, -1)).slice(
|
||||
sentContentPartCount
|
||||
);
|
||||
const pendingContentPartIndex = nextContentParts.findIndex(
|
||||
(content) =>
|
||||
!final &&
|
||||
ttsSplitOn === 'punctuation' &&
|
||||
(content.split(/\s+/).length < 4 || content.length < 50)
|
||||
);
|
||||
const dispatchContentParts =
|
||||
pendingContentPartIndex === -1
|
||||
? nextContentParts
|
||||
: nextContentParts.slice(0, pendingContentPartIndex);
|
||||
|
||||
dispatchContentParts.forEach((content) => {
|
||||
eventTarget.dispatchEvent(
|
||||
new CustomEvent('chat', {
|
||||
detail: {
|
||||
id: message.id,
|
||||
content
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
message.ttsSentContentPartCount = sentContentPartCount + dispatchContentParts.length;
|
||||
};
|
||||
|
||||
const getContents = () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue