mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Delete itemized prompts on chat deletion
This commit is contained in:
@ -832,6 +832,22 @@ export async function replaceItemizedPromptText(mesId, promptText) {
|
||||
itemizedPrompt.rawPrompt = promptText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the itemized prompts for a chat.
|
||||
* @param {string} chatId Chat ID to delete itemized prompts for
|
||||
*/
|
||||
export async function deleteItemizedPrompts(chatId) {
|
||||
try {
|
||||
if (!chatId) {
|
||||
return;
|
||||
}
|
||||
|
||||
await promptStorage.removeItem(chatId);
|
||||
} catch {
|
||||
console.log("Error deleting itemized prompts for chat", chatId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empties the itemized prompts array and caches.
|
||||
*/
|
||||
@ -7246,6 +7262,44 @@ function doTogglePanels() {
|
||||
$("#option_settings").trigger('click')
|
||||
}
|
||||
|
||||
function addDebugFunctions() {
|
||||
registerDebugFunction('backfillTokenCounts', 'Backfill token counters',
|
||||
`Recalculates token counts of all messages in the current chat to refresh the counters.
|
||||
Useful when you switch between models that have different tokenizers.
|
||||
This is a visual change only. Your chat will be reloaded.`, async () => {
|
||||
for (const message of chat) {
|
||||
// System messages are not counted
|
||||
if (message.is_system) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!message.extra) {
|
||||
message.extra = {};
|
||||
}
|
||||
|
||||
message.extra.token_count = getTokenCount(message.mes, 0);
|
||||
}
|
||||
|
||||
await saveChatConditional();
|
||||
await reloadCurrentChat();
|
||||
});
|
||||
|
||||
registerDebugFunction('generationTest', 'Send a generation request', 'Generates text using the currently selected API.', async () => {
|
||||
const text = prompt('Input text:', 'Hello');
|
||||
toastr.info('Working on it...');
|
||||
const message = await generateRaw(text, null);
|
||||
alert(message);
|
||||
});
|
||||
|
||||
registerDebugFunction('clearPrompts', 'Delete itemized prompts', 'Deletes all itemized prompts from the local storage.', async () => {
|
||||
await clearItemizedPrompts();
|
||||
toastr.info('Itemized prompts deleted.');
|
||||
if (getCurrentChatId()) {
|
||||
await reloadCurrentChat();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(async function () {
|
||||
|
||||
if (isMobile() === true) {
|
||||
@ -9046,39 +9100,12 @@ jQuery(async function () {
|
||||
// Added here to prevent execution before script.js is loaded and get rid of quirky timeouts
|
||||
await firstLoadInit();
|
||||
|
||||
registerDebugFunction('backfillTokenCounts', 'Backfill token counters',
|
||||
`Recalculates token counts of all messages in the current chat to refresh the counters.
|
||||
Useful when you switch between models that have different tokenizers.
|
||||
This is a visual change only. Your chat will be reloaded.`, async () => {
|
||||
for (const message of chat) {
|
||||
// System messages are not counted
|
||||
if (message.is_system) {
|
||||
continue;
|
||||
}
|
||||
addDebugFunctions();
|
||||
|
||||
if (!message.extra) {
|
||||
message.extra = {};
|
||||
}
|
||||
|
||||
message.extra.token_count = getTokenCount(message.mes, 0);
|
||||
}
|
||||
|
||||
await saveChatConditional();
|
||||
await reloadCurrentChat();
|
||||
eventSource.on(event_types.CHAT_DELETED, async (name) => {
|
||||
await deleteItemizedPrompts(name);
|
||||
});
|
||||
|
||||
registerDebugFunction('generationTest', 'Send a generation request', 'Generates text using the currently selected API.', async () => {
|
||||
const text = prompt('Input text:', 'Hello');
|
||||
toastr.info('Working on it...');
|
||||
const message = await generateRaw(text, null);
|
||||
alert(message);
|
||||
});
|
||||
|
||||
registerDebugFunction('clearPrompts', 'Delete itemized prompts', 'Deletes all itemized prompts from the local storage.', async () => {
|
||||
await clearItemizedPrompts();
|
||||
toastr.info('Itemized prompts deleted.');
|
||||
if (getCurrentChatId()) {
|
||||
await reloadCurrentChat();
|
||||
}
|
||||
eventSource.on(event_types.GROUP_CHAT_DELETED, async (name) => {
|
||||
await deleteItemizedPrompts(name);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user