Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
ability to scroll when message is being generated
Browse files
src/lib/components/InferencePlayground/InferencePlaygroundConversation.svelte
CHANGED
|
@@ -12,6 +12,10 @@
|
|
| 12 |
export let viewCode: boolean;
|
| 13 |
export let hfToken: string;
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
const dispatch = createEventDispatcher<{
|
| 16 |
addMessage: void;
|
| 17 |
deleteMessage: number;
|
|
@@ -34,6 +38,7 @@
|
|
| 34 |
|
| 35 |
function scrollToBottom() {
|
| 36 |
if (messageContainer) {
|
|
|
|
| 37 |
messageContainer.scrollTop = messageContainer.scrollHeight;
|
| 38 |
}
|
| 39 |
}
|
|
@@ -41,22 +46,37 @@
|
|
| 41 |
$: {
|
| 42 |
if (conversation.messages.at(-1)) {
|
| 43 |
resizeMessageTextAreas();
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
</script>
|
| 48 |
|
| 49 |
<div
|
| 50 |
class="flex max-h-[calc(100dvh-5.8rem)] flex-col overflow-y-auto overflow-x-hidden @container"
|
| 51 |
-
class:pointer-events-none={loading}
|
| 52 |
class:animate-pulse={loading && !conversation.streaming}
|
| 53 |
bind:this={messageContainer}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
>
|
| 55 |
{#if !viewCode}
|
| 56 |
{#each conversation.messages as message, messageIdx}
|
| 57 |
<Message
|
| 58 |
class="border-b"
|
| 59 |
{message}
|
|
|
|
| 60 |
on:input={resizeMessageTextAreas}
|
| 61 |
on:delete={() => dispatch("deleteMessage", messageIdx)}
|
| 62 |
autofocus={!loading && messageIdx === conversation.messages.length - 1}
|
|
|
|
| 12 |
export let viewCode: boolean;
|
| 13 |
export let hfToken: string;
|
| 14 |
|
| 15 |
+
let shouldScrollToBottom = true;
|
| 16 |
+
let isProgrammaticScroll = true;
|
| 17 |
+
let conversationLength = conversation.messages.length;
|
| 18 |
+
|
| 19 |
const dispatch = createEventDispatcher<{
|
| 20 |
addMessage: void;
|
| 21 |
deleteMessage: number;
|
|
|
|
| 38 |
|
| 39 |
function scrollToBottom() {
|
| 40 |
if (messageContainer) {
|
| 41 |
+
isProgrammaticScroll = true;
|
| 42 |
messageContainer.scrollTop = messageContainer.scrollHeight;
|
| 43 |
}
|
| 44 |
}
|
|
|
|
| 46 |
$: {
|
| 47 |
if (conversation.messages.at(-1)) {
|
| 48 |
resizeMessageTextAreas();
|
| 49 |
+
if (shouldScrollToBottom) {
|
| 50 |
+
scrollToBottom();
|
| 51 |
+
}
|
| 52 |
}
|
| 53 |
}
|
| 54 |
+
|
| 55 |
+
$: if (conversation.messages.length !== conversationLength) {
|
| 56 |
+
// enable automatic scrolling when new message was added
|
| 57 |
+
conversationLength = conversation.messages.length;
|
| 58 |
+
shouldScrollToBottom = true;
|
| 59 |
+
}
|
| 60 |
</script>
|
| 61 |
|
| 62 |
<div
|
| 63 |
class="flex max-h-[calc(100dvh-5.8rem)] flex-col overflow-y-auto overflow-x-hidden @container"
|
|
|
|
| 64 |
class:animate-pulse={loading && !conversation.streaming}
|
| 65 |
bind:this={messageContainer}
|
| 66 |
+
on:scroll={() => {
|
| 67 |
+
// disable automatic scrolling is user initiates scroll
|
| 68 |
+
if (!isProgrammaticScroll) {
|
| 69 |
+
shouldScrollToBottom = false;
|
| 70 |
+
}
|
| 71 |
+
isProgrammaticScroll = false;
|
| 72 |
+
}}
|
| 73 |
>
|
| 74 |
{#if !viewCode}
|
| 75 |
{#each conversation.messages as message, messageIdx}
|
| 76 |
<Message
|
| 77 |
class="border-b"
|
| 78 |
{message}
|
| 79 |
+
{loading}
|
| 80 |
on:input={resizeMessageTextAreas}
|
| 81 |
on:delete={() => dispatch("deleteMessage", messageIdx)}
|
| 82 |
autofocus={!loading && messageIdx === conversation.messages.length - 1}
|
src/lib/components/InferencePlayground/InferencePlaygroundMessage.svelte
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
import { createEventDispatcher } from "svelte";
|
| 4 |
|
| 5 |
export let message: ChatCompletionInputMessage;
|
|
|
|
| 6 |
export let autofocus: boolean = false;
|
| 7 |
|
| 8 |
const dispatch = createEventDispatcher<{ delete: void; input: void }>();
|
|
@@ -10,6 +11,7 @@
|
|
| 10 |
|
| 11 |
<div
|
| 12 |
class="group/message group grid grid-cols-[1fr,2.5rem] items-start gap-2 px-3.5 pb-6 pt-4 hover:bg-gray-100/70 @2xl:grid-cols-[130px,1fr,2.5rem] @2xl:grid-rows-1 @2xl:gap-4 @2xl:px-6 dark:border-gray-800 dark:hover:bg-gray-800/30 {$$props.class}"
|
|
|
|
| 13 |
>
|
| 14 |
<div class="col-span-2 pb-1 pt-3 text-sm font-semibold uppercase @2xl:col-span-1 @2xl:pb-2">
|
| 15 |
{message.role}
|
|
|
|
| 3 |
import { createEventDispatcher } from "svelte";
|
| 4 |
|
| 5 |
export let message: ChatCompletionInputMessage;
|
| 6 |
+
export let loading: boolean = false;
|
| 7 |
export let autofocus: boolean = false;
|
| 8 |
|
| 9 |
const dispatch = createEventDispatcher<{ delete: void; input: void }>();
|
|
|
|
| 11 |
|
| 12 |
<div
|
| 13 |
class="group/message group grid grid-cols-[1fr,2.5rem] items-start gap-2 px-3.5 pb-6 pt-4 hover:bg-gray-100/70 @2xl:grid-cols-[130px,1fr,2.5rem] @2xl:grid-rows-1 @2xl:gap-4 @2xl:px-6 dark:border-gray-800 dark:hover:bg-gray-800/30 {$$props.class}"
|
| 14 |
+
class:pointer-events-none={loading}
|
| 15 |
>
|
| 16 |
<div class="col-span-2 pb-1 pt-3 text-sm font-semibold uppercase @2xl:col-span-1 @2xl:pb-2">
|
| 17 |
{message.role}
|