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
6524cae407
commit
8cc834901f
@ -28,6 +28,17 @@
|
|||||||
let responseContent = null;
|
let responseContent = null;
|
||||||
let responseDone = false;
|
let responseDone = false;
|
||||||
|
|
||||||
|
const autoScroll = async () => {
|
||||||
|
// Scroll to bottom only if the scroll is at the bottom give 50px buffer
|
||||||
|
const responseContainer = document.getElementById('response-container');
|
||||||
|
if (
|
||||||
|
responseContainer.scrollHeight - responseContainer.clientHeight <=
|
||||||
|
responseContainer.scrollTop + 50
|
||||||
|
) {
|
||||||
|
responseContainer.scrollTop = responseContainer.scrollHeight;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const askHandler = async () => {
|
const askHandler = async () => {
|
||||||
if (!model) {
|
if (!model) {
|
||||||
toast.error('Model not selected');
|
toast.error('Model not selected');
|
||||||
@ -71,6 +82,9 @@
|
|||||||
if (line.startsWith('data: ')) {
|
if (line.startsWith('data: ')) {
|
||||||
if (line.startsWith('data: [DONE]')) {
|
if (line.startsWith('data: [DONE]')) {
|
||||||
responseDone = true;
|
responseDone = true;
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
autoScroll();
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// Parse the JSON chunk
|
// Parse the JSON chunk
|
||||||
@ -81,14 +95,7 @@
|
|||||||
if (data.choices && data.choices[0]?.delta?.content) {
|
if (data.choices && data.choices[0]?.delta?.content) {
|
||||||
responseContent += data.choices[0].delta.content;
|
responseContent += data.choices[0].delta.content;
|
||||||
|
|
||||||
// Scroll to bottom only if the scroll is at the bottom give 50px buffer
|
autoScroll();
|
||||||
const responseContainer = document.getElementById('response-container');
|
|
||||||
if (
|
|
||||||
responseContainer.scrollHeight - responseContainer.clientHeight <=
|
|
||||||
responseContainer.scrollTop + 50
|
|
||||||
) {
|
|
||||||
responseContainer.scrollTop = responseContainer.scrollHeight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -148,6 +155,9 @@
|
|||||||
if (line.startsWith('data: ')) {
|
if (line.startsWith('data: ')) {
|
||||||
if (line.startsWith('data: [DONE]')) {
|
if (line.startsWith('data: [DONE]')) {
|
||||||
responseDone = true;
|
responseDone = true;
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
autoScroll();
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// Parse the JSON chunk
|
// Parse the JSON chunk
|
||||||
@ -158,14 +168,7 @@
|
|||||||
if (data.choices && data.choices[0]?.delta?.content) {
|
if (data.choices && data.choices[0]?.delta?.content) {
|
||||||
responseContent += data.choices[0].delta.content;
|
responseContent += data.choices[0].delta.content;
|
||||||
|
|
||||||
// Scroll to bottom
|
autoScroll();
|
||||||
const responseContainer = document.getElementById('response-container');
|
|
||||||
if (
|
|
||||||
responseContainer.scrollHeight - responseContainer.clientHeight <=
|
|
||||||
responseContainer.scrollTop + 50
|
|
||||||
) {
|
|
||||||
responseContainer.scrollTop = responseContainer.scrollHeight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user