mirror of
https://github.com/open-webui/open-webui
synced 2024-11-28 15:05:07 +00:00
refac
This commit is contained in:
parent
6aefc79807
commit
6e5b557a1f
@ -2,8 +2,6 @@
|
|||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
import tippy from 'tippy.js';
|
|
||||||
import auto_render from 'katex/dist/contrib/auto-render.mjs';
|
|
||||||
import mermaid from 'mermaid';
|
import mermaid from 'mermaid';
|
||||||
|
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
@ -81,6 +79,7 @@
|
|||||||
import 'katex/dist/katex.min.css';
|
import 'katex/dist/katex.min.css';
|
||||||
|
|
||||||
import markedKatex from '$lib/utils/katex-extension';
|
import markedKatex from '$lib/utils/katex-extension';
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
throwOnError: false
|
throwOnError: false
|
||||||
};
|
};
|
||||||
@ -95,37 +94,6 @@
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
$: if (message?.done ?? false) {
|
|
||||||
renderLatex();
|
|
||||||
}
|
|
||||||
|
|
||||||
const renderLatex = () => {
|
|
||||||
let chatMessageElements = document
|
|
||||||
.getElementById(`message-${message.id}`)
|
|
||||||
?.getElementsByClassName('chat-assistant');
|
|
||||||
|
|
||||||
if (chatMessageElements) {
|
|
||||||
for (const element of chatMessageElements) {
|
|
||||||
auto_render(element, {
|
|
||||||
// customised options
|
|
||||||
// • auto-render specific keys, e.g.:
|
|
||||||
delimiters: [
|
|
||||||
{ left: '$$', right: '$$', display: false },
|
|
||||||
{ left: '$ ', right: ' $', display: false },
|
|
||||||
{ left: '\\pu{', right: '}', display: false },
|
|
||||||
{ left: '\\ce{', right: '}', display: false },
|
|
||||||
{ left: '\\(', right: '\\)', display: false },
|
|
||||||
{ left: '( ', right: ' )', display: false },
|
|
||||||
{ left: '\\[', right: '\\]', display: false },
|
|
||||||
{ left: '[ ', right: ' ]', display: false }
|
|
||||||
],
|
|
||||||
// • rendering keys, e.g.:
|
|
||||||
throwOnError: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const playAudio = (idx) => {
|
const playAudio = (idx) => {
|
||||||
return new Promise((res) => {
|
return new Promise((res) => {
|
||||||
speakingIdx = idx;
|
speakingIdx = idx;
|
||||||
@ -191,7 +159,7 @@
|
|||||||
const res = await synthesizeOpenAISpeech(
|
const res = await synthesizeOpenAISpeech(
|
||||||
localStorage.token,
|
localStorage.token,
|
||||||
$settings?.audio?.tts?.defaultVoice === $config.audio.tts.voice
|
$settings?.audio?.tts?.defaultVoice === $config.audio.tts.voice
|
||||||
? ($settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice)
|
? $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice
|
||||||
: $config?.audio?.tts?.voice,
|
: $config?.audio?.tts?.voice,
|
||||||
sentence
|
sentence
|
||||||
).catch((error) => {
|
).catch((error) => {
|
||||||
@ -279,14 +247,12 @@
|
|||||||
editedContent = '';
|
editedContent = '';
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
renderLatex();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const cancelEditMessage = async () => {
|
const cancelEditMessage = async () => {
|
||||||
edit = false;
|
edit = false;
|
||||||
editedContent = '';
|
editedContent = '';
|
||||||
await tick();
|
await tick();
|
||||||
renderLatex();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateImage = async (message) => {
|
const generateImage = async (message) => {
|
||||||
@ -311,7 +277,6 @@
|
|||||||
$: if (!edit) {
|
$: if (!edit) {
|
||||||
(async () => {
|
(async () => {
|
||||||
await tick();
|
await tick();
|
||||||
renderLatex();
|
|
||||||
|
|
||||||
await mermaid.run({
|
await mermaid.run({
|
||||||
querySelector: '.mermaid'
|
querySelector: '.mermaid'
|
||||||
@ -321,8 +286,6 @@
|
|||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await tick();
|
await tick();
|
||||||
renderLatex();
|
|
||||||
|
|
||||||
await mermaid.run({
|
await mermaid.run({
|
||||||
querySelector: '.mermaid'
|
querySelector: '.mermaid'
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user