mirror of
https://github.com/open-webui/open-webui.git
synced 2026-04-30 01:10:17 -05:00
refac
Co-Authored-By: Algorithm5838 <108630393+Algorithm5838@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
import { replaceTokens, processResponseContent } from '$lib/utils';
|
import { replaceTokens, processResponseContent } from '$lib/utils';
|
||||||
import { user } from '$lib/stores';
|
import { user } from '$lib/stores';
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
export let onTaskClick = () => {};
|
export let onTaskClick = () => {};
|
||||||
|
|
||||||
let tokens = [];
|
let tokens = [];
|
||||||
|
let pendingUpdate = null;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
@@ -53,13 +55,29 @@
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
$: (async () => {
|
const parseTokens = () => {
|
||||||
if (content) {
|
tokens = marked.lexer(
|
||||||
tokens = marked.lexer(
|
replaceTokens(processResponseContent(content), model?.name, $user?.name)
|
||||||
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>
|
</script>
|
||||||
|
|
||||||
{#key id}
|
{#key id}
|
||||||
|
|||||||
Reference in New Issue
Block a user