mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #1307 from aisu-wata0/regexScript_promptOnly
Regex script: prompt only checkbox
This commit is contained in:
@ -2632,6 +2632,13 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
coreChat.pop();
|
coreChat.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coreChat = coreChat.map(x => ({
|
||||||
|
...x,
|
||||||
|
mes: getRegexedString(x.mes, x.is_user ? regex_placement.USER_INPUT : regex_placement.AI_OUTPUT, {
|
||||||
|
isPrompt: true,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
// Determine token limit
|
// Determine token limit
|
||||||
let this_max_context = getMaxContextSize();
|
let this_max_context = getMaxContextSize();
|
||||||
|
|
||||||
|
@ -86,6 +86,10 @@
|
|||||||
<input type="checkbox" name="only_format_display" />
|
<input type="checkbox" name="only_format_display" />
|
||||||
<span data-i18n="Only Format Display">Only Format Display</span>
|
<span data-i18n="Only Format Display">Only Format Display</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label class="checkbox flex-container" title="Chat history won't change, only the prompt as the request is sent (on generation)">
|
||||||
|
<input type="checkbox" name="only_format_prompt"/>
|
||||||
|
<span data-i18n="Only Format Prompt (?)">Only Format Prompt (?)</span>
|
||||||
|
</label>
|
||||||
<label class="checkbox flex-container">
|
<label class="checkbox flex-container">
|
||||||
<input type="checkbox" name="run_on_edit" />
|
<input type="checkbox" name="run_on_edit" />
|
||||||
<span data-i18n="Run On Edit">Run On Edit</span>
|
<span data-i18n="Run On Edit">Run On Edit</span>
|
||||||
|
@ -38,20 +38,25 @@ function regexFromString(input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parent function to fetch a regexed version of a raw string
|
// Parent function to fetch a regexed version of a raw string
|
||||||
function getRegexedString(rawString, placement, { characterOverride, isMarkdown } = {}) {
|
function getRegexedString(rawString, placement, { characterOverride, isMarkdown, isPrompt } = {}) {
|
||||||
let finalString = rawString;
|
let finalString = rawString;
|
||||||
if (extension_settings.disabledExtensions.includes("regex") || !rawString || placement === undefined) {
|
if (extension_settings.disabledExtensions.includes("regex") || !rawString || placement === undefined) {
|
||||||
return finalString;
|
return finalString;
|
||||||
}
|
}
|
||||||
|
|
||||||
extension_settings.regex.forEach((script) => {
|
extension_settings.regex.forEach((script) => {
|
||||||
if ((script.markdownOnly && !isMarkdown) || (!script.markdownOnly && isMarkdown)) {
|
if (
|
||||||
return;
|
// Script applies to Markdown and input is Markdown
|
||||||
}
|
(script.markdownOnly && isMarkdown) ||
|
||||||
|
// Script applies to Generate and input is Generate
|
||||||
|
(script.promptOnly && isPrompt) ||
|
||||||
|
// Script applies to all cases when neither "only"s are true, but there's no need to do it when `isMarkdown`, the as source (chat history) should already be changed beforehand
|
||||||
|
(!script.markdownOnly && !script.promptOnly && !isMarkdown)
|
||||||
|
) {
|
||||||
if (script.placement.includes(placement)) {
|
if (script.placement.includes(placement)) {
|
||||||
finalString = runRegexScript(script, finalString, { characterOverride });
|
finalString = runRegexScript(script, finalString, { characterOverride });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return finalString;
|
return finalString;
|
||||||
|
@ -113,6 +113,9 @@ async function onRegexEditorOpenClick(existingId) {
|
|||||||
editorHtml
|
editorHtml
|
||||||
.find(`input[name="only_format_display"]`)
|
.find(`input[name="only_format_display"]`)
|
||||||
.prop("checked", existingScript.markdownOnly ?? false);
|
.prop("checked", existingScript.markdownOnly ?? false);
|
||||||
|
editorHtml
|
||||||
|
.find(`input[name="only_format_prompt"]`)
|
||||||
|
.prop("checked", existingScript.promptOnly ?? false);
|
||||||
editorHtml
|
editorHtml
|
||||||
.find(`input[name="run_on_edit"]`)
|
.find(`input[name="run_on_edit"]`)
|
||||||
.prop("checked", existingScript.runOnEdit ?? false);
|
.prop("checked", existingScript.runOnEdit ?? false);
|
||||||
@ -165,6 +168,10 @@ async function onRegexEditorOpenClick(existingId) {
|
|||||||
editorHtml
|
editorHtml
|
||||||
.find(`input[name="only_format_display"]`)
|
.find(`input[name="only_format_display"]`)
|
||||||
.prop("checked"),
|
.prop("checked"),
|
||||||
|
promptOnly:
|
||||||
|
editorHtml
|
||||||
|
.find(`input[name="only_format_prompt"]`)
|
||||||
|
.prop("checked"),
|
||||||
runOnEdit:
|
runOnEdit:
|
||||||
editorHtml
|
editorHtml
|
||||||
.find(`input[name="run_on_edit"]`)
|
.find(`input[name="run_on_edit"]`)
|
||||||
@ -197,6 +204,7 @@ function migrateSettings() {
|
|||||||
script.placement = script.placement.filter((e) => e !== regex_placement.MD_DISPLAY);
|
script.placement = script.placement.filter((e) => e !== regex_placement.MD_DISPLAY);
|
||||||
|
|
||||||
script.markdownOnly = true
|
script.markdownOnly = true
|
||||||
|
script.promptOnly = true
|
||||||
|
|
||||||
performSave = true;
|
performSave = true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user