mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-06 04:38:21 +01:00
/stop slash command to stop generation
This commit is contained in:
parent
6e86ab07dd
commit
7de43d3a9c
@ -520,6 +520,7 @@ const chatElement = $('#chat');
|
||||
let dialogueResolve = null;
|
||||
let dialogueCloseStop = false;
|
||||
export let chat_metadata = {};
|
||||
/** @type {StreamingProcessor} */
|
||||
export let streamingProcessor = null;
|
||||
let crop_data = undefined;
|
||||
let is_delete_mode = false;
|
||||
@ -837,6 +838,7 @@ export let main_api;// = "kobold";
|
||||
//novel settings
|
||||
export let novelai_settings;
|
||||
export let novelai_setting_names;
|
||||
/** @type {AbortController} */
|
||||
let abortController;
|
||||
|
||||
//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.
|
||||
* @param {object[]} messages Array of chat messages
|
||||
@ -10342,15 +10363,7 @@ jQuery(async function () {
|
||||
});
|
||||
|
||||
$(document).on('click', '.mes_stop', function () {
|
||||
if (streamingProcessor) {
|
||||
streamingProcessor.onStopStreaming();
|
||||
streamingProcessor = null;
|
||||
}
|
||||
if (abortController) {
|
||||
abortController.abort('Clicked stop button');
|
||||
hideStopButton();
|
||||
}
|
||||
eventSource.emit(event_types.GENERATION_STOPPED);
|
||||
stopGeneration();
|
||||
});
|
||||
|
||||
$(document).on('click', '#form_sheld .stscript_continue', function () {
|
||||
@ -10839,3 +10852,4 @@ jQuery(async function () {
|
||||
|
||||
initCustomSelectedSamplers();
|
||||
});
|
||||
|
||||
|
@ -33,6 +33,7 @@ import {
|
||||
setCharacterName,
|
||||
setExtensionPrompt,
|
||||
setUserName,
|
||||
stopGeneration,
|
||||
substituteParams,
|
||||
system_avatar,
|
||||
system_message_types,
|
||||
@ -898,6 +899,24 @@ export function initDefaultSlashCommands() {
|
||||
],
|
||||
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({
|
||||
name: 'abort',
|
||||
callback: abortCallback,
|
||||
|
Loading…
x
Reference in New Issue
Block a user