mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
refac
Co-Authored-By: Algorithm5838 <108630393+Algorithm5838@users.noreply.github.com>
This commit is contained in:
parent
acb2147024
commit
484ba91b07
1 changed files with 24 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
|||
<script>
|
||||
import { onDestroy } from 'svelte';
|
||||
import { marked } from 'marked';
|
||||
import { replaceTokens, processResponseContent } from '$lib/utils';
|
||||
import { user } from '$lib/stores';
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
export let onTaskClick = () => {};
|
||||
|
||||
let tokens = [];
|
||||
let pendingUpdate = null;
|
||||
|
||||
const options = {
|
||||
throwOnError: false,
|
||||
|
|
@ -53,13 +55,29 @@
|
|||
]
|
||||
});
|
||||
|
||||
$: (async () => {
|
||||
if (content) {
|
||||
tokens = marked.lexer(
|
||||
replaceTokens(processResponseContent(content), model?.name, $user?.name)
|
||||
);
|
||||
const parseTokens = () => {
|
||||
tokens = marked.lexer(
|
||||
replaceTokens(processResponseContent(content), model?.name, $user?.name)
|
||||
);
|
||||
};
|
||||
|
||||
// Throttle parsing to once per animation frame while streaming
|
||||
$: if (content) {
|
||||
if (done) {
|
||||
cancelAnimationFrame(pendingUpdate);
|
||||
pendingUpdate = null;
|
||||
parseTokens();
|
||||
} else if (!pendingUpdate) {
|
||||
pendingUpdate = requestAnimationFrame(() => {
|
||||
pendingUpdate = null;
|
||||
parseTokens();
|
||||
});
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
cancelAnimationFrame(pendingUpdate);
|
||||
});
|
||||
</script>
|
||||
|
||||
{#key id}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue