Support "before main prompt" extension position in prompt manager
This commit is contained in:
parent
ad95be2500
commit
902acc44a2
|
@ -636,7 +636,7 @@ let is_send_press = false; //Send generation
|
|||
|
||||
let this_del_mes = 0;
|
||||
|
||||
//message editing and chat scroll posistion persistence
|
||||
//message editing and chat scroll position persistence
|
||||
var this_edit_mes_text = "";
|
||||
var this_edit_mes_chname = "";
|
||||
var this_edit_mes_id;
|
||||
|
@ -2578,7 +2578,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||
addPersonaDescriptionExtensionPrompt();
|
||||
// Call combined AN into Generate
|
||||
let allAnchors = getAllExtensionPrompts();
|
||||
const beforeScenarioAnchor = getExtensionPrompt(extension_prompt_types.BEFORE_PROMPT)
|
||||
const beforeScenarioAnchor = getExtensionPrompt(extension_prompt_types.BEFORE_PROMPT).trimStart();
|
||||
const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.IN_PROMPT);
|
||||
let zeroDepthAnchor = getExtensionPrompt(extension_prompt_types.IN_CHAT, 0, ' ');
|
||||
|
||||
|
|
|
@ -581,6 +581,22 @@ function populateDialogueExamples(prompts, chatCompletion) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} position - Prompt position in the extensions object.
|
||||
* @returns {string|false} - The prompt position for prompt collection.
|
||||
*/
|
||||
function getPromptPosition(position) {
|
||||
if (position == extension_prompt_types.BEFORE_PROMPT) {
|
||||
return 'start';
|
||||
}
|
||||
|
||||
if (position == extension_prompt_types.IN_PROMPT) {
|
||||
return 'end';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate a chat conversation by adding prompts to the conversation and managing system and user prompts.
|
||||
*
|
||||
|
@ -645,28 +661,39 @@ function populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, ty
|
|||
if (bias && bias.trim().length) addToChatCompletion('bias');
|
||||
|
||||
// Tavern Extras - Summary
|
||||
if (prompts.has('summary')) chatCompletion.insert(Message.fromPrompt(prompts.get('summary')), 'main');
|
||||
if (prompts.has('summary')) {
|
||||
const summary = prompts.get('summary');
|
||||
|
||||
if (summary.position) {
|
||||
chatCompletion.insert(Message.fromPrompt(summary), 'main', summary.position);
|
||||
}
|
||||
}
|
||||
|
||||
// Authors Note
|
||||
if (prompts.has('authorsNote')) {
|
||||
const authorsNote = Message.fromPrompt(prompts.get('authorsNote'));
|
||||
const authorsNote = prompts.get('authorsNote') ;
|
||||
|
||||
// ToDo: Ideally this should not be retrieved here but already be referenced in some configuration object
|
||||
const afterScenario = document.querySelector('input[name="extension_floating_position"]').checked;
|
||||
|
||||
// Add authors notes
|
||||
if (true === afterScenario) chatCompletion.insert(authorsNote, 'scenario');
|
||||
if (authorsNote.position) {
|
||||
chatCompletion.insert(Message.fromPrompt(authorsNote), 'main', authorsNote.position);
|
||||
}
|
||||
}
|
||||
|
||||
// Vectors Memory
|
||||
if (prompts.has('vectorsMemory')) {
|
||||
const vectorsMemory = Message.fromPrompt(prompts.get('vectorsMemory'));
|
||||
chatCompletion.insert(vectorsMemory, 'main');
|
||||
const vectorsMemory = prompts.get('vectorsMemory');
|
||||
|
||||
if (vectorsMemory.position) {
|
||||
chatCompletion.insert(Message.fromPrompt(vectorsMemory), 'main', vectorsMemory.position);
|
||||
}
|
||||
}
|
||||
|
||||
// Smart Context (ChromaDB)
|
||||
if (prompts.has('smartContext')) {
|
||||
chatCompletion.insert(Message.fromPrompt(prompts.get('smartContext')), 'main');
|
||||
const smartContext = prompts.get('smartContext');
|
||||
|
||||
if (smartContext.position) {
|
||||
chatCompletion.insert(Message.fromPrompt(smartContext), 'main', smartContext.position);
|
||||
}
|
||||
}
|
||||
|
||||
// Decide whether dialogue examples should always be added
|
||||
|
@ -725,7 +752,8 @@ function preparePromptsForChatCompletion({Scenario, charPersonality, name2, worl
|
|||
if (summary && summary.value) systemPrompts.push({
|
||||
role: 'system',
|
||||
content: summary.value,
|
||||
identifier: 'summary'
|
||||
identifier: 'summary',
|
||||
position: getPromptPosition(summary.position),
|
||||
});
|
||||
|
||||
// Authors Note
|
||||
|
@ -733,7 +761,8 @@ function preparePromptsForChatCompletion({Scenario, charPersonality, name2, worl
|
|||
if (authorsNote && authorsNote.value) systemPrompts.push({
|
||||
role: 'system',
|
||||
content: authorsNote.value,
|
||||
identifier: 'authorsNote'
|
||||
identifier: 'authorsNote',
|
||||
position: getPromptPosition(authorsNote.position),
|
||||
});
|
||||
|
||||
// Vectors Memory
|
||||
|
@ -742,6 +771,7 @@ function preparePromptsForChatCompletion({Scenario, charPersonality, name2, worl
|
|||
role: 'system',
|
||||
content: vectorsMemory.value,
|
||||
identifier: 'vectorsMemory',
|
||||
position: getPromptPosition(vectorsMemory.position),
|
||||
});
|
||||
|
||||
// Smart Context (ChromaDB)
|
||||
|
@ -749,7 +779,8 @@ function preparePromptsForChatCompletion({Scenario, charPersonality, name2, worl
|
|||
if (smartContext && smartContext.value) systemPrompts.push({
|
||||
role: 'system',
|
||||
content: smartContext.value,
|
||||
identifier: 'smartContext'
|
||||
identifier: 'smartContext',
|
||||
position: getPromptPosition(smartContext.position),
|
||||
});
|
||||
|
||||
// Persona Description
|
||||
|
|
Loading…
Reference in New Issue