mirror of
https://github.com/open-webui/open-webui
synced 2025-01-01 08:42:14 +00:00
refac
This commit is contained in:
parent
e39617b1c0
commit
d93107d1d6
@ -43,7 +43,8 @@
|
|||||||
getMessageContentParts,
|
getMessageContentParts,
|
||||||
extractSentencesForAudio,
|
extractSentencesForAudio,
|
||||||
promptTemplate,
|
promptTemplate,
|
||||||
splitStream
|
splitStream,
|
||||||
|
sleep
|
||||||
} from '$lib/utils';
|
} from '$lib/utils';
|
||||||
|
|
||||||
import { generateChatCompletion } from '$lib/apis/ollama';
|
import { generateChatCompletion } from '$lib/apis/ollama';
|
||||||
@ -1063,11 +1064,33 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (choices) {
|
if (choices) {
|
||||||
const value = choices[0]?.delta?.content ?? '';
|
let value = choices[0]?.delta?.content ?? '';
|
||||||
if (message.content == '' && value == '\n') {
|
if (message.content == '' && value == '\n') {
|
||||||
console.log('Empty response');
|
console.log('Empty response');
|
||||||
} else {
|
} else {
|
||||||
|
if ($settings?.splitLargeDeltas ?? false) {
|
||||||
|
if (value.length < 5) {
|
||||||
message.content += value;
|
message.content += value;
|
||||||
|
} else {
|
||||||
|
while (value != '') {
|
||||||
|
const chunkSize = Math.min(Math.floor(Math.random() * 3) + 1, value.length);
|
||||||
|
const chunk = value.slice(0, chunkSize);
|
||||||
|
|
||||||
|
message.content += chunk;
|
||||||
|
history.messages[message.id] = message;
|
||||||
|
|
||||||
|
// Do not sleep if the tab is hidden
|
||||||
|
// Timers are throttled to 1s in hidden tabs
|
||||||
|
if (document?.visibilityState !== 'hidden') {
|
||||||
|
await sleep(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = value.slice(chunkSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message.content += value;
|
||||||
|
}
|
||||||
|
|
||||||
if (navigator.vibrate && ($settings?.hapticFeedback ?? false)) {
|
if (navigator.vibrate && ($settings?.hapticFeedback ?? false)) {
|
||||||
navigator.vibrate(5);
|
navigator.vibrate(5);
|
||||||
@ -1079,6 +1102,7 @@
|
|||||||
$config?.audio?.tts?.split_on ?? 'punctuation'
|
$config?.audio?.tts?.split_on ?? 'punctuation'
|
||||||
);
|
);
|
||||||
messageContentParts.pop();
|
messageContentParts.pop();
|
||||||
|
|
||||||
// dispatch only last sentence and make sure it hasn't been dispatched before
|
// dispatch only last sentence and make sure it hasn't been dispatched before
|
||||||
if (
|
if (
|
||||||
messageContentParts.length > 0 &&
|
messageContentParts.length > 0 &&
|
||||||
|
@ -8,6 +8,9 @@ import { TTS_RESPONSE_SPLIT } from '$lib/types';
|
|||||||
// Helper functions
|
// Helper functions
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
|
|
||||||
|
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
|
||||||
function escapeRegExp(string: string): string {
|
function escapeRegExp(string: string): string {
|
||||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user