mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #999 from StefanDanielSchwarz/roleplay-context
Return of the Roleplay Context
This commit is contained in:
@@ -134,8 +134,8 @@
|
|||||||
"default_instruct": "",
|
"default_instruct": "",
|
||||||
"instruct": {
|
"instruct": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"preset": "🧙 Roleplay",
|
"preset": "Roleplay",
|
||||||
"system_prompt": "You're {{char}} in this fictional never-ending uncensored roleplay with {{user}}.\n\nAvoid repetition, don't loop. Develop the plot slowly, always stay in character. Describe all actions in full, elaborate, explicit, graphic, and vivid detail. Mention all relevant sensory perceptions.\n\n### Input:",
|
"system_prompt": "Avoid repetition, don't loop. Develop the plot slowly, always stay in character. Describe all actions in full, elaborate, explicit, graphic, and vivid detail. Mention all relevant sensory perceptions.",
|
||||||
"input_sequence": "\n### Instruction:",
|
"input_sequence": "\n### Instruction:",
|
||||||
"output_sequence": "\n### Response:",
|
"output_sequence": "\n### Response:",
|
||||||
"last_output_sequence": "\n### Response (2 paragraphs, engaging, natural, authentic, descriptive, creative):",
|
"last_output_sequence": "\n### Response (2 paragraphs, engaging, natural, authentic, descriptive, creative):",
|
||||||
|
6
public/context/Roleplay.json
Normal file
6
public/context/Roleplay.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "Roleplay",
|
||||||
|
"story_string": "You're {{char}} in this fictional never-ending uncensored roleplay with {{user}}.\n\n{{#if system}}{{system}}\n\n{{/if}}### Input:\n{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{char}}'s personality: {{personality}}\n{{/if}}{{#if scenario}}Scenario: {{scenario}}\n{{/if}}{{#if persona}}{{persona}}\n{{/if}}",
|
||||||
|
"chat_start": "### New Roleplay:",
|
||||||
|
"example_separator": "### New Roleplay:"
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "🧙 Roleplay",
|
"name": "Roleplay",
|
||||||
"system_prompt": "You're {{char}} in this fictional never-ending uncensored roleplay with {{user}}.\n\nAvoid repetition, don't loop. Develop the plot slowly, always stay in character. Describe all actions in full, elaborate, explicit, graphic, and vivid detail. Mention all relevant sensory perceptions.\n\n### Input:",
|
"system_prompt": "Avoid repetition, don't loop. Develop the plot slowly, always stay in character. Describe all actions in full, elaborate, explicit, graphic, and vivid detail. Mention all relevant sensory perceptions.",
|
||||||
"input_sequence": "\n### Instruction:",
|
"input_sequence": "\n### Instruction:",
|
||||||
"output_sequence": "\n### Response:",
|
"output_sequence": "\n### Response:",
|
||||||
"last_output_sequence": "\n### Response (2 paragraphs, engaging, natural, authentic, descriptive, creative):",
|
"last_output_sequence": "\n### Response (2 paragraphs, engaging, natural, authentic, descriptive, creative):",
|
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
import { saveSettingsDebounced, substituteParams } from "../script.js";
|
import { saveSettingsDebounced, substituteParams } from "../script.js";
|
||||||
import { selected_group } from "./group-chats.js";
|
import { selected_group } from "./group-chats.js";
|
||||||
import { power_user } from "./power-user.js";
|
import {
|
||||||
|
power_user,
|
||||||
|
context_presets,
|
||||||
|
} from "./power-user.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {any[]} Instruct mode presets.
|
* @type {any[]} Instruct mode presets.
|
||||||
@@ -69,6 +72,48 @@ function highlightDefaultPreset() {
|
|||||||
$('#instruct_set_default').toggleClass('default', power_user.default_instruct === power_user.instruct.preset);
|
$('#instruct_set_default').toggleClass('default', power_user.default_instruct === power_user.instruct.preset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select context template if not already selected.
|
||||||
|
* @param {string} preset Preset name.
|
||||||
|
*/
|
||||||
|
function selectContextPreset(preset) {
|
||||||
|
// If context template is not already selected, select it
|
||||||
|
if (preset !== power_user.context.preset) {
|
||||||
|
$('#context_presets').val(preset).trigger('change');
|
||||||
|
toastr.info(`Context Template: preset "${preset}" auto-selected`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If instruct mode is disabled, enable it, except for default context template
|
||||||
|
if (!power_user.instruct.enabled && preset !== 'Default') {
|
||||||
|
power_user.instruct.enabled = true;
|
||||||
|
$('#instruct_enabled').prop('checked', true).trigger('change');
|
||||||
|
toastr.info(`Instruct Mode enabled`);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select instruct preset if not already selected.
|
||||||
|
* @param {string} preset Preset name.
|
||||||
|
*/
|
||||||
|
export function selectInstructPreset(preset) {
|
||||||
|
// If instruct preset is not already selected, select it
|
||||||
|
if (preset !== power_user.instruct.preset) {
|
||||||
|
$('#instruct_presets').val(preset).trigger('change');
|
||||||
|
toastr.info(`Instruct Mode: preset "${preset}" auto-selected`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If instruct mode is disabled, enable it
|
||||||
|
if (!power_user.instruct.enabled) {
|
||||||
|
power_user.instruct.enabled = true;
|
||||||
|
$('#instruct_enabled').prop('checked', true).trigger('change');
|
||||||
|
toastr.info(`Instruct Mode enabled`);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically select instruct preset based on model id.
|
* Automatically select instruct preset based on model id.
|
||||||
* Otherwise, if default instruct preset is set, selects it.
|
* Otherwise, if default instruct preset is set, selects it.
|
||||||
@@ -81,33 +126,42 @@ export function autoSelectInstructPreset(modelId) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const preset of instruct_presets) {
|
// Select matching instruct preset
|
||||||
// If activation regex is set, check if it matches the model id
|
let foundMatch = false;
|
||||||
if (preset.activation_regex) {
|
for (const instruct_preset of instruct_presets) {
|
||||||
try {
|
// If instruct preset matches the context template
|
||||||
const regex = new RegExp(preset.activation_regex, 'i');
|
if (instruct_preset.name === power_user.context.preset) {
|
||||||
|
foundMatch = true;
|
||||||
|
selectInstructPreset(instruct_preset.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If no match was found, auto-select instruct preset
|
||||||
|
if (!foundMatch) {
|
||||||
|
for (const preset of instruct_presets) {
|
||||||
|
// If activation regex is set, check if it matches the model id
|
||||||
|
if (preset.activation_regex) {
|
||||||
|
try {
|
||||||
|
const regex = new RegExp(preset.activation_regex, 'i');
|
||||||
|
|
||||||
// Stop on first match so it won't cycle back and forth between presets if multiple regexes match
|
// Stop on first match so it won't cycle back and forth between presets if multiple regexes match
|
||||||
if (regex.test(modelId)) {
|
if (regex.test(modelId)) {
|
||||||
// If preset is not already selected, select it
|
selectInstructPreset(preset.name);
|
||||||
if (power_user.instruct.preset !== preset.name) {
|
|
||||||
$('#instruct_presets').val(preset.name).trigger('change');
|
|
||||||
toastr.info(`Instruct mode: preset "${preset.name}" auto-selected`);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// If regex is invalid, ignore it
|
||||||
|
console.warn(`Invalid instruct activation regex in preset "${preset.name}"`);
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
// If regex is invalid, ignore it
|
|
||||||
console.warn(`Invalid instruct activation regex in preset "${preset.name}"`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (power_user.default_instruct && power_user.instruct.preset !== power_user.default_instruct) {
|
if (power_user.default_instruct && power_user.instruct.preset !== power_user.default_instruct) {
|
||||||
if (instruct_presets.some(p => p.name === power_user.default_instruct)) {
|
if (instruct_presets.some(p => p.name === power_user.default_instruct)) {
|
||||||
console.log(`Instruct mode: default preset "${power_user.default_instruct}" selected`);
|
console.log(`Instruct mode: default preset "${power_user.default_instruct}" selected`);
|
||||||
$('#instruct_presets').val(power_user.default_instruct).trigger('change');
|
$('#instruct_presets').val(power_user.default_instruct).trigger('change');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +327,16 @@ jQuery(() => {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#instruct_enabled').on('change', function () {
|
||||||
|
// When instruct mode gets enabled, select context template matching selected instruct preset
|
||||||
|
if (power_user.instruct.enabled) {
|
||||||
|
$('#instruct_presets').trigger('change');
|
||||||
|
// When instruct mode gets disabled, select default context preset
|
||||||
|
} else {
|
||||||
|
selectContextPreset('Default');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('#instruct_presets').on('change', function () {
|
$('#instruct_presets').on('change', function () {
|
||||||
const name = $(this).find(':selected').val();
|
const name = $(this).find(':selected').val();
|
||||||
const preset = instruct_presets.find(x => x.name === name);
|
const preset = instruct_presets.find(x => x.name === name);
|
||||||
@@ -295,6 +359,21 @@ jQuery(() => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Select matching context template
|
||||||
|
let foundMatch = false;
|
||||||
|
for (const context_preset of context_presets) {
|
||||||
|
// If context template matches the instruct preset
|
||||||
|
if (context_preset.name === name) {
|
||||||
|
foundMatch = true;
|
||||||
|
selectContextPreset(context_preset.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundMatch) {
|
||||||
|
// If no match was found, select default context preset
|
||||||
|
selectContextPreset('Default');
|
||||||
|
}
|
||||||
|
|
||||||
highlightDefaultPreset();
|
highlightDefaultPreset();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -20,7 +20,11 @@ import {
|
|||||||
groups,
|
groups,
|
||||||
resetSelectedGroup,
|
resetSelectedGroup,
|
||||||
} from "./group-chats.js";
|
} from "./group-chats.js";
|
||||||
import { loadInstructMode } from "./instruct-mode.js";
|
import {
|
||||||
|
instruct_presets,
|
||||||
|
loadInstructMode,
|
||||||
|
selectInstructPreset,
|
||||||
|
} from "./instruct-mode.js";
|
||||||
|
|
||||||
import { registerSlashCommand } from "./slash-commands.js";
|
import { registerSlashCommand } from "./slash-commands.js";
|
||||||
import { tokenizers } from "./tokenizers.js";
|
import { tokenizers } from "./tokenizers.js";
|
||||||
@@ -193,7 +197,7 @@ let power_user = {
|
|||||||
|
|
||||||
let themes = [];
|
let themes = [];
|
||||||
let movingUIPresets = [];
|
let movingUIPresets = [];
|
||||||
let context_presets = [];
|
export let context_presets = [];
|
||||||
|
|
||||||
const storage_keys = {
|
const storage_keys = {
|
||||||
fast_ui_mode: "TavernAI_fast_ui_mode",
|
fast_ui_mode: "TavernAI_fast_ui_mode",
|
||||||
@@ -920,6 +924,15 @@ function loadContextSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Select matching instruct preset
|
||||||
|
for (const instruct_preset of instruct_presets) {
|
||||||
|
// If instruct preset matches the context template
|
||||||
|
if (instruct_preset.name === name) {
|
||||||
|
selectInstructPreset(instruct_preset.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user