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
17 changed files with 214 additions and 104 deletions

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 () {