Prompt manager configuration fixes (#1078)

* Refactor oai preset change event into before and after

* Simplify and reinforce prompt manager render without character

* Check if main prompt exists before adding nsfwAvoidance

* Sanitize prompt manager configuration on preset loading

---------

Co-authored-by: maver <kentucky@posteo.de>
This commit is contained in:
Cohee
2023-09-01 23:23:03 +03:00
committed by GitHub
parent 428c851c9b
commit 4a6705cea8
3 changed files with 26 additions and 25 deletions

View File

@ -354,7 +354,11 @@ function setupChatCompletionPromptManager(openAiSettings) {
}
promptManager.tryGenerate = () => {
return Generate('normal', {}, true);
if (characters[this_chid]) {
return Generate('normal', {}, true);
} else{
return Promise.resolve();
}
}
promptManager.tokenHandler = tokenHandler;
@ -613,7 +617,7 @@ function populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, ty
// Insert nsfw avoidance prompt into main, if no nsfw prompt is present
if (false === chatCompletion.has('nsfw') && oai_settings.nsfw_avoidance_prompt)
if (prompts.has('nsfwAvoidance')) chatCompletion.insert(Message.fromPrompt(prompts.get('nsfwAvoidance')), 'main');
if (prompts.has('nsfwAvoidance') && prompts.has('main')) chatCompletion.insert(Message.fromPrompt(prompts.get('nsfwAvoidance')), 'main');
// Bias
if (bias && bias.trim().length) addToChatCompletion('bias');
@ -2463,7 +2467,7 @@ function onSettingsPresetChange() {
const updateCheckbox = (selector, value) => $(selector).prop('checked', value).trigger('input');
// Allow subscribers to alter the preset before applying deltas
eventSource.emit(event_types.OAI_PRESET_CHANGED, {
eventSource.emit(event_types.OAI_PRESET_CHANGED_BEFORE, {
preset: preset,
presetName: presetName,
settingsToUpdate: settingsToUpdate,
@ -2485,6 +2489,7 @@ function onSettingsPresetChange() {
$(`#openai_logit_bias_preset`).trigger('change');
saveSettingsDebounced();
eventSource.emit(event_types.OAI_PRESET_CHANGED_AFTER);
});
}