mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add slash commands for instruct and context
This commit is contained in:
@ -78,6 +78,7 @@ import {
|
|||||||
ui_mode,
|
ui_mode,
|
||||||
switchSimpleMode,
|
switchSimpleMode,
|
||||||
flushEphemeralStoppingStrings,
|
flushEphemeralStoppingStrings,
|
||||||
|
context_presets,
|
||||||
} from './scripts/power-user.js';
|
} from './scripts/power-user.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -178,6 +179,9 @@ import {
|
|||||||
getInstructStoppingSequences,
|
getInstructStoppingSequences,
|
||||||
autoSelectInstructPreset,
|
autoSelectInstructPreset,
|
||||||
formatInstructModeSystemPrompt,
|
formatInstructModeSystemPrompt,
|
||||||
|
selectInstructPreset,
|
||||||
|
instruct_presets,
|
||||||
|
selectContextPreset,
|
||||||
} from './scripts/instruct-mode.js';
|
} from './scripts/instruct-mode.js';
|
||||||
import { applyLocale, initLocales } from './scripts/i18n.js';
|
import { applyLocale, initLocales } from './scripts/i18n.js';
|
||||||
import { getFriendlyTokenizerName, getTokenCount, getTokenizerModel, initTokenizers, saveTokenCache } from './scripts/tokenizers.js';
|
import { getFriendlyTokenizerName, getTokenCount, getTokenizerModel, initTokenizers, saveTokenCache } from './scripts/tokenizers.js';
|
||||||
@ -7401,6 +7405,54 @@ const CONNECT_API_MAP = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function selectContextCallback(_, name) {
|
||||||
|
if (!name) {
|
||||||
|
toastr.warning('Context preset name is required');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const contextNames = context_presets.map(preset => preset.name);
|
||||||
|
const fuse = new Fuse(contextNames);
|
||||||
|
const result = fuse.search(name);
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
toastr.warning(`Context preset "${name}" not found`);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const foundName = result[0].item;
|
||||||
|
selectContextPreset(foundName);
|
||||||
|
return foundName;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function selectInstructCallback(_, name) {
|
||||||
|
if (!name) {
|
||||||
|
toastr.warning('Instruct preset name is required');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const instructNames = instruct_presets.map(preset => preset.name);
|
||||||
|
const fuse = new Fuse(instructNames);
|
||||||
|
const result = fuse.search(name);
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
toastr.warning(`Instruct preset "${name}" not found`);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const foundName = result[0].item;
|
||||||
|
selectInstructPreset(foundName);
|
||||||
|
return foundName;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function enableInstructCallback() {
|
||||||
|
$('#instruct_enabled').prop('checked', true).trigger('change');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function disableInstructCallback() {
|
||||||
|
$('#instruct_enabled').prop('checked', false).trigger('change');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} text API name
|
* @param {string} text API name
|
||||||
*/
|
*/
|
||||||
@ -7698,6 +7750,10 @@ jQuery(async function () {
|
|||||||
registerSlashCommand('closechat', doCloseChat, [], '– closes the current chat', true, true);
|
registerSlashCommand('closechat', doCloseChat, [], '– closes the current chat', true, true);
|
||||||
registerSlashCommand('panels', doTogglePanels, ['togglepanels'], '– toggle UI panels on/off', true, true);
|
registerSlashCommand('panels', doTogglePanels, ['togglepanels'], '– toggle UI panels on/off', true, true);
|
||||||
registerSlashCommand('forcesave', doForceSave, [], '– forces a save of the current chat and settings', true, true);
|
registerSlashCommand('forcesave', doForceSave, [], '– forces a save of the current chat and settings', true, true);
|
||||||
|
registerSlashCommand('instruct', selectInstructCallback, [], '<span class="monospace">(name)</span> – selects instruct mode preset by name', true, true);
|
||||||
|
registerSlashCommand('instruct-on', enableInstructCallback, [], '– enables instruct mode', true, true);
|
||||||
|
registerSlashCommand('instruct-off', disableInstructCallback, [], '– disables instruct mode', true, true);
|
||||||
|
registerSlashCommand('context', selectContextCallback, [], '<span class="monospace">(name)</span> – selects context template by name', true, true);
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$('#groupControlsToggle').trigger('click');
|
$('#groupControlsToggle').trigger('click');
|
||||||
|
@ -83,7 +83,7 @@ function highlightDefaultPreset() {
|
|||||||
* Select context template if not already selected.
|
* Select context template if not already selected.
|
||||||
* @param {string} preset Preset name.
|
* @param {string} preset Preset name.
|
||||||
*/
|
*/
|
||||||
function selectContextPreset(preset) {
|
export function selectContextPreset(preset) {
|
||||||
// If context template is not already selected, select it
|
// If context template is not already selected, select it
|
||||||
if (preset !== power_user.context.preset) {
|
if (preset !== power_user.context.preset) {
|
||||||
$('#context_presets').val(preset).trigger('change');
|
$('#context_presets').val(preset).trigger('change');
|
||||||
|
Reference in New Issue
Block a user