mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-13 04:45:19 +00:00
Merge pull request #16061 from silentoplayz/fix/autoscrolling-in-FloatingButtons
fix: prevent error when autoscrolling in FloatingButtons
This commit is contained in:
commit
47d86d3c2f
1 changed files with 34 additions and 11 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
|
|
||||||
import { getContext, tick } from 'svelte';
|
import { getContext, tick, onDestroy } from 'svelte';
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
import { chatCompletion } from '$lib/apis/openai';
|
import { chatCompletion } from '$lib/apis/openai';
|
||||||
|
|
@ -27,15 +27,18 @@
|
||||||
let prompt = '';
|
let prompt = '';
|
||||||
let responseContent = null;
|
let responseContent = null;
|
||||||
let responseDone = false;
|
let responseDone = false;
|
||||||
|
let controller = null;
|
||||||
|
|
||||||
const autoScroll = async () => {
|
const autoScroll = async () => {
|
||||||
// Scroll to bottom only if the scroll is at the bottom give 50px buffer
|
|
||||||
const responseContainer = document.getElementById('response-container');
|
const responseContainer = document.getElementById('response-container');
|
||||||
if (
|
if (responseContainer) {
|
||||||
responseContainer.scrollHeight - responseContainer.clientHeight <=
|
// Scroll to bottom only if the scroll is at the bottom give 50px buffer
|
||||||
responseContainer.scrollTop + 50
|
if (
|
||||||
) {
|
responseContainer.scrollHeight - responseContainer.clientHeight <=
|
||||||
responseContainer.scrollTop = responseContainer.scrollHeight;
|
responseContainer.scrollTop + 50
|
||||||
|
) {
|
||||||
|
responseContainer.scrollTop = responseContainer.scrollHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -54,7 +57,8 @@
|
||||||
floatingInputValue = '';
|
floatingInputValue = '';
|
||||||
|
|
||||||
responseContent = '';
|
responseContent = '';
|
||||||
const [res, controller] = await chatCompletion(localStorage.token, {
|
let res;
|
||||||
|
[res, controller] = await chatCompletion(localStorage.token, {
|
||||||
model: model,
|
model: model,
|
||||||
messages: [
|
messages: [
|
||||||
...messages,
|
...messages,
|
||||||
|
|
@ -116,7 +120,13 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// Process the stream in the background
|
// Process the stream in the background
|
||||||
await processStream();
|
try {
|
||||||
|
await processStream();
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name !== 'AbortError') {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error('An error occurred while fetching the explanation');
|
toast.error('An error occurred while fetching the explanation');
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +144,8 @@
|
||||||
prompt = `${quotedText}\n\nExplain`;
|
prompt = `${quotedText}\n\nExplain`;
|
||||||
|
|
||||||
responseContent = '';
|
responseContent = '';
|
||||||
const [res, controller] = await chatCompletion(localStorage.token, {
|
let res;
|
||||||
|
[res, controller] = await chatCompletion(localStorage.token, {
|
||||||
model: model,
|
model: model,
|
||||||
messages: [
|
messages: [
|
||||||
...messages,
|
...messages,
|
||||||
|
|
@ -196,7 +207,13 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// Process the stream in the background
|
// Process the stream in the background
|
||||||
await processStream();
|
try {
|
||||||
|
await processStream();
|
||||||
|
} catch (e) {
|
||||||
|
if (e.name !== 'AbortError') {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error('An error occurred while fetching the explanation');
|
toast.error('An error occurred while fetching the explanation');
|
||||||
}
|
}
|
||||||
|
|
@ -227,6 +244,12 @@
|
||||||
floatingInput = false;
|
floatingInput = false;
|
||||||
floatingInputValue = '';
|
floatingInputValue = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (controller) {
|
||||||
|
controller.abort();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue