mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-20 21:41:32 +01:00
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:
parent
428c851c9b
commit
4a6705cea8
@ -279,7 +279,8 @@ export const event_types = {
|
||||
CHATCOMPLETION_SOURCE_CHANGED: 'chatcompletion_source_changed',
|
||||
CHATCOMPLETION_MODEL_CHANGED: 'chatcompletion_model_changed',
|
||||
OAI_BEFORE_CHATCOMPLETION: 'oai_before_chatcompletion',
|
||||
OAI_PRESET_CHANGED: 'oai_preset_changed',
|
||||
OAI_PRESET_CHANGED_BEFORE: 'oai_preset_changed_before',
|
||||
OAI_PRESET_CHANGED_AFTER: 'oai_preset_changed_after',
|
||||
WORLDINFO_SETTINGS_UPDATED: 'worldinfo_settings_updated',
|
||||
CHARACTER_EDITED: 'character_edited',
|
||||
USER_MESSAGE_RENDERED: 'user_message_rendered',
|
||||
|
@ -53,7 +53,7 @@ const registerPromptManagerMigration = () => {
|
||||
};
|
||||
|
||||
eventSource.on(event_types.SETTINGS_LOADED_BEFORE, settings => migrate(settings));
|
||||
eventSource.on(event_types.OAI_PRESET_CHANGED, event => migrate(event.preset, event.savePreset, event.presetName));
|
||||
eventSource.on(event_types.OAI_PRESET_CHANGED_BEFORE, event => migrate(event.preset, event.savePreset, event.presetName));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -604,22 +604,20 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_close_button').addEventListener('click', closeAndClearPopup);
|
||||
|
||||
// Re-render prompt manager on openai preset change
|
||||
eventSource.on(event_types.OAI_PRESET_CHANGED, settings => {
|
||||
// Save configuration and wrap everything up.
|
||||
this.saveServiceSettings().then(() => {
|
||||
const mainPrompt = this.getPromptById('main');
|
||||
this.updateQuickEdit('main', mainPrompt);
|
||||
eventSource.on(event_types.OAI_PRESET_CHANGED_AFTER, () => {
|
||||
this.sanitizeServiceSettings();
|
||||
const mainPrompt = this.getPromptById('main');
|
||||
this.updateQuickEdit('main', mainPrompt);
|
||||
|
||||
const nsfwPrompt = this.getPromptById('nsfw');
|
||||
this.updateQuickEdit('nsfw', nsfwPrompt);
|
||||
const nsfwPrompt = this.getPromptById('nsfw');
|
||||
this.updateQuickEdit('nsfw', nsfwPrompt);
|
||||
|
||||
const jailbreakPrompt = this.getPromptById('jailbreak');
|
||||
this.updateQuickEdit('jailbreak', jailbreakPrompt);
|
||||
const jailbreakPrompt = this.getPromptById('jailbreak');
|
||||
this.updateQuickEdit('jailbreak', jailbreakPrompt);
|
||||
|
||||
this.hidePopup();
|
||||
this.clearEditForm();
|
||||
this.renderDebounced();
|
||||
});
|
||||
this.hidePopup();
|
||||
this.clearEditForm();
|
||||
this.renderDebounced();
|
||||
});
|
||||
|
||||
// Re-render prompt manager on world settings update
|
||||
@ -643,19 +641,13 @@ PromptManagerModule.prototype.render = function (afterTryGenerate = true) {
|
||||
if (true === afterTryGenerate) {
|
||||
// Executed during dry-run for determining context composition
|
||||
this.profileStart('filling context');
|
||||
this.tryGenerate().then(() => {
|
||||
this.tryGenerate().finally(() => {
|
||||
this.profileEnd('filling context');
|
||||
this.profileStart('render');
|
||||
this.renderPromptManager();
|
||||
this.renderPromptManagerListItems()
|
||||
this.makeDraggable();
|
||||
this.profileEnd('render');
|
||||
}).catch(error => {
|
||||
this.profileEnd('filling context');
|
||||
this.log('Error caught during render: ' + error);
|
||||
this.renderPromptManager();
|
||||
this.renderPromptManagerListItems()
|
||||
this.makeDraggable();
|
||||
});
|
||||
} else {
|
||||
// Executed during live communication
|
||||
@ -1383,6 +1375,9 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () {
|
||||
</li>
|
||||
`;
|
||||
|
||||
console.log(this.activeCharacter)
|
||||
console.log(this.serviceSettings)
|
||||
console.log(this.getPromptsForCharacter(this.activeCharacter))
|
||||
this.getPromptsForCharacter(this.activeCharacter).forEach(prompt => {
|
||||
if (!prompt) return;
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user