mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
/stop slash command to stop generation
This commit is contained in:
@ -520,6 +520,7 @@ const chatElement = $('#chat');
|
|||||||
let dialogueResolve = null;
|
let dialogueResolve = null;
|
||||||
let dialogueCloseStop = false;
|
let dialogueCloseStop = false;
|
||||||
export let chat_metadata = {};
|
export let chat_metadata = {};
|
||||||
|
/** @type {StreamingProcessor} */
|
||||||
export let streamingProcessor = null;
|
export let streamingProcessor = null;
|
||||||
let crop_data = undefined;
|
let crop_data = undefined;
|
||||||
let is_delete_mode = false;
|
let is_delete_mode = false;
|
||||||
@ -837,6 +838,7 @@ export let main_api;// = "kobold";
|
|||||||
//novel settings
|
//novel settings
|
||||||
export let novelai_settings;
|
export let novelai_settings;
|
||||||
export let novelai_setting_names;
|
export let novelai_setting_names;
|
||||||
|
/** @type {AbortController} */
|
||||||
let abortController;
|
let abortController;
|
||||||
|
|
||||||
//css
|
//css
|
||||||
@ -4380,6 +4382,25 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the generation and any streaming if it is currently running.
|
||||||
|
*/
|
||||||
|
export function stopGeneration() {
|
||||||
|
let stopped = false;
|
||||||
|
if (streamingProcessor) {
|
||||||
|
streamingProcessor.onStopStreaming();
|
||||||
|
streamingProcessor = null;
|
||||||
|
stopped = true;
|
||||||
|
}
|
||||||
|
if (abortController) {
|
||||||
|
abortController.abort('Clicked stop button');
|
||||||
|
hideStopButton();
|
||||||
|
stopped = true;
|
||||||
|
}
|
||||||
|
eventSource.emit(event_types.GENERATION_STOPPED);
|
||||||
|
return stopped;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injects extension prompts into chat messages.
|
* Injects extension prompts into chat messages.
|
||||||
* @param {object[]} messages Array of chat messages
|
* @param {object[]} messages Array of chat messages
|
||||||
@ -10342,15 +10363,7 @@ jQuery(async function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '.mes_stop', function () {
|
$(document).on('click', '.mes_stop', function () {
|
||||||
if (streamingProcessor) {
|
stopGeneration();
|
||||||
streamingProcessor.onStopStreaming();
|
|
||||||
streamingProcessor = null;
|
|
||||||
}
|
|
||||||
if (abortController) {
|
|
||||||
abortController.abort('Clicked stop button');
|
|
||||||
hideStopButton();
|
|
||||||
}
|
|
||||||
eventSource.emit(event_types.GENERATION_STOPPED);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '#form_sheld .stscript_continue', function () {
|
$(document).on('click', '#form_sheld .stscript_continue', function () {
|
||||||
@ -10839,3 +10852,4 @@ jQuery(async function () {
|
|||||||
|
|
||||||
initCustomSelectedSamplers();
|
initCustomSelectedSamplers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import {
|
|||||||
setCharacterName,
|
setCharacterName,
|
||||||
setExtensionPrompt,
|
setExtensionPrompt,
|
||||||
setUserName,
|
setUserName,
|
||||||
|
stopGeneration,
|
||||||
substituteParams,
|
substituteParams,
|
||||||
system_avatar,
|
system_avatar,
|
||||||
system_message_types,
|
system_message_types,
|
||||||
@ -898,6 +899,24 @@ export function initDefaultSlashCommands() {
|
|||||||
],
|
],
|
||||||
helpString: 'Adds a swipe to the last chat message.',
|
helpString: 'Adds a swipe to the last chat message.',
|
||||||
}));
|
}));
|
||||||
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
|
name: 'stop',
|
||||||
|
callback: () => {
|
||||||
|
const stopped = stopGeneration();
|
||||||
|
return String(stopped);
|
||||||
|
},
|
||||||
|
returns: 'true/false, whether the generation was running and got stopped',
|
||||||
|
helpString: `
|
||||||
|
<div>
|
||||||
|
Stops the generation and any streaming if it is currently running.
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
Note: This command cannot be executed from the chat input, as sending any message or script from there is blocked during generation.
|
||||||
|
But it can be executed via automations or QR scripts/buttons.
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
aliases: ['generate-stop'],
|
||||||
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'abort',
|
name: 'abort',
|
||||||
callback: abortCallback,
|
callback: abortCallback,
|
||||||
|
Reference in New Issue
Block a user