Add GENERATE_BEFORE_COMBINE_PROMPTS event
Allows for context to be ordered by extensions
This commit is contained in:
parent
0a649a395d
commit
f30f75b310
|
@ -315,6 +315,7 @@ export const event_types = {
|
||||||
FORCE_SET_BACKGROUND: 'force_set_background',
|
FORCE_SET_BACKGROUND: 'force_set_background',
|
||||||
CHAT_DELETED: 'chat_deleted',
|
CHAT_DELETED: 'chat_deleted',
|
||||||
GROUP_CHAT_DELETED: 'group_chat_deleted',
|
GROUP_CHAT_DELETED: 'group_chat_deleted',
|
||||||
|
GENERATE_BEFORE_COMBINE_PROMPTS: 'generate_before_combine_prompts',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const eventSource = new EventEmitter();
|
export const eventSource = new EventEmitter();
|
||||||
|
@ -3623,30 +3624,57 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
|
||||||
generatedPromptCache = cleanupPromptCache(generatedPromptCache);
|
generatedPromptCache = cleanupPromptCache(generatedPromptCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right now, everything is suffixed with a newline
|
// Flattens the multiple prompt objects to a string.
|
||||||
mesSendString = finalMesSend.map((e) => `${e.extensionPrompts.join('')}${e.message}`).join('');
|
const combine = () => {
|
||||||
|
// Right now, everything is suffixed with a newline
|
||||||
|
mesSendString = finalMesSend.map((e) => `${e.extensionPrompts.join('')}${e.message}`).join('');
|
||||||
|
|
||||||
// add chat preamble
|
// add a custom dingus (if defined)
|
||||||
mesSendString = addChatsPreamble(mesSendString);
|
mesSendString = addChatsSeparator(mesSendString);
|
||||||
|
|
||||||
// add a custom dingus (if defined)
|
// add chat preamble
|
||||||
mesSendString = addChatsSeparator(mesSendString);
|
mesSendString = addChatsPreamble(mesSendString);
|
||||||
|
|
||||||
let combinedPrompt =
|
let combinedPrompt = beforeScenarioAnchor +
|
||||||
beforeScenarioAnchor +
|
storyString +
|
||||||
storyString +
|
afterScenarioAnchor +
|
||||||
afterScenarioAnchor +
|
mesExmString +
|
||||||
mesExmString +
|
mesSendString +
|
||||||
mesSendString +
|
generatedPromptCache;
|
||||||
generatedPromptCache;
|
|
||||||
|
|
||||||
combinedPrompt = combinedPrompt.replace(/\r/gm, '');
|
combinedPrompt = combinedPrompt.replace(/\r/gm, '');
|
||||||
|
|
||||||
if (power_user.collapse_newlines) {
|
if (power_user.collapse_newlines) {
|
||||||
combinedPrompt = collapseNewlines(combinedPrompt);
|
combinedPrompt = collapseNewlines(combinedPrompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return combinedPrompt;
|
return combinedPrompt;
|
||||||
|
};
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
api: main_api,
|
||||||
|
combinedPrompt: null,
|
||||||
|
description,
|
||||||
|
personality,
|
||||||
|
persona,
|
||||||
|
scenario,
|
||||||
|
char: name2,
|
||||||
|
user: name1,
|
||||||
|
beforeScenarioAnchor,
|
||||||
|
afterScenarioAnchor,
|
||||||
|
mesExmString,
|
||||||
|
finalMesSend,
|
||||||
|
generatedPromptCache,
|
||||||
|
main: system,
|
||||||
|
jailbreak,
|
||||||
|
naiPreamble: nai_settings.preamble,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Before returning the combined prompt, give available context related information to all subscribers.
|
||||||
|
eventSource.emitAndWait(event_types.GENERATE_BEFORE_COMBINE_PROMPTS, data);
|
||||||
|
|
||||||
|
// If one or multiple subscribers return a value, forfeit the responsibillity of flattening the context.
|
||||||
|
return !data.combinedPrompt ? combine() : data.combinedPrompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the negative prompt first since it has the unmodified mesSend array
|
// Get the negative prompt first since it has the unmodified mesSend array
|
||||||
|
|
Loading…
Reference in New Issue