Added automatic scrolling to bottom of message container when new messages are added.
Browse files
src/lib/components/Playground/Playground.svelte
CHANGED
@@ -84,6 +84,7 @@
|
|
84 |
out += chunk.choices[0].delta.content;
|
85 |
streamingMessage.content = out;
|
86 |
messages = [...messages];
|
|
|
87 |
}
|
88 |
}
|
89 |
}
|
@@ -99,6 +100,7 @@
|
|
99 |
if (response.choices && response.choices.length > 0) {
|
100 |
const newMessage = { role: 'assistant', content: response.choices[0].message.content };
|
101 |
messages = [...messages, newMessage];
|
|
|
102 |
}
|
103 |
}
|
104 |
} catch (error) {
|
@@ -106,10 +108,23 @@
|
|
106 |
} finally {
|
107 |
loading = false;
|
108 |
streamingMessage = null;
|
|
|
109 |
}
|
110 |
}
|
111 |
|
112 |
$: console.log(messages);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
</script>
|
114 |
|
115 |
<svelte:window on:keydown={onKeydown} />
|
|
|
84 |
out += chunk.choices[0].delta.content;
|
85 |
streamingMessage.content = out;
|
86 |
messages = [...messages];
|
87 |
+
scrollToBottom();
|
88 |
}
|
89 |
}
|
90 |
}
|
|
|
100 |
if (response.choices && response.choices.length > 0) {
|
101 |
const newMessage = { role: 'assistant', content: response.choices[0].message.content };
|
102 |
messages = [...messages, newMessage];
|
103 |
+
scrollToBottom();
|
104 |
}
|
105 |
}
|
106 |
} catch (error) {
|
|
|
108 |
} finally {
|
109 |
loading = false;
|
110 |
streamingMessage = null;
|
111 |
+
scrollToBottom();
|
112 |
}
|
113 |
}
|
114 |
|
115 |
$: console.log(messages);
|
116 |
+
|
117 |
+
function scrollToBottom() {
|
118 |
+
if (messageContainer) {
|
119 |
+
messageContainer.scrollTop = messageContainer.scrollHeight;
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
$: {
|
124 |
+
if (messages) {
|
125 |
+
scrollToBottom();
|
126 |
+
}
|
127 |
+
}
|
128 |
</script>
|
129 |
|
130 |
<svelte:window on:keydown={onKeydown} />
|