Fix type errors
| @@ -25,6 +25,10 @@ const REROLL_BUTTON = $('#logprobsReroll'); | |||
| 25 | */ | 25 | */ |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * @typedef {(Node|JQuery<Text>|JQuery<HTMLElement>)[]} NodeArray - Array of DOM nodes | ||
| 29 | */ | ||
| 30 | |||
| 31 | /** | ||
| 28 | * Logprob data for a single message | 32 | * Logprob data for a single message |
| 29 | * @typedef {Object} MessageLogprobData | 33 | * @typedef {Object} MessageLogprobData |
| 30 | * @property {number} created - timestamp of when the message was generated | 34 | * @property {number} created - timestamp of when the message was generated |
| @@ -200,15 +204,15 @@ function renderTopLogprobs() { | |||
| 200 | container.addClass('selected'); | 204 | container.addClass('selected'); |
| 201 | } | 205 | } |
| 202 | 206 | ||
| 203 | const tokenText = $('<span></span>').text(`${toVisibleWhitespace(token)}`); | 207 | const tokenText = $('<span></span>').text(`${toVisibleWhitespace(token.toString())}`); |
| 204 | const percentText = $('<span></span>').text(`${(probability * 100).toFixed(2)}%`); | 208 | const percentText = $('<span></span>').text(`${(+probability * 100).toFixed(2)}%`); |
| 205 | container.append(tokenText, percentText); | 209 | container.append(tokenText, percentText); |
| 206 | if (log) { | 210 | if (log) { |
| 207 | container.attr('title', `logarithm: ${log}`); | 211 | container.attr('title', `logarithm: ${log}`); |
| 208 | } | 212 | } |
| 209 | addKeyboardProps(container); | 213 | addKeyboardProps(container); |
| 210 | if (token !== '<others>') { | 214 | if (token !== '<others>') { |
| 211 | container.on('click', () => onAlternativeClicked(state.selectedTokenLogprobs, token)); | 215 | container.on('click', () => onAlternativeClicked(state.selectedTokenLogprobs, token.toString())); |
| 212 | } else { | 216 | } else { |
| 213 | container.prop('disabled', true); | 217 | container.prop('disabled', true); |
| 214 | } | 218 | } |
| @@ -228,7 +232,7 @@ function renderTopLogprobs() { | |||
| 228 | * User clicks on a token in the token output view. It updates the selected token state | 232 | * User clicks on a token in the token output view. It updates the selected token state |
| 229 | * and re-renders the top logprobs view, or deselects the token if it was already selected. | 233 | * and re-renders the top logprobs view, or deselects the token if it was already selected. |
| 230 | * @param {TokenLogprobs} logprobs - logprob data for the selected token | 234 | * @param {TokenLogprobs} logprobs - logprob data for the selected token |
| 231 | * @param {Element} span - target span node that was clicked | 235 | * @param {Node|JQuery} span - target span node that was clicked |
| 232 | */ | 236 | */ |
| 233 | function onSelectedTokenChanged(logprobs, span) { | 237 | function onSelectedTokenChanged(logprobs, span) { |
| 234 | $('.logprobs_output_token.selected').removeClass('selected'); | 238 | $('.logprobs_output_token.selected').removeClass('selected'); |
| @@ -399,11 +403,11 @@ function toVisibleWhitespace(input) { | |||
| 399 | * after the span node if its token begins or ends with whitespace in order to | 403 | * after the span node if its token begins or ends with whitespace in order to |
| 400 | * allow text to wrap despite whitespace characters being replaced with a dot. | 404 | * allow text to wrap despite whitespace characters being replaced with a dot. |
| 401 | * @param {string} text - token text being evaluated for whitespace | 405 | * @param {string} text - token text being evaluated for whitespace |
| 402 | * @param {Element} span - target span node to be wrapped | 406 | * @param {Node|JQuery} span - target span node to be wrapped |
| 403 | * @returns {Node[]} - array of nodes to be appended to the parent element | 407 | * @returns {NodeArray} - array of nodes to be appended to the parent element |
| 404 | */ | 408 | */ |
| 405 | function withVirtualWhitespace(text, span) { | 409 | function withVirtualWhitespace(text, span) { |
| 406 | /** @type {Node[]} */ | 410 | /** @type {NodeArray} */ |
| 407 | const result = [span]; | 411 | const result = [span]; |
| 408 | if (text.match(/^\s/)) { | 412 | if (text.match(/^\s/)) { |
| 409 | result.unshift(document.createTextNode('\u200b')); | 413 | result.unshift(document.createTextNode('\u200b')); |
| @@ -522,7 +526,7 @@ function convertTokenIdLogprobsToText(input) { | |||
| 522 | 526 | ||
| 523 | // Submit token IDs to tokenizer to get token text, then build ID->text map | 527 | // Submit token IDs to tokenizer to get token text, then build ID->text map |
| 524 | // noinspection JSCheckFunctionSignatures - mutates input in-place | 528 | // noinspection JSCheckFunctionSignatures - mutates input in-place |
| 525 | const { chunks } = decodeTextTokens(tokenizerId, tokenIds); | 529 | const { chunks } = decodeTextTokens(tokenizerId, tokenIds.map(parseInt)); |
| 526 | const tokenIdText = new Map(tokenIds.map((id, i) => [id, chunks[i]])); | 530 | const tokenIdText = new Map(tokenIds.map((id, i) => [id, chunks[i]])); |
| 527 | 531 | ||
| 528 | // Fixup logprobs data with token text | 532 | // Fixup logprobs data with token text |