mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix type errors
This commit is contained in:
@@ -24,6 +24,10 @@ const REROLL_BUTTON = $('#logprobsReroll');
|
|||||||
* @typedef {[string, number]} Candidate - (token, logprob)
|
* @typedef {[string, number]} Candidate - (token, logprob)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {(Node|JQuery<Text>|JQuery<HTMLElement>)[]} NodeArray - Array of DOM nodes
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logprob data for a single message
|
* Logprob data for a single message
|
||||||
* @typedef {Object} MessageLogprobData
|
* @typedef {Object} MessageLogprobData
|
||||||
@@ -200,15 +204,15 @@ function renderTopLogprobs() {
|
|||||||
container.addClass('selected');
|
container.addClass('selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenText = $('<span></span>').text(`${toVisibleWhitespace(token)}`);
|
const tokenText = $('<span></span>').text(`${toVisibleWhitespace(token.toString())}`);
|
||||||
const percentText = $('<span></span>').text(`${(probability * 100).toFixed(2)}%`);
|
const percentText = $('<span></span>').text(`${(+probability * 100).toFixed(2)}%`);
|
||||||
container.append(tokenText, percentText);
|
container.append(tokenText, percentText);
|
||||||
if (log) {
|
if (log) {
|
||||||
container.attr('title', `logarithm: ${log}`);
|
container.attr('title', `logarithm: ${log}`);
|
||||||
}
|
}
|
||||||
addKeyboardProps(container);
|
addKeyboardProps(container);
|
||||||
if (token !== '<others>') {
|
if (token !== '<others>') {
|
||||||
container.on('click', () => onAlternativeClicked(state.selectedTokenLogprobs, token));
|
container.on('click', () => onAlternativeClicked(state.selectedTokenLogprobs, token.toString()));
|
||||||
} else {
|
} else {
|
||||||
container.prop('disabled', true);
|
container.prop('disabled', true);
|
||||||
}
|
}
|
||||||
@@ -228,7 +232,7 @@ function renderTopLogprobs() {
|
|||||||
* User clicks on a token in the token output view. It updates the selected token state
|
* User clicks on a token in the token output view. It updates the selected token state
|
||||||
* and re-renders the top logprobs view, or deselects the token if it was already selected.
|
* and re-renders the top logprobs view, or deselects the token if it was already selected.
|
||||||
* @param {TokenLogprobs} logprobs - logprob data for the selected token
|
* @param {TokenLogprobs} logprobs - logprob data for the selected token
|
||||||
* @param {Element} span - target span node that was clicked
|
* @param {Node|JQuery} span - target span node that was clicked
|
||||||
*/
|
*/
|
||||||
function onSelectedTokenChanged(logprobs, span) {
|
function onSelectedTokenChanged(logprobs, span) {
|
||||||
$('.logprobs_output_token.selected').removeClass('selected');
|
$('.logprobs_output_token.selected').removeClass('selected');
|
||||||
@@ -399,11 +403,11 @@ function toVisibleWhitespace(input) {
|
|||||||
* after the span node if its token begins or ends with whitespace in order to
|
* after the span node if its token begins or ends with whitespace in order to
|
||||||
* allow text to wrap despite whitespace characters being replaced with a dot.
|
* allow text to wrap despite whitespace characters being replaced with a dot.
|
||||||
* @param {string} text - token text being evaluated for whitespace
|
* @param {string} text - token text being evaluated for whitespace
|
||||||
* @param {Element} span - target span node to be wrapped
|
* @param {Node|JQuery} span - target span node to be wrapped
|
||||||
* @returns {Node[]} - array of nodes to be appended to the parent element
|
* @returns {NodeArray} - array of nodes to be appended to the parent element
|
||||||
*/
|
*/
|
||||||
function withVirtualWhitespace(text, span) {
|
function withVirtualWhitespace(text, span) {
|
||||||
/** @type {Node[]} */
|
/** @type {NodeArray} */
|
||||||
const result = [span];
|
const result = [span];
|
||||||
if (text.match(/^\s/)) {
|
if (text.match(/^\s/)) {
|
||||||
result.unshift(document.createTextNode('\u200b'));
|
result.unshift(document.createTextNode('\u200b'));
|
||||||
@@ -522,7 +526,7 @@ function convertTokenIdLogprobsToText(input) {
|
|||||||
|
|
||||||
// Submit token IDs to tokenizer to get token text, then build ID->text map
|
// Submit token IDs to tokenizer to get token text, then build ID->text map
|
||||||
// noinspection JSCheckFunctionSignatures - mutates input in-place
|
// noinspection JSCheckFunctionSignatures - mutates input in-place
|
||||||
const { chunks } = decodeTextTokens(tokenizerId, tokenIds);
|
const { chunks } = decodeTextTokens(tokenizerId, tokenIds.map(parseInt));
|
||||||
const tokenIdText = new Map(tokenIds.map((id, i) => [id, chunks[i]]));
|
const tokenIdText = new Map(tokenIds.map((id, i) => [id, chunks[i]]));
|
||||||
|
|
||||||
// Fixup logprobs data with token text
|
// Fixup logprobs data with token text
|
||||||
|
Reference in New Issue
Block a user