jfrery-zama commited on
Commit
8a699bc
·
unverified ·
1 Parent(s): cb10dda

chore: only enable 16 tokens

Browse files
Files changed (1) hide show
  1. wasm-demo.js +29 -0
wasm-demo.js CHANGED
@@ -140,6 +140,35 @@ $('btnKeygen').onclick = async () => {
140
  }
141
  };
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  $('btnEncrypt').onclick = async () => {
144
  const text = $('tokenInput').value.trim();
145
  if (!text) {
 
140
  }
141
  };
142
 
143
+ // Add token counter functionality
144
+ $('tokenInput').addEventListener('input', () => {
145
+ const text = $('tokenInput').value.trim();
146
+ if (text && typeof llama3Tokenizer !== 'undefined') {
147
+ try {
148
+ const tokenIds = llama3Tokenizer.encode(text);
149
+ const tokenCount = tokenIds.length;
150
+ const TOKEN_LIMIT = 16;
151
+
152
+ if (tokenCount > TOKEN_LIMIT) {
153
+ $('encStatus').textContent = `⚠️ ${tokenCount}/${TOKEN_LIMIT} tokens - text too long`;
154
+ $('encStatus').style.color = '#d32f2f';
155
+ } else if (tokenCount > TOKEN_LIMIT * 0.8) {
156
+ $('encStatus').textContent = `${tokenCount}/${TOKEN_LIMIT} tokens`;
157
+ $('encStatus').style.color = '#f57c00';
158
+ } else {
159
+ $('encStatus').textContent = `${tokenCount}/${TOKEN_LIMIT} tokens`;
160
+ $('encStatus').style.color = '';
161
+ }
162
+ } catch (e) {
163
+ // Tokenizer might not be ready yet
164
+ $('encStatus').textContent = '';
165
+ }
166
+ } else {
167
+ $('encStatus').textContent = '';
168
+ $('encStatus').style.color = '';
169
+ }
170
+ });
171
+
172
  $('btnEncrypt').onclick = async () => {
173
  const text = $('tokenInput').value.trim();
174
  if (!text) {