Merge pull request #1017 from StefanDanielSchwarz/improved-instruct-mode-sequences

improved instruct mode sequences and UI
This commit is contained in:
Cohee 2023-08-26 01:03:38 +03:00 committed by GitHub
commit fabba9370b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 214 additions and 104 deletions

View File

@ -139,8 +139,10 @@
"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:",
"output_sequence": "\n### Response:",
"first_output_sequence": "",
"last_output_sequence": "\n### Response (2 paragraphs, engaging, natural, authentic, descriptive, creative):",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "",
"wrap": true,

View File

@ -140,9 +140,13 @@
"Wrap Sequences with Newline": "用换行符换行序列",
"Include Names": "包括名称",
"System Prompt": "系统提示",
"Instruct Mode Sequences": "指令模式序列",
"Input Sequence": "输入序列",
"Output Sequence": "输出序列",
"System Sequence": "系统顺序",
"First Output Sequence": "第一个输出序列",
"Last Output Sequence": "最后输出序列",
"System Sequence Prefix": "系统序列前缀",
"System Sequence Suffix": "系统序列后缀",
"Stop Sequence": "停止序列",
"Context Formatting": "上下文格式",
"Tokenizer": "分词器",
@ -693,9 +697,12 @@
"Wrap Sequences with Newline": "シーケンスを改行でラップする",
"Include Names": "名前を含める",
"System Prompt": "システムプロンプト",
"Instruct Mode Sequences": "命令モードシーケンス",
"Input Sequence": "入力シーケンス",
"Output Sequence": "出力シーケンス",
"System Sequence": "システムシーケンス",
"First Output Sequence": "最初の出力シーケンス",
"Last Output Sequence": "最後の出力シーケンス",
"System Sequence Prefix": "システムシーケンスプレフィックス",
"System Sequence Suffix": "システムシーケンスサフィックス",
"Stop Sequence": "停止シーケンス",
"Context Formatting": "コンテキストフォーマッティング",
"Tokenizer": "トークナイザー",
@ -1248,9 +1255,12 @@
"Wrap Sequences with Newline": "배열 명령 양 끝에 줄바꿈 삽입",
"Include Names": "이름 포함",
"System Prompt": "시스템 프롬프트",
"Instruct Mode Sequences": "지시 모드 순서",
"Input Sequence": "입력 배열",
"Output Sequence": "출력 배열",
"System Sequence": "시스템 배열",
"First Output Sequence": "첫 번째 출력 시퀀스",
"Last Output Sequence": "마지막 출력 순서",
"System Sequence Prefix": "시스템 시퀀스 접두사",
"System Sequence Suffix": "시스템 시퀀스 접미사",
"Stop Sequence": "정지 배열",
"Context Formatting": "맥락 서식",
"Tokenizer": "토큰화 장치",
@ -1807,9 +1817,12 @@
"Wrap Sequences with Newline": "Отделять последовательности красной строкой",
"Include Names": "Показывать имена",
"System Prompt": "Системная инструкция",
"Instruct Mode Sequences": "Последовательности режима обучения",
"Input Sequence": "Input Sequence",
"Output Sequence": "Output Sequence",
"System Sequence": "System Sequence",
"First Output Sequence": "Первая выходная последовательность",
"Last Output Sequence": "Последняя выходная последовательность",
"System Sequence Prefix": "Префикс системной последовательности",
"System Sequence Suffix": "Суффикс системной последовательности",
"Stop Sequence": "Stop Sequence",
"Context Formatting": "Форматирование контекста",
"Tokenizer": "Токенайзер",
@ -2363,9 +2376,12 @@
"Wrap Sequences with Newline": "Ogni sequenza viene rimandata a capo",
"Include Names": "Includi i nomi",
"System Prompt": "Prompt di sistema",
"Instruct Mode Sequences": "Sequenze in modalità istruzione",
"Input Sequence": "Sequenza di input",
"Output Sequence": "Sequenza di output",
"System Sequence": "Sequenza di sistema",
"First Output Sequence": "Prima sequenza di output",
"Last Output Sequence": "Ultima sequenza di output",
"System Sequence Prefix": "Prefisso sequenza di sistema",
"System Sequence Suffix": "Suffisso della sequenza del sistema",
"Stop Sequence": "Sequenza d'arresto",
"Context Formatting": "Formattazione del contesto",
"Tokenizer": "Tokenizer",
@ -3044,9 +3060,12 @@
"Wrap Sequences with Newline": "Wikkel sequenties in met een nieuwe regel",
"Include Names": "Inclusief namen",
"System Prompt": "Systeemprompt",
"Instruct Mode Sequences": "Instrueermodusreeksen",
"Input Sequence": "Invoersequentie",
"Output Sequence": "Uitvoersequentie",
"System Sequence": "Systeemsequentie",
"First Output Sequence": "Eerste uitvoerreeks",
"Last Output Sequence": "Laatste uitvoerreeks",
"System Sequence Prefix": "Systeemreeksvoorvoegsel",
"System Sequence Suffix": "Systeemreeksachtervoegsel",
"Stop Sequence": "Stopsequentie",
"Context Formatting": "Contextopmaak",
"Tokenizer": "Tokenizer",

View File

@ -2097,14 +2097,14 @@
<label for="context_story_string">
<small data-i18n="Story String">Story String</small>
</label>
<textarea id="context_story_string" class="text_pole textarea_compact" rows="6"></textarea>
<textarea id="context_story_string" class="text_pole textarea_compact autoSetHeight" rows="1"></textarea>
<div class="flex-container">
<div class="flex1">
<label for="context_example_separator">
<small data-i18n="Example Separator">Example Separator</small>
</label>
<div>
<textarea id="context_example_separator" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="context_example_separator" class="text_pole textarea_compact autoSetHeight" maxlength="500" rows="1"></textarea>
</div>
</div>
<div class="flex1">
@ -2112,7 +2112,7 @@
<small data-i18n="Chat Start">Chat Start</small>
</label>
<div>
<textarea id="context_chat_start" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="context_chat_start" class="text_pole textarea_compact autoSetHeight" maxlength="500" rows="1"></textarea>
</div>
</div>
</div>
@ -2150,7 +2150,7 @@
</small>
</label>
<div>
<textarea id="instruct_activation_regex" class="text_pole textarea_compact" maxlength="5000" rows="1"></textarea>
<textarea id="instruct_activation_regex" class="text_pole textarea_compact autoSetHeight" maxlength="5000" rows="1"></textarea>
</div>
<div>
<label for="instruct_wrap" class="checkbox_label">
@ -2175,59 +2175,89 @@
<div class="prompt_overridden">
Overridden by the Character Definitions.
</div>
<textarea id="instruct_system_prompt" class="text_pole textarea_compact" rows="4"></textarea>
<div class="flex-container">
<div class="flex1">
<label for="instruct_input_sequence">
<small data-i18n="Input Sequence">Input Sequence</small>
</label>
<div>
<textarea id="instruct_input_sequence" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
</div>
<textarea id="instruct_system_prompt" class="text_pole textarea_compact autoSetHeight" rows="1"></textarea>
<div class="inline-drawer wide100p flexFlowColumn">
<div class="inline-drawer-toggle inline-drawer-header">
<b><span data-i18n="Instruct Mode Sequences">Instruct Mode Sequences</span></b>
<div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
</div>
<div class="flex1">
<label for="instruct_output_sequence">
<small data-i18n="Output Sequence">Output Sequence</small>
</label>
<div>
<textarea id="instruct_output_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
<div class="inline-drawer-content">
<div class="flex-container">
<div class="flex1">
<label for="instruct_input_sequence">
<small data-i18n="Input Sequence">Input Sequence</small>
</label>
<div>
<textarea id="instruct_input_sequence" class="text_pole textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_output_sequence">
<small data-i18n="Output Sequence">Output Sequence</small>
</label>
<div>
<textarea id="instruct_output_sequence" class="text_pole wide100p textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
</div>
</div>
<div class="flex1">
<label for="instruct_last_output_sequence">
<small data-i18n="Last Sequence">Last Sequence</small>
</label>
<div>
<textarea id="instruct_last_output_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
</div>
</div>
</div>
<div class="flex-container">
<div class="flex1">
<label for="instruct_system_sequence">
<small data-i18n="System Sequence">System Sequence</small>
</label>
<div>
<textarea id="instruct_system_sequence" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_stop_sequence">
<small data-i18n="Stop Sequence">Stop Sequence</small>
</label>
<div>
<textarea id="instruct_stop_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_separator_sequence">
<small data-i18n="Separator">Separator</small>
</label>
<div>
<textarea id="instruct_separator_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
<div class="flex-container">
<div class="flex1">
<label for="instruct_first_output_sequence">
<small data-i18n="First Output Sequence">First Output Sequence</small>
</label>
<div>
<textarea id="instruct_first_output_sequence" class="text_pole textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_last_output_sequence">
<small data-i18n="Last Output Sequence">Last Output Sequence</small>
</label>
<div>
<textarea id="instruct_last_output_sequence" class="text_pole wide100p textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
</div>
<div class="flex-container">
<div class="flex1">
<label for="instruct_system_sequence_prefix">
<small data-i18n="System Sequence Prefix">System Sequence Prefix</small>
</label>
<div>
<textarea id="instruct_system_sequence_prefix" class="text_pole textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_system_sequence_suffix">
<small data-i18n="System Sequence Suffix">System Sequence Suffix</small>
</label>
<div>
<textarea id="instruct_system_sequence_suffix" class="text_pole wide100p textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
</div>
<div class="flex-container">
<div class="flex1">
<label for="instruct_stop_sequence">
<small data-i18n="Stop Sequence">Stop Sequence</small>
</label>
<div>
<textarea id="instruct_stop_sequence" class="text_pole textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_separator_sequence">
<small data-i18n="Separator">Separator</small>
</label>
<div>
<textarea id="instruct_separator_sequence" class="text_pole wide100p textarea_compact autoSetHeight" maxlength="500" placeholder="&mdash;" rows="1"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div name="ContextFormatting" class="flex1">

View File

@ -3,8 +3,10 @@
"system_prompt": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n",
"input_sequence": "### Instruction:",
"output_sequence": "### Response:",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "",
"wrap": true,

View File

@ -3,8 +3,10 @@
"system_prompt": "Write {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n",
"input_sequence": "USER: ",
"output_sequence": "GPT: ",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "BEGINNING OF CONVERSATION: ",
"system_sequence_prefix": "BEGINNING OF CONVERSATION: ",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "</s>",
"wrap": false,

View File

@ -3,8 +3,10 @@
"system_prompt": "Write {{char}}'s next reply in this fictional roleplay with {{user}}.",
"input_sequence": "[INST] ",
"output_sequence": " [/INST] ",
"first_output_sequence": "[/INST] ",
"last_output_sequence": "",
"system_sequence": "[INST] <<SYS>>\n{{sys}}\n<</SYS>>\n",
"system_sequence_prefix": "[INST] <<SYS>>\n",
"system_sequence_suffix": "\n<</SYS>>\n",
"stop_sequence": "",
"separator_sequence": "\n",
"wrap": false,

View File

@ -3,8 +3,10 @@
"system_prompt": "Enter roleplay mode. You must act as {{char}}, whose persona follows:",
"input_sequence": "<|user|>",
"output_sequence": "<|model|>",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "<|system|>",
"system_sequence_prefix": "<|system|>",
"system_sequence_suffix": "",
"stop_sequence": "</s>",
"separator_sequence": "",
"wrap": false,

View File

@ -3,8 +3,10 @@
"system_prompt": "You are a helpful assistant. Please answer truthfully and write out your thinking step by step to be sure you get the right answer. If you make a mistake or encounter an error in your thinking, say so out loud and attempt to correct it. If you don't know or aren't sure about something, say so clearly. You will act as a professional logician, mathematician, and physicist. You will also act as the most appropriate type of expert to answer any particular question or solve the relevant problem; state which expert type your are, if so. Also think of any particular named expert that would be ideal to answer the relevant question or solve the relevant problem; name and act as them, if appropriate.\n",
"input_sequence": "User: ",
"output_sequence": "<|end_of_turn|>\nAssistant: ",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "<|end_of_turn|>\n",
"wrap": false,

View File

@ -3,8 +3,10 @@
"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:",
"output_sequence": "\n### Response:",
"first_output_sequence": "",
"last_output_sequence": "\n### Response (2 paragraphs, engaging, natural, authentic, descriptive, creative):",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "",
"wrap": true,

View File

@ -3,8 +3,10 @@
"system_prompt": "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n",
"input_sequence": "### Human:",
"output_sequence": "### Assistant:",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "",
"wrap": true,

View File

@ -3,8 +3,10 @@
"system_prompt": "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n",
"input_sequence": "\nUSER: ",
"output_sequence": "\nASSISTANT: ",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "BEGINNING OF CONVERSATION:",
"system_sequence_prefix": "BEGINNING OF CONVERSATION:",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "</s>",
"wrap": false,

View File

@ -3,8 +3,10 @@
"system_prompt": "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n\nWrite {{char}}'s next detailed reply in a fictional roleplay chat between {{user}} and {{char}}.",
"input_sequence": "USER: ",
"output_sequence": "ASSISTANT: ",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "",
"wrap": true,

View File

@ -3,8 +3,10 @@
"system_prompt": "Write {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n",
"input_sequence": "",
"output_sequence": "### Response:",
"first_output_sequence": "",
"last_output_sequence": "",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "</s>",
"wrap": true,

View File

@ -3,8 +3,10 @@
"system_prompt": "[System note: Write one reply only. Do not decide what {{user}} says or does. Write at least one paragraph, up to four. Be descriptive and immersive, providing vivid details about {{char}}'s actions, emotions, and the environment. Write with a high degree of complexity and burstiness. Do not repeat this message.]",
"input_sequence": "### Instruction:\n#### {{user}}:",
"output_sequence": "### Response:\n#### {{char}}:",
"first_output_sequence": "",
"last_output_sequence": "### Response (2 paragraphs, engaging, natural, authentic, descriptive, creative):\n#### {{char}}:",
"system_sequence": "",
"system_sequence_prefix": "",
"system_sequence_suffix": "",
"stop_sequence": "",
"separator_sequence": "",
"wrap": true,

View File

@ -132,6 +132,7 @@ import {
PAGINATION_TEMPLATE,
waitUntilCondition,
escapeRegex,
resetScrollHeight,
} from "./scripts/utils.js";
import { extension_settings, getContext, loadExtensionSettings, processExtensionHelpers, registerExtensionHelper, runGenerationInterceptors, saveMetadataDebounced } from "./scripts/extensions.js";
@ -163,6 +164,7 @@ import { getRegexedString, regex_placement } from "./scripts/extensions/regex/en
import { FILTER_TYPES, FilterHelper } from "./scripts/filters.js";
import { getCfgPrompt, getGuidanceScale } from "./scripts/extensions/cfg/util.js";
import {
force_output_sequence,
formatInstructModeChat,
formatInstructModePrompt,
formatInstructModeExamples,
@ -2437,11 +2439,16 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, false);
if (j === 0 && isInstruct) {
// Reformat with the first output sequence (if any)
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.FIRST);
}
// Do not suffix the message for continuation
if (i === 0 && isContinue) {
if (isInstruct) {
// Reformat with the last output line (if any)
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, true);
// Reformat with the last output sequence (if any)
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, force_output_sequence.LAST);
}
chat2[i] = chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length);
@ -3234,9 +3241,9 @@ export function getBiasStrings(textareaText, type) {
/**
* @param {Object} chatItem Message history item.
* @param {boolean} isInstruct Whether instruct mode is enabled.
* @param {boolean} forceLastOutputSequence Whether to force the last output sequence for instruct mode.
* @param {boolean|number} forceOutputSequence Whether to force the first/last output sequence for instruct mode.
*/
function formatMessageHistoryItem(chatItem, isInstruct, forceLastOutputSequence) {
function formatMessageHistoryItem(chatItem, isInstruct, forceOutputSequence) {
const isNarratorType = chatItem?.extra?.type === system_message_types.NARRATOR;
const characterName = (selected_group || chatItem.force_avatar) ? chatItem.name : name2;
const itemName = chatItem.is_user ? chatItem['name'] : characterName;
@ -3245,7 +3252,7 @@ function formatMessageHistoryItem(chatItem, isInstruct, forceLastOutputSequence)
let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`;
if (isInstruct) {
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2, forceLastOutputSequence);
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2, forceOutputSequence);
}
textResult = replaceBiasMarkup(textResult);
@ -8624,6 +8631,10 @@ $(document).ready(function () {
});
}
// Set the height of "autoSetHeight" textareas within the drawer to their scroll height
$(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(function() {
resetScrollHeight($(this));
});
} else if (drawerWasOpenAlready) { //to close manually
icon.toggleClass('closedIcon openIcon');
@ -8690,6 +8701,11 @@ $(document).ready(function () {
icon.toggleClass('down up');
icon.toggleClass('fa-circle-chevron-down fa-circle-chevron-up');
$(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle();
// Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
$(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(function() {
resetScrollHeight($(this));
});
});
$(document).on('click', '.mes .avatar', function () {

View File

@ -6,6 +6,7 @@ import {
power_user,
context_presets,
} from "./power-user.js";
import { resetScrollHeight } from "./utils.js";
/**
* @type {any[]} Instruct mode presets.
@ -16,7 +17,8 @@ const controls = [
{ id: "instruct_enabled", property: "enabled", isCheckbox: true },
{ id: "instruct_wrap", property: "wrap", isCheckbox: true },
{ id: "instruct_system_prompt", property: "system_prompt", isCheckbox: false },
{ id: "instruct_system_sequence", property: "system_sequence", isCheckbox: false },
{ id: "instruct_system_sequence_prefix", property: "system_sequence_prefix", isCheckbox: false },
{ id: "instruct_system_sequence_suffix", property: "system_sequence_suffix", isCheckbox: false },
{ id: "instruct_separator_sequence", property: "separator_sequence", isCheckbox: false },
{ id: "instruct_input_sequence", property: "input_sequence", isCheckbox: false },
{ id: "instruct_output_sequence", property: "output_sequence", isCheckbox: false },
@ -24,6 +26,7 @@ const controls = [
{ id: "instruct_names", property: "names", isCheckbox: true },
{ id: "instruct_macro", property: "macro", isCheckbox: true },
{ id: "instruct_names_force_groups", property: "names_force_groups", isCheckbox: true },
{ id: "instruct_first_output_sequence", property: "first_output_sequence", isCheckbox: false },
{ id: "instruct_last_output_sequence", property: "last_output_sequence", isCheckbox: false },
{ id: "instruct_activation_regex", property: "activation_regex", isCheckbox: false },
];
@ -53,6 +56,9 @@ export function loadInstructMode(data) {
$element.on('input', function () {
power_user.instruct[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
saveSettingsDebounced();
if (!control.isCheckbox) {
resetScrollHeight($element);
}
});
});
@ -200,9 +206,10 @@ export function getInstructStoppingSequences() {
if (power_user.instruct.enabled) {
const input_sequence = power_user.instruct.input_sequence;
const output_sequence = power_user.instruct.output_sequence;
const first_output_sequence = power_user.instruct.first_output_sequence;
const last_output_sequence = power_user.instruct.last_output_sequence;
const combined_sequence = `${input_sequence}\n${output_sequence}\n${last_output_sequence}`;
const combined_sequence = `${input_sequence}\n${output_sequence}\n${first_output_sequence}\n${last_output_sequence}`;
combined_sequence.split('\n').filter((line, index, self) => self.indexOf(line) === index).forEach(addInstructSequence);
}
@ -210,6 +217,11 @@ export function getInstructStoppingSequences() {
return result;
}
export const force_output_sequence = {
FIRST: 1,
LAST: 2,
}
/**
* Formats instruct mode chat message.
* @param {string} name Character name.
@ -219,10 +231,10 @@ export function getInstructStoppingSequences() {
* @param {string} forceAvatar Force avatar string.
* @param {string} name1 User name.
* @param {string} name2 Character name.
* @param {boolean} forceLastOutputSequence Force to use last outline sequence (if configured).
* @param {boolean|number} forceOutputSequence Force to use first/last output sequence (if configured).
* @returns {string} Formatted instruct mode chat message.
*/
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2, forceLastOutputSequence) {
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2, forceOutputSequence) {
let includeNames = isNarrator ? false : power_user.instruct.names;
if (!isNarrator && power_user.instruct.names_force_groups && (selected_group || forceAvatar)) {
@ -231,8 +243,12 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
let sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
if (sequence === power_user.instruct.output_sequence && forceLastOutputSequence && power_user.instruct.last_output_sequence) {
sequence = power_user.instruct.last_output_sequence;
if (forceOutputSequence && sequence === power_user.instruct.output_sequence) {
if (forceOutputSequence === force_output_sequence.FIRST && power_user.instruct.first_output_sequence) {
sequence = power_user.instruct.first_output_sequence;
} else if (forceOutputSequence === force_output_sequence.LAST && power_user.instruct.last_output_sequence) {
sequence = power_user.instruct.last_output_sequence;
}
}
if (power_user.instruct.macro) {
@ -254,14 +270,14 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
* @returns {string} Formatted instruct mode system prompt.
*/
export function formatInstructModeSystemPrompt(systemPrompt){
if (power_user.instruct.system_sequence) {
const separator = power_user.instruct.wrap ? '\n' : '';
const separator = power_user.instruct.wrap ? '\n' : '';
if (power_user.instruct.system_sequence.includes("{{sys}}")) {
return power_user.instruct.system_sequence.replace(/{{sys}}/gi, systemPrompt);
} else {
return power_user.instruct.system_sequence + separator + systemPrompt;
}
if (power_user.instruct.system_sequence_prefix) {
systemPrompt = power_user.instruct.system_sequence_prefix + separator + systemPrompt;
}
if (power_user.instruct.system_sequence_suffix) {
systemPrompt = systemPrompt + separator + power_user.instruct.system_sequence_suffix;
}
return systemPrompt;

View File

@ -29,7 +29,7 @@ import {
import { registerSlashCommand } from "./slash-commands.js";
import { tokenizers } from "./tokenizers.js";
import { delay } from "./utils.js";
import { delay, resetScrollHeight } from "./utils.js";
export {
loadPowerUserSettings,
@ -159,19 +159,21 @@ let power_user = {
default_instruct: '',
instruct: {
enabled: false,
preset: "Alpaca",
system_prompt: "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.\n",
input_sequence: "### Instruction:",
output_sequence: "### Response:",
first_output_sequence: "",
last_output_sequence: "",
system_sequence_prefix: "",
system_sequence_suffix: "",
stop_sequence: "",
separator_sequence: "",
wrap: true,
macro: true,
names: false,
system_prompt: "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}. Write 1 reply only.",
system_sequence: '',
stop_sequence: '',
input_sequence: '### Instruction:',
output_sequence: '### Response:',
last_output_sequence: '',
preset: 'Alpaca',
separator_sequence: '',
macro: false,
names_force_groups: true,
activation_regex: '',
activation_regex: "",
},
context: {
@ -904,6 +906,9 @@ function loadContextSettings() {
$element.on('input', function () {
power_user.context[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
saveSettingsDebounced();
if (!control.isCheckbox) {
resetScrollHeight($element);
}
});
});