cfahlgren1 HF staff commited on
Commit
75ad4be
·
1 Parent(s): 734c928

add slider for max tokens

Browse files
Files changed (1) hide show
  1. src/routes/+page.svelte +20 -12
src/routes/+page.svelte CHANGED
@@ -2,7 +2,7 @@
2
  import Textarea from "@/lib/components/ui/textarea/textarea.svelte";
3
  import Badge from "@/lib/components/ui/badge/badge.svelte";
4
  import * as webllm from "@mlc-ai/web-llm";
5
- import { onMount, tick } from 'svelte';
6
 
7
  let selectedModel = "smollm-360M-instruct-add-basics-q0f32-MLC";
8
 
@@ -16,6 +16,7 @@
16
  let tokensPerSecond: number | null = null;
17
  let isGenerating = false;
18
  let pendingRequest: string | null = null;
 
19
 
20
  const promptExamples = [
21
  "Tell me a story about a cat.",
@@ -81,21 +82,15 @@
81
  isGenerating = true;
82
  const startTime = performance.now();
83
  try {
84
- console.log("Generating completion:", content);
85
  const response = await engine.chat.completions.create({
86
  messages: [
87
  {role: "user", content: content}
88
  ],
89
- max_tokens: 15,
90
  });
91
 
92
  outputText = response.choices[0].message.content || "";
93
 
94
- // indicate that the response was cut short if it doesn't end with a period
95
- if (response.choices[0].finish_reason === "length" && outputText[outputText.length - 1] !== ".") {
96
- outputText += "...";
97
- }
98
-
99
  const endTime = performance.now();
100
  const elapsedTimeInSeconds = (endTime - startTime) / 1000;
101
  completionSpeed = Math.round(endTime - startTime);
@@ -122,14 +117,15 @@
122
  </script>
123
 
124
 
125
- <div class="flex my-12 flex-col items-center gap-6 max-w-xl mx-auto relative">
126
  <img
127
  src="logo_smollm.png"
128
  alt="logo"
129
  class="absolute top-0 right-0 w-28 h-28 object-contain -mt-8 -mr-8 lg:-mr-16"
130
  />
131
- <h1 class="text-center font-sans font-bold text-5xl text-gray-800 mb-2">SmolLM Playground</h1>
132
- <p class="text-center font-sans text-sm text-gray-600 mb-4">Powered by <a href="https://huggingface.co/mlc-ai" target="_blank" class="underline text-gray-800">MLC</a> WebLLM <a class="underline text-gray-800" href="https://huggingface.co/HuggingFaceTB/smollm-360M-instruct-add-basics" target="_blank">SmolLM-360M-Instruct-Add-Basics</a> <span class="text-xs italic">(15 Max Tokens)</span></p>
 
133
 
134
  <Textarea
135
  bind:value={inputText}
@@ -138,7 +134,7 @@
138
  class="w-full text-lg"
139
  placeholder="Say something..."
140
  />
141
- <p class="text-center font-sans text-xs text-gray-600 mb-4 italic">This is a smol model, go easy on it. Check out <a href="https://huggingface.co/spaces/HuggingFaceTB/SmolLM-360M-Instruct-WebGPU" target="_blank" class="underline text-gray-800">this demo</a> for full conversations.</p>
142
  {#if isLoading}
143
  <p class="text-sm text-slate-600 text-center">{loadingStatus}</p>
144
  {:else if error}
@@ -153,6 +149,18 @@
153
  {/if}
154
  </div>
155
  {/if}
 
 
 
 
 
 
 
 
 
 
 
 
156
  <div class="flex flex-col items-center mb-4">
157
  {#if inputText === '' && !isLoading}
158
  <p class="text-sm mb-2">Try these examples:</p>
 
2
  import Textarea from "@/lib/components/ui/textarea/textarea.svelte";
3
  import Badge from "@/lib/components/ui/badge/badge.svelte";
4
  import * as webllm from "@mlc-ai/web-llm";
5
+ import { onMount } from 'svelte';
6
 
7
  let selectedModel = "smollm-360M-instruct-add-basics-q0f32-MLC";
8
 
 
16
  let tokensPerSecond: number | null = null;
17
  let isGenerating = false;
18
  let pendingRequest: string | null = null;
19
+ let maxTokens = 15;
20
 
21
  const promptExamples = [
22
  "Tell me a story about a cat.",
 
82
  isGenerating = true;
83
  const startTime = performance.now();
84
  try {
 
85
  const response = await engine.chat.completions.create({
86
  messages: [
87
  {role: "user", content: content}
88
  ],
89
+ max_tokens: maxTokens,
90
  });
91
 
92
  outputText = response.choices[0].message.content || "";
93
 
 
 
 
 
 
94
  const endTime = performance.now();
95
  const elapsedTimeInSeconds = (endTime - startTime) / 1000;
96
  completionSpeed = Math.round(endTime - startTime);
 
117
  </script>
118
 
119
 
120
+ <div class="flex my-12 flex-col items-center gap-6 max-w-xl mx-auto relative font-sans">
121
  <img
122
  src="logo_smollm.png"
123
  alt="logo"
124
  class="absolute top-0 right-0 w-28 h-28 object-contain -mt-8 -mr-8 lg:-mr-16"
125
  />
126
+ <h1 class="text-center font-bold text-5xl text-gray-800 mb-2">SmolLM Playground</h1>
127
+ <p class="text-center text-sm text-gray-600">Powered by <a href="https://huggingface.co/mlc-ai" target="_blank" class="underline text-gray-800">MLC</a> WebLLM <a class="underline text-gray-800" href="https://huggingface.co/HuggingFaceTB/smollm-360M-instruct-add-basics" target="_blank">SmolLM-360M-Instruct-Add-Basics</a></p>
128
+ <p class="text-center text-xs text-gray-600 mb-4 italic">This is a smol model, go easy on it. Check out <a href="https://huggingface.co/spaces/HuggingFaceTB/SmolLM-360M-Instruct-WebGPU" target="_blank" class="underline text-gray-800">this demo</a> for full conversations.</p>
129
 
130
  <Textarea
131
  bind:value={inputText}
 
134
  class="w-full text-lg"
135
  placeholder="Say something..."
136
  />
137
+
138
  {#if isLoading}
139
  <p class="text-sm text-slate-600 text-center">{loadingStatus}</p>
140
  {:else if error}
 
149
  {/if}
150
  </div>
151
  {/if}
152
+ <div class="w-full flex flex-col items-center gap-2">
153
+ <input
154
+ type="range"
155
+ id="max-tokens"
156
+ bind:value={maxTokens}
157
+ min="15"
158
+ max="75"
159
+ step="1"
160
+ class="w-full accent-black"
161
+ />
162
+ <label for="max-tokens" class="text-xs italic text-slate-800">Max of {maxTokens} tokens</label>
163
+ </div>
164
  <div class="flex flex-col items-center mb-4">
165
  {#if inputText === '' && !isLoading}
166
  <p class="text-sm mb-2">Try these examples:</p>