mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-23 07:27:41 +01:00
Add continue postfix controls for Chat Completion
This commit is contained in:
parent
67e78fa456
commit
6665666098
@ -1656,6 +1656,28 @@
|
|||||||
<!-- Hidden input for loading radio buttons from presets. Don't remove! -->
|
<!-- Hidden input for loading radio buttons from presets. Don't remove! -->
|
||||||
<input type="hidden" id="names_behavior" class="displayNone" />
|
<input type="hidden" id="names_behavior" class="displayNone" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="range-block marginBot10">
|
||||||
|
<h4 class="range-block-title justifyLeft marginBot5 flex-container alignItemsCenter">
|
||||||
|
<span data-i18n="Continue Postfix">Continue Postfix</span>
|
||||||
|
<i class="right_menu_button fa-solid fa-circle-exclamation" title="The next chunk of the continued message will be appended using this as a separator."></i>
|
||||||
|
</h4>
|
||||||
|
<div class="flex-container flexFlowColumn">
|
||||||
|
<label class="checkbox_label flexWrap alignItemsCenter" for="continue_postfix_space">
|
||||||
|
<input type="radio" id="continue_postfix_space" name="continue_postfix" value="0">
|
||||||
|
<span data-i18n="Space">Space</span>
|
||||||
|
</label>
|
||||||
|
<label class="checkbox_label flexWrap alignItemsCenter" for="continue_postfix_newline">
|
||||||
|
<input type="radio" id="continue_postfix_newline" name="continue_postfix" value="1">
|
||||||
|
<span data-i18n="Newline">Newline</span>
|
||||||
|
</label>
|
||||||
|
<label class="checkbox_label flexWrap alignItemsCenter" for="continue_postfix_double_newline">
|
||||||
|
<input type="radio" id="continue_postfix_double_newline" name="continue_postfix" value="2">
|
||||||
|
<span data-i18n="Double Newline">Double Newline</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<!-- Hidden input for loading radio buttons from presets. Don't remove! -->
|
||||||
|
<input type="hidden" id="continue_postfix" class="displayNone" />
|
||||||
|
</div>
|
||||||
<div class="range-block">
|
<div class="range-block">
|
||||||
<label for="wrap_in_quotes" title="Wrap user messages in quotes before sending" data-i18n="[title]Wrap user messages in quotes before sending" class="checkbox_label widthFreeExpand">
|
<label for="wrap_in_quotes" title="Wrap user messages in quotes before sending" data-i18n="[title]Wrap user messages in quotes before sending" class="checkbox_label widthFreeExpand">
|
||||||
<input id="wrap_in_quotes" type="checkbox" /><span data-i18n="Wrap in Quotes">
|
<input id="wrap_in_quotes" type="checkbox" /><span data-i18n="Wrap in Quotes">
|
||||||
@ -5225,9 +5247,9 @@
|
|||||||
<input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
|
<input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
|
||||||
<span data-i18n="as">as</span>
|
<span data-i18n="as">as</span>
|
||||||
<select id="extension_floating_role" class="text_pole widthNatural">
|
<select id="extension_floating_role" class="text_pole widthNatural">
|
||||||
<option value="0">System</option>
|
<option data-i18n="System" value="0">System</option>
|
||||||
<option value="1">User</option>
|
<option data-i18n="User" value="1">User</option>
|
||||||
<option value="2">Assistant</option>
|
<option data-i18n="Assistant" value="2">Assistant</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@ -5310,9 +5332,9 @@
|
|||||||
<input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
|
<input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
|
||||||
<span data-i18n="as">as</span>
|
<span data-i18n="as">as</span>
|
||||||
<select id="extension_default_role" class="text_pole widthNatural">
|
<select id="extension_default_role" class="text_pole widthNatural">
|
||||||
<option value="0">System</option>
|
<option data-i18n="System" value="0">System</option>
|
||||||
<option value="1">User</option>
|
<option data-i18n="User" value="1">User</option>
|
||||||
<option value="2">Assistant</option>
|
<option data-i18n="Assistant" value="2">Assistant</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3258,7 +3258,12 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
|
|||||||
let continue_mag = '';
|
let continue_mag = '';
|
||||||
for (let i = coreChat.length - 1, j = 0; i >= 0; i--, j++) {
|
for (let i = coreChat.length - 1, j = 0; i >= 0; i--, j++) {
|
||||||
if (main_api == 'openai') {
|
if (main_api == 'openai') {
|
||||||
break;
|
chat2[i] = coreChat[j].mes;
|
||||||
|
if (i === 0 && isContinue) {
|
||||||
|
chat2[i] = chat2[i].slice(0, chat2[i].lastIndexOf(coreChat[j].mes) + coreChat[j].mes.length);
|
||||||
|
continue_mag = coreChat[j].mes;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, false);
|
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, false);
|
||||||
@ -3399,8 +3404,8 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
|
|||||||
// Coping mechanism for OAI spacing
|
// Coping mechanism for OAI spacing
|
||||||
const isForceInstruct = isOpenRouterWithInstruct();
|
const isForceInstruct = isOpenRouterWithInstruct();
|
||||||
if (main_api === 'openai' && !isForceInstruct && !cyclePrompt.endsWith(' ')) {
|
if (main_api === 'openai' && !isForceInstruct && !cyclePrompt.endsWith(' ')) {
|
||||||
cyclePrompt += ' ';
|
cyclePrompt += oai_settings.continue_postfix;
|
||||||
continue_mag += ' ';
|
continue_mag += oai_settings.continue_postfix;
|
||||||
}
|
}
|
||||||
message_already_generated = continue_mag;
|
message_already_generated = continue_mag;
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,12 @@ const character_names_behavior = {
|
|||||||
CONTENT: 2,
|
CONTENT: 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const continue_postfix_types = {
|
||||||
|
SPACE: ' ',
|
||||||
|
NEWLINE: '\n',
|
||||||
|
DOUBLE_NEWLINE: '\n\n',
|
||||||
|
};
|
||||||
|
|
||||||
const prefixMap = selected_group ? {
|
const prefixMap = selected_group ? {
|
||||||
assistant: '',
|
assistant: '',
|
||||||
user: '',
|
user: '',
|
||||||
@ -253,6 +259,7 @@ const default_settings = {
|
|||||||
bypass_status_check: false,
|
bypass_status_check: false,
|
||||||
continue_prefill: false,
|
continue_prefill: false,
|
||||||
names_behavior: character_names_behavior.NONE,
|
names_behavior: character_names_behavior.NONE,
|
||||||
|
continue_postfix: continue_postfix_types.SPACE,
|
||||||
seed: -1,
|
seed: -1,
|
||||||
n: 1,
|
n: 1,
|
||||||
};
|
};
|
||||||
@ -320,6 +327,7 @@ const oai_settings = {
|
|||||||
bypass_status_check: false,
|
bypass_status_check: false,
|
||||||
continue_prefill: false,
|
continue_prefill: false,
|
||||||
names_behavior: character_names_behavior.NONE,
|
names_behavior: character_names_behavior.NONE,
|
||||||
|
continue_postfix: continue_postfix_types.SPACE,
|
||||||
seed: -1,
|
seed: -1,
|
||||||
n: 1,
|
n: 1,
|
||||||
};
|
};
|
||||||
@ -718,7 +726,7 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul
|
|||||||
// Reserve budget for continue nudge
|
// Reserve budget for continue nudge
|
||||||
let continueMessage = null;
|
let continueMessage = null;
|
||||||
const instruct = isOpenRouterWithInstruct();
|
const instruct = isOpenRouterWithInstruct();
|
||||||
if (type === 'continue' && cyclePrompt && !instruct) {
|
if (type === 'continue' && cyclePrompt && !instruct && !oai_settings.continue_prefill) {
|
||||||
const promptObject = oai_settings.continue_prefill ?
|
const promptObject = oai_settings.continue_prefill ?
|
||||||
{
|
{
|
||||||
identifier: 'continueNudge',
|
identifier: 'continueNudge',
|
||||||
@ -2600,6 +2608,7 @@ function loadOpenAISettings(data, settings) {
|
|||||||
oai_settings.squash_system_messages = settings.squash_system_messages ?? default_settings.squash_system_messages;
|
oai_settings.squash_system_messages = settings.squash_system_messages ?? default_settings.squash_system_messages;
|
||||||
oai_settings.continue_prefill = settings.continue_prefill ?? default_settings.continue_prefill;
|
oai_settings.continue_prefill = settings.continue_prefill ?? default_settings.continue_prefill;
|
||||||
oai_settings.names_behavior = settings.names_behavior ?? default_settings.names_behavior;
|
oai_settings.names_behavior = settings.names_behavior ?? default_settings.names_behavior;
|
||||||
|
oai_settings.continue_postfix = settings.continue_postfix ?? default_settings.continue_postfix;
|
||||||
|
|
||||||
// Migrate from old settings
|
// Migrate from old settings
|
||||||
if (settings.names_in_completion === true) {
|
if (settings.names_in_completion === true) {
|
||||||
@ -2716,6 +2725,7 @@ function loadOpenAISettings(data, settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setNamesBehaviorControls();
|
setNamesBehaviorControls();
|
||||||
|
setContinuePostfixControls();
|
||||||
|
|
||||||
$('#chat_completion_source').val(oai_settings.chat_completion_source).trigger('change');
|
$('#chat_completion_source').val(oai_settings.chat_completion_source).trigger('change');
|
||||||
$('#oai_max_context_unlocked').prop('checked', oai_settings.max_context_unlocked);
|
$('#oai_max_context_unlocked').prop('checked', oai_settings.max_context_unlocked);
|
||||||
@ -2735,6 +2745,27 @@ function setNamesBehaviorControls() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setContinuePostfixControls() {
|
||||||
|
switch (oai_settings.continue_postfix) {
|
||||||
|
case continue_postfix_types.SPACE:
|
||||||
|
$('#continue_postfix_space').prop('checked', true);
|
||||||
|
break;
|
||||||
|
case continue_postfix_types.NEWLINE:
|
||||||
|
$('#continue_postfix_newline').prop('checked', true);
|
||||||
|
break;
|
||||||
|
case continue_postfix_types.DOUBLE_NEWLINE:
|
||||||
|
$('#continue_postfix_double_newline').prop('checked', true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Prevent preset value abuse
|
||||||
|
oai_settings.continue_postfix = continue_postfix_types.SPACE;
|
||||||
|
$('#continue_postfix_space').prop('checked', true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#continue_postfix').val(oai_settings.continue_postfix);
|
||||||
|
}
|
||||||
|
|
||||||
async function getStatusOpen() {
|
async function getStatusOpen() {
|
||||||
if (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI) {
|
if (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI) {
|
||||||
let status;
|
let status;
|
||||||
@ -2891,6 +2922,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
|
|||||||
image_inlining: settings.image_inlining,
|
image_inlining: settings.image_inlining,
|
||||||
bypass_status_check: settings.bypass_status_check,
|
bypass_status_check: settings.bypass_status_check,
|
||||||
continue_prefill: settings.continue_prefill,
|
continue_prefill: settings.continue_prefill,
|
||||||
|
continue_postfix: settings.continue_postfix,
|
||||||
seed: settings.seed,
|
seed: settings.seed,
|
||||||
n: settings.n,
|
n: settings.n,
|
||||||
};
|
};
|
||||||
@ -3265,6 +3297,7 @@ function onSettingsPresetChange() {
|
|||||||
squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true],
|
squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true],
|
||||||
image_inlining: ['#openai_image_inlining', 'image_inlining', true],
|
image_inlining: ['#openai_image_inlining', 'image_inlining', true],
|
||||||
continue_prefill: ['#continue_prefill', 'continue_prefill', true],
|
continue_prefill: ['#continue_prefill', 'continue_prefill', true],
|
||||||
|
continue_postfix: ['#continue_postfix', 'continue_postfix', false],
|
||||||
seed: ['#seed_openai', 'seed', false],
|
seed: ['#seed_openai', 'seed', false],
|
||||||
n: ['#n_openai', 'n', false],
|
n: ['#n_openai', 'n', false],
|
||||||
};
|
};
|
||||||
@ -4387,6 +4420,27 @@ $(document).ready(async function () {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#continue_postifx').on('input', function () {
|
||||||
|
oai_settings.continue_postfix = String($(this).val());
|
||||||
|
setContinuePostfixControls();
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#continue_postfix_space').on('input', function () {
|
||||||
|
oai_settings.continue_postfix = continue_postfix_types.SPACE;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#continue_postfix_newline').on('input', function () {
|
||||||
|
oai_settings.continue_postfix = continue_postfix_types.NEWLINE;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#continue_postfix_double_newline').on('input', function () {
|
||||||
|
oai_settings.continue_postfix = continue_postfix_types.DOUBLE_NEWLINE;
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('input', '#openai_settings .autoSetHeight', function () {
|
$(document).on('input', '#openai_settings .autoSetHeight', function () {
|
||||||
resetScrollHeight($(this));
|
resetScrollHeight($(this));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user