mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add debug functions menu
This commit is contained in:
@ -2961,9 +2961,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-container">
|
||||||
<div id="reload_chat" class="menu_button whitespacenowrap" data-i18n="Reload Chat">
|
<div id="reload_chat" class="menu_button whitespacenowrap" data-i18n="Reload Chat">
|
||||||
Reload Chat
|
Reload Chat
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="debug_menu" class="menu_button whitespacenowrap" data-i18n="Debug Menu">
|
||||||
|
Debug Menu
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,6 +70,7 @@ import {
|
|||||||
MAX_CONTEXT_DEFAULT,
|
MAX_CONTEXT_DEFAULT,
|
||||||
renderStoryString,
|
renderStoryString,
|
||||||
sortEntitiesList,
|
sortEntitiesList,
|
||||||
|
registerDebugFunction,
|
||||||
} from "./scripts/power-user.js";
|
} from "./scripts/power-user.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -6658,6 +6659,7 @@ window["SillyTavern"].getContext = function () {
|
|||||||
saveReply,
|
saveReply,
|
||||||
registerSlashCommand: registerSlashCommand,
|
registerSlashCommand: registerSlashCommand,
|
||||||
registerHelper: registerExtensionHelper,
|
registerHelper: registerExtensionHelper,
|
||||||
|
registedDebugFunction: registerDebugFunction,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { registerDebugFunction } from "./power-user.js";
|
||||||
import { waitUntilCondition } from "./utils.js";
|
import { waitUntilCondition } from "./utils.js";
|
||||||
|
|
||||||
const storageKey = "language";
|
const storageKey = "language";
|
||||||
@ -48,9 +49,9 @@ function getMissingTranslations() {
|
|||||||
|
|
||||||
console.table(uniqueMissingData);
|
console.table(uniqueMissingData);
|
||||||
console.log(missingDataMap);
|
console.log(missingDataMap);
|
||||||
}
|
|
||||||
|
|
||||||
window["getMissingTranslations"] = getMissingTranslations;
|
toastr.success(`Found ${uniqueMissingData.length} missing translations. See browser console for details.`);
|
||||||
|
}
|
||||||
|
|
||||||
export function applyLocale(root = document) {
|
export function applyLocale(root = document) {
|
||||||
const overrideLanguage = localStorage.getItem("language");
|
const overrideLanguage = localStorage.getItem("language");
|
||||||
@ -106,7 +107,6 @@ function addLanguagesToDropdown() {
|
|||||||
|
|
||||||
jQuery(async () => {
|
jQuery(async () => {
|
||||||
waitUntilCondition(() => !!localeData);
|
waitUntilCondition(() => !!localeData);
|
||||||
window["applyLocale"] = applyLocale;
|
|
||||||
applyLocale();
|
applyLocale();
|
||||||
addLanguagesToDropdown();
|
addLanguagesToDropdown();
|
||||||
|
|
||||||
@ -121,4 +121,7 @@ jQuery(async () => {
|
|||||||
|
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerDebugFunction('getMissingTranslations', 'Get missing translations', 'Detects missing localization data and dumps the data into the browser console.', getMissingTranslations);
|
||||||
|
registerDebugFunction('applyLocale', 'Apply locale', 'Reapplies the currently selected locale to the page.', applyLocale);
|
||||||
});
|
});
|
||||||
|
@ -13,7 +13,8 @@ import {
|
|||||||
getCurrentChatId,
|
getCurrentChatId,
|
||||||
printCharacters,
|
printCharacters,
|
||||||
setCharacterId,
|
setCharacterId,
|
||||||
setEditedMessageId
|
setEditedMessageId,
|
||||||
|
renderTemplate,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
import { isMobile, initMovingUI } from "./RossAscends-mods.js";
|
import { isMobile, initMovingUI } from "./RossAscends-mods.js";
|
||||||
import {
|
import {
|
||||||
@ -232,6 +233,7 @@ const storage_keys = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let browser_has_focus = true;
|
let browser_has_focus = true;
|
||||||
|
const debug_functions = [];
|
||||||
|
|
||||||
function playMessageSound() {
|
function playMessageSound() {
|
||||||
if (!power_user.play_message_sound) {
|
if (!power_user.play_message_sound) {
|
||||||
@ -653,6 +655,22 @@ async function applyMovingUIPreset(name) {
|
|||||||
loadMovingUIState()
|
loadMovingUIState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a function to be executed when the debug menu is opened.
|
||||||
|
* @param {string} functionId Unique ID for the function.
|
||||||
|
* @param {string} name Name of the function.
|
||||||
|
* @param {string} description Description of the function.
|
||||||
|
* @param {function} func Function to be executed.
|
||||||
|
*/
|
||||||
|
export function registerDebugFunction(functionId, name, description, func) {
|
||||||
|
debug_functions.push({ functionId, name, description, func });
|
||||||
|
}
|
||||||
|
|
||||||
|
function showDebugMenu() {
|
||||||
|
const template = renderTemplate('debug', { functions: debug_functions });
|
||||||
|
callPopup(template, 'text', '', { wide: true, large: true });
|
||||||
|
}
|
||||||
|
|
||||||
switchUiMode();
|
switchUiMode();
|
||||||
applyFontScale('forced');
|
applyFontScale('forced');
|
||||||
applyThemeColor();
|
applyThemeColor();
|
||||||
@ -2113,6 +2131,21 @@ $(document).ready(() => {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#debug_menu').on('click', function () {
|
||||||
|
showDebugMenu();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '#debug_table [data-debug-function]', function () {
|
||||||
|
const functionId = $(this).data('debug-function');
|
||||||
|
const functionRecord = debug_functions.find(f => f.functionId === functionId);
|
||||||
|
|
||||||
|
if (functionRecord) {
|
||||||
|
functionRecord.func();
|
||||||
|
} else {
|
||||||
|
console.warn(`Debug function ${functionId} not found`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$(window).on('focus', function () {
|
$(window).on('focus', function () {
|
||||||
browser_has_focus = true;
|
browser_has_focus = true;
|
||||||
});
|
});
|
||||||
|
25
public/scripts/templates/debug.html
Normal file
25
public/scripts/templates/debug.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<h3 data-i18n="Debug Menu">Debug Menu</h3>
|
||||||
|
<div data-i18n="Debug Warning">
|
||||||
|
Functions in this category are for advanced users only. Don't click anything if you're not sure about the consequences.
|
||||||
|
</div>
|
||||||
|
<table id="debug_table" class="responsiveTable">
|
||||||
|
{{#each functions}}
|
||||||
|
{{#with this}}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="justifyLeft">
|
||||||
|
<b>{{this.name}}</b>
|
||||||
|
</div>
|
||||||
|
<div class="justifyLeft">
|
||||||
|
{{this.description}}
|
||||||
|
</div>
|
||||||
|
<div class="flex-container justifyCenter">
|
||||||
|
<div class="menu_button menu_button_icon" data-debug-function="{{this.functionId}}" data-i18n="Execute">
|
||||||
|
Execute
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/with}}
|
||||||
|
{{/each}}
|
||||||
|
</table>
|
@ -1,5 +1,5 @@
|
|||||||
import { characters, main_api, nai_settings, online_status, this_chid } from "../script.js";
|
import { characters, main_api, nai_settings, online_status, this_chid } from "../script.js";
|
||||||
import { power_user } from "./power-user.js";
|
import { power_user, registerDebugFunction } from "./power-user.js";
|
||||||
import { chat_completion_sources, oai_settings } from "./openai.js";
|
import { chat_completion_sources, oai_settings } from "./openai.js";
|
||||||
import { groups, selected_group } from "./group-chats.js";
|
import { groups, selected_group } from "./group-chats.js";
|
||||||
import { getStringHash } from "./utils.js";
|
import { getStringHash } from "./utils.js";
|
||||||
@ -59,13 +59,12 @@ async function resetTokenCache() {
|
|||||||
console.debug('Chat Completions: resetting token cache');
|
console.debug('Chat Completions: resetting token cache');
|
||||||
Object.keys(tokenCache).forEach(key => delete tokenCache[key]);
|
Object.keys(tokenCache).forEach(key => delete tokenCache[key]);
|
||||||
await objectStore.removeItem('tokenCache');
|
await objectStore.removeItem('tokenCache');
|
||||||
|
toastr.success('Token cache cleared. Please reload the chat to re-tokenize it.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Chat Completions: unable to reset token cache', e);
|
console.log('Chat Completions: unable to reset token cache', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window['resetTokenCache'] = resetTokenCache;
|
|
||||||
|
|
||||||
function getTokenizerBestMatch() {
|
function getTokenizerBestMatch() {
|
||||||
if (main_api === 'novel') {
|
if (main_api === 'novel') {
|
||||||
if (nai_settings.model_novel.includes('krake') || nai_settings.model_novel.includes('euterpe')) {
|
if (nai_settings.model_novel.includes('krake') || nai_settings.model_novel.includes('euterpe')) {
|
||||||
@ -438,4 +437,5 @@ export function decodeTextTokens(tokenizerType, ids) {
|
|||||||
|
|
||||||
jQuery(async () => {
|
jQuery(async () => {
|
||||||
await loadTokenCache();
|
await loadTokenCache();
|
||||||
|
registerDebugFunction('resetTokenCache', 'Reset token cache', 'Purges the calculated token counts. Use this if you want to force a full re-tokenization of all chats or suspect the token counts are wrong.', resetTokenCache);
|
||||||
});
|
});
|
||||||
|
@ -1768,10 +1768,10 @@ grammarly-extension {
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
box-shadow: 0px 0px 14px var(--black50a);
|
box-shadow: 0px 0px 14px var(--black70a);
|
||||||
border: 1px solid var(--white30a);
|
border: 1px solid var(--white30a);
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
background-color: var(--black30a);
|
background-color: var(--black50a);
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
max-height: 90vh;
|
max-height: 90vh;
|
||||||
max-height: 90svh;
|
max-height: 90svh;
|
||||||
|
Reference in New Issue
Block a user