Fix type errors

b143b3c8208c83264e70fc2337fd0cce6378ef76

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +12 -8Showing whitespace changes
public/scripts/logprobs.js+12 -8
@@ -25,6 +25,10 @@ const REROLL_BUTTON = $('#logprobsReroll');
2525 */
2626
2727/**
28+ * @typedef {(Node|JQuery<Text>|JQuery<HTMLElement>)[]} NodeArray - Array of DOM nodes
29+ */
30+
31+/**
2832 * Logprob data for a single message
2933 * @typedef {Object} MessageLogprobData
3034 * @property {number} created - timestamp of when the message was generated
@@ -200,15 +204,15 @@ function renderTopLogprobs() {
200204 container.addClass('selected');
201205 }
202206
203207 const tokenText = $('<span></span>').text(`${toVisibleWhitespace(token.toString())}`);
204208 const percentText = $('<span></span>').text(`${(+probability * 100).toFixed(2)}%`);
205209 container.append(tokenText, percentText);
206210 if (log) {
207211 container.attr('title', `logarithm: ${log}`);
208212 }
209213 addKeyboardProps(container);
210214 if (token !== '<others>') {
211215 container.on('click', () => onAlternativeClicked(state.selectedTokenLogprobs, token.toString()));
212216 } else {
213217 container.prop('disabled', true);
214218 }
@@ -228,7 +232,7 @@ function renderTopLogprobs() {
228232 * User clicks on a token in the token output view. It updates the selected token state
229233 * and re-renders the top logprobs view, or deselects the token if it was already selected.
230234 * @param {TokenLogprobs} logprobs - logprob data for the selected token
231235 * @param {ElementNode|JQuery} span - target span node that was clicked
232236 */
233237function onSelectedTokenChanged(logprobs, span) {
234238 $('.logprobs_output_token.selected').removeClass('selected');
@@ -399,11 +403,11 @@ function toVisibleWhitespace(input) {
399403 * after the span node if its token begins or ends with whitespace in order to
400404 * allow text to wrap despite whitespace characters being replaced with a dot.
401405 * @param {string} text - token text being evaluated for whitespace
402406 * @param {ElementNode|JQuery} span - target span node to be wrapped
403407 * @returns {Node[]NodeArray} - array of nodes to be appended to the parent element
404408 */
405409function withVirtualWhitespace(text, span) {
406410 /** @type {Node[]NodeArray} */
407411 const result = [span];
408412 if (text.match(/^\s/)) {
409413 result.unshift(document.createTextNode('\u200b'));
@@ -522,7 +526,7 @@ function convertTokenIdLogprobsToText(input) {
522526
523527 // Submit token IDs to tokenizer to get token text, then build ID->text map
524528 // noinspection JSCheckFunctionSignatures - mutates input in-place
525529 const { chunks } = decodeTextTokens(tokenizerId, tokenIds.map(parseInt));
526530 const tokenIdText = new Map(tokenIds.map((id, i) => [id, chunks[i]]));
527531
528532 // Fixup logprobs data with token text