correctly interpret some alternate whitespaces in token names

5d5e552cbdaf46bd123a3ce5a90057e93d545e09

50h100a <all_awful@proton.me>

2 files changed, +5 -5Showing whitespace changes
public/scripts/extensions/token-counter/index.js+1 -1
@@ -89,7 +89,7 @@ function drawChunks(chunks, ids) {
8989 $('#tokenized_chunks_display').empty();
9090
9191 for (let i = 0; i < chunks.length; i++) {
9292 let chunk = chunks[i].replace(/[Ġ]/g, ' '); // This is a leading space in sentencepiece. More info: Lower one eighth block (U+2581)
9393
9494 // If <0xHEX>, decode it
9595 if (/^<0x[0-9A-F]+>$/i.test(chunk)) {
public/scripts/logprobs.js+4 -4
@@ -160,7 +160,7 @@ function renderTopLogprobs() {
160160 let matched = false;
161161 for (const [token, probability, log] of candidates) {
162162 const container = $('<button class="flex-container flexFlowColumn logprobs_top_candidate"></button>');
163163 const tokenNormalized = String(token).replace(/^[Ġ]/g, ' ');
164164
165165 if (token === selectedToken || tokenNormalized === selectedToken) {
166166 matched = true;
@@ -230,7 +230,7 @@ function onAlternativeClicked(tokenLogprobs, alternative) {
230230 const replaceIndex = messageLogprobs.findIndex(x => x === tokenLogprobs);
231231
232232 const tokens = messageLogprobs.slice(0, replaceIndex + 1).map(({ token }) => token);
233233 tokens[replaceIndex] = String(alternative).replace(/^[Ġ]/g, ' ').replace(/Ċ/g, '\n');
234234
235235 const prefix = continueFrom || '';
236236 const prompt = prefix + tokens.join('');
@@ -343,7 +343,7 @@ function createSwipe(messageId, prompt) {
343343 * @returns {string}
344344 */
345345function toVisibleWhitespace(input) {
346346 return input.replace(/ /g, '·').replace(/[Ġ]/g, '·').replace(/\n]/g, '↵');
347347}
348348
349349/**
@@ -362,7 +362,7 @@ function withVirtualWhitespace(text, span) {
362362 if (text.match(/\s$/)) {
363363 result.push($(document.createTextNode('\u200b')));
364364 }
365365 if (text.match(/^[Ġ]/)) {
366366 result.unshift(document.createTextNode('\u200b'));
367367 }
368368 // line breaks are trickier. we don't currently handle consecutive line