Spaces:
Running
Running
Commit
•
fb60bd2
1
Parent(s):
bf465c4
add tok/s badge
Browse files- src/routes/+page.svelte +13 -3
src/routes/+page.svelte
CHANGED
@@ -11,6 +11,7 @@
|
|
11 |
let outputText = '';
|
12 |
let error = '';
|
13 |
let completionSpeed: number | null = null;
|
|
|
14 |
let selectedModel = "SmolLM-360M-Instruct-q4f16_1-MLC";
|
15 |
let isGenerating = false;
|
16 |
|
@@ -49,13 +50,19 @@
|
|
49 |
isGenerating = true;
|
50 |
const startTime = performance.now();
|
51 |
try {
|
52 |
-
const
|
53 |
messages: [{role:"system",content: "You are a helpful AI agent helping users. Try your best to answer the users request.",},{ role: "user", content: inputText }],
|
54 |
max_tokens: 10,
|
55 |
});
|
56 |
|
57 |
-
outputText =
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
error = '';
|
60 |
} catch (err) {
|
61 |
error = `Error: ${(err as Error).message}`;
|
@@ -91,6 +98,9 @@
|
|
91 |
{#if completionSpeed !== null}
|
92 |
<Badge>{completionSpeed}ms</Badge>
|
93 |
{/if}
|
|
|
|
|
|
|
94 |
<Badge class="bg-green-700">{selectedModel}</Badge>
|
95 |
</div>
|
96 |
{/if}
|
|
|
11 |
let outputText = '';
|
12 |
let error = '';
|
13 |
let completionSpeed: number | null = null;
|
14 |
+
let tokensPerSecond: number | null = null;
|
15 |
let selectedModel = "SmolLM-360M-Instruct-q4f16_1-MLC";
|
16 |
let isGenerating = false;
|
17 |
|
|
|
50 |
isGenerating = true;
|
51 |
const startTime = performance.now();
|
52 |
try {
|
53 |
+
const response = await engine.chat.completions.create({
|
54 |
messages: [{role:"system",content: "You are a helpful AI agent helping users. Try your best to answer the users request.",},{ role: "user", content: inputText }],
|
55 |
max_tokens: 10,
|
56 |
});
|
57 |
|
58 |
+
outputText = response.choices[0].message.content || "";
|
59 |
+
const endTime = performance.now();
|
60 |
+
const elapsedTimeInSeconds = (endTime - startTime) / 1000;
|
61 |
+
completionSpeed = Math.round(endTime - startTime);
|
62 |
+
|
63 |
+
const generatedTokens = response.usage?.completion_tokens || 0;
|
64 |
+
tokensPerSecond = Math.round(generatedTokens / elapsedTimeInSeconds);
|
65 |
+
|
66 |
error = '';
|
67 |
} catch (err) {
|
68 |
error = `Error: ${(err as Error).message}`;
|
|
|
98 |
{#if completionSpeed !== null}
|
99 |
<Badge>{completionSpeed}ms</Badge>
|
100 |
{/if}
|
101 |
+
{#if tokensPerSecond !== null}
|
102 |
+
<Badge>{tokensPerSecond} tok/s</Badge>
|
103 |
+
{/if}
|
104 |
<Badge class="bg-green-700">{selectedModel}</Badge>
|
105 |
</div>
|
106 |
{/if}
|