Add auto-select for instruct presets. Re-organize instruct mode code. Prepare for preset manager integration

This commit is contained in:
Cohee
2023-08-20 23:29:43 +03:00
parent 01cdcfa198
commit 6738ffe2a4
6 changed files with 289 additions and 199 deletions

View File

@ -66,9 +66,6 @@ import {
power_user,
pygmalion_options,
tokenizers,
formatInstructModeChat,
formatInstructStoryString,
formatInstructModePrompt,
persona_description_positions,
loadMovingUIState,
getCustomStoppingStrings,
@ -165,6 +162,13 @@ import { deviceInfo } from "./scripts/RossAscends-mods.js";
import { registerPromptManagerMigration } from "./scripts/PromptManager.js";
import { getRegexedString, regex_placement } from "./scripts/extensions/regex/engine.js";
import { FILTER_TYPES, FilterHelper } from "./scripts/filters.js";
import {
formatInstructModeChat,
formatInstructModePrompt,
getInstructStoppingSequences,
formatInstructStoryString,
autoSelectInstructPreset,
} from "./scripts/instruct-mode.js";
//exporting functions and vars for mods
export {
@ -330,7 +334,6 @@ let scrollLock = false;
const durationSaveEdit = 1000;
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
export const saveCharacterDebounced = debounce(() => $("#create_button").trigger('click'), durationSaveEdit);
const getStatusDebounced = debounce(() => getStatus(), 300_000);
const saveChatDebounced = debounce(() => saveChatConditional(), durationSaveEdit);
const system_message_types = {
@ -884,10 +887,6 @@ async function getStatus() {
const hordeStatus = await checkHordeStatus();
online_status = hordeStatus ? 'Connected' : 'no_connection';
resultCheckStatus();
if (online_status !== "no_connection") {
getStatusDebounced();
}
}
catch {
online_status = "no_connection";
@ -916,6 +915,10 @@ async function getStatus() {
if (online_status == undefined) {
online_status = "no_connection";
}
// Determine instruct mode preset
autoSelectInstructPreset(online_status);
if ((online_status.toLowerCase().indexOf("pygmalion") != -1 && power_user.pygmalion_formatting == pygmalion_options.AUTO)
|| (online_status !== "no_connection" && power_user.pygmalion_formatting == pygmalion_options.ENABLED)) {
is_pygmalion = true;
@ -937,9 +940,6 @@ async function getStatus() {
//console.log(online_status);
resultCheckStatus();
if (online_status !== "no_connection") {
getStatusDebounced();
}
},
error: function (jqXHR, exception) {
console.log(exception);
@ -1913,32 +1913,7 @@ function getStoppingStrings(isImpersonate, addSpace) {
}
}
function addInstructSequence(sequence) {
// Cohee: oobabooga's textgen always appends newline before the sequence as a stopping string
// But it's a problem for Metharme which doesn't use newlines to separate them.
const wrap = (s) => power_user.instruct.wrap ? '\n' + s : s;
// Sequence must be a non-empty string
if (typeof sequence === 'string' && sequence.length > 0) {
// If sequence is just a whitespace or newline - we don't want to make it a stopping string
// User can always add it as a custom stop string if really needed
if (sequence.trim().length > 0) {
const wrappedSequence = wrap(sequence);
// Need to respect "insert macro" setting
const stopString = power_user.instruct.macro ? substituteParams(wrappedSequence) : wrappedSequence;
result.push(stopString);
}
}
}
if (power_user.instruct.enabled) {
const input_sequence = power_user.instruct.input_sequence;
const output_sequence = power_user.instruct.output_sequence;
const last_output_sequence = power_user.instruct.last_output_sequence;
const combined_sequence = `${input_sequence}\n${output_sequence}\n${last_output_sequence}`;
combined_sequence.split('\n').filter((line, index, self) => self.indexOf(line) === index).forEach(addInstructSequence);
}
result.push(...getInstructStoppingSequences());
if (power_user.custom_stopping_strings) {
const customStoppingStrings = getCustomStoppingStrings();