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