Add support for persona description positioning

This commit is contained in:
maver 2023-06-27 19:45:40 +02:00
parent 4ed92d69b0
commit d0aba85692
1 changed files with 34 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import {
} from "./PromptManager.js";
import {
persona_description_positions,
power_user,
} from "./power-user.js";
import {
@ -521,6 +522,34 @@ function populateChatCompletion (prompts, chatCompletion, {bias, quietPrompt, ty
else chatCompletion.insert(authorsNote, 'main')
}
// Persona Description
if(power_user.persona_description) {
const personaDescription = Message.fromPrompt(prompts.get('personaDescription'));
try {
switch (power_user.persona_description_position) {
case persona_description_positions.BEFORE_CHAR:
chatCompletion.insertAtStart(personaDescription, 'charDescription');
break;
case persona_description_positions.AFTER_CHAR:
chatCompletion.insertAtEnd(personaDescription, 'charDescription');
break;
case persona_description_positions.TOP_AN:
chatCompletion.insertAtStart(personaDescription, 'authorsNote');
break;
case persona_description_positions.BOTTOM_AN:
chatCompletion.insertAtEnd(personaDescription, 'authorsNote');
break;
}
} catch (error) {
if (error instanceof IdentifierNotFoundError) {
// Error is acceptable in this context
} else {
throw error;
}
}
}
// Decide whether dialogue examples should always be added
if (power_user.pin_examples) {
populateDialogueExamples(prompts, chatCompletion);
@ -595,6 +624,11 @@ function prepareOpenAIMessages({
const authorsNote = extensionPrompts['2_floating_prompt'];
if (authorsNote && authorsNote.content) mappedPrompts.push({role: 'system', content: authorsNote.content, identifier: 'authorsNote'});
// Persona Description
if (power_user.persona_description) {
mappedPrompts.push({role: 'system', content: power_user.persona_description, identifier: 'personaDescription'});
}
// Create prompt objects and substitute markers
mappedPrompts.forEach(prompt => {
const newPrompt = promptManager.preparePrompt(prompt);