Added latency tracking and display to the Playground component.
Browse files
src/lib/components/Playground/Playground.svelte
CHANGED
@@ -26,6 +26,7 @@
|
|
26 |
|
27 |
let loading = false;
|
28 |
let streamingMessage: Message | null = null;
|
|
|
29 |
|
30 |
function addMessage() {
|
31 |
messages = [
|
@@ -60,6 +61,7 @@
|
|
60 |
}
|
61 |
(document.activeElement as HTMLElement).blur();
|
62 |
loading = true;
|
|
|
63 |
|
64 |
try {
|
65 |
const hf = new HfInference(hfToken);
|
@@ -107,6 +109,8 @@
|
|
107 |
} catch (error) {
|
108 |
alert('error: ' + error.message);
|
109 |
} finally {
|
|
|
|
|
110 |
loading = false;
|
111 |
streamingMessage = null;
|
112 |
scrollToBottom();
|
@@ -172,7 +176,7 @@
|
|
172 |
>Reset</button
|
173 |
>
|
174 |
<div class="flex-1 items-center justify-center text-center text-sm text-gray-500">
|
175 |
-
23 tokens · Latency
|
176 |
</div>
|
177 |
<button
|
178 |
type="button"
|
|
|
26 |
|
27 |
let loading = false;
|
28 |
let streamingMessage: Message | null = null;
|
29 |
+
let latency = 0;
|
30 |
|
31 |
function addMessage() {
|
32 |
messages = [
|
|
|
61 |
}
|
62 |
(document.activeElement as HTMLElement).blur();
|
63 |
loading = true;
|
64 |
+
const startTime = performance.now();
|
65 |
|
66 |
try {
|
67 |
const hf = new HfInference(hfToken);
|
|
|
109 |
} catch (error) {
|
110 |
alert('error: ' + error.message);
|
111 |
} finally {
|
112 |
+
const endTime = performance.now();
|
113 |
+
latency = Math.round(endTime - startTime);
|
114 |
loading = false;
|
115 |
streamingMessage = null;
|
116 |
scrollToBottom();
|
|
|
176 |
>Reset</button
|
177 |
>
|
178 |
<div class="flex-1 items-center justify-center text-center text-sm text-gray-500">
|
179 |
+
23 tokens · Latency {latency}ms
|
180 |
</div>
|
181 |
<button
|
182 |
type="button"
|