Add roles to Author's Notes

This commit is contained in:
Cohee 2024-03-23 18:45:37 +02:00
parent 848af1fd4b
commit bb6ac5147b
4 changed files with 86 additions and 25 deletions

View File

@ -5202,7 +5202,7 @@
<b>Unique to this chat</b>.<br>
Checkpoints inherit the Note from their parent, and can be changed individually after that.<br>
</small>
<textarea id="extension_floating_prompt" class="text_pole" rows="8" maxlength="50000"></textarea>
<textarea id="extension_floating_prompt" class="text_pole textarea_compact" rows="8" maxlength="50000"></textarea>
<div class="extension_token_counter">
Tokens: <span id="extension_floating_prompt_token_counter">0</span>
</div>
@ -5211,22 +5211,34 @@
<span data-i18n="Include in World Info Scanning">Include in World Info Scanning</span>
</label>
<div class="floating_prompt_radio_group">
<label>
<input type="radio" name="extension_floating_position" value="2" />
Before Main Prompt / Story String
<label class="checkbox_label" for="extension_floating_position_before">
<input type="radio" id="extension_floating_position_before" name="extension_floating_position" value="2" />
<span data-i18n="Before Main Prompt / Story String">Before Main Prompt / Story String</span>
</label>
<label>
<input type="radio" name="extension_floating_position" value="0" />
After Main Prompt / Story String
<label class="checkbox_label" for="extension_floating_position_after">
<input type="radio" id="extension_floating_position_after" name="extension_floating_position" value="0" />
<span data-i18n="After Main Prompt / Story String">After Main Prompt / Story String</span>
</label>
<label>
<input type="radio" name="extension_floating_position" value="1" />
In-chat @ Depth <input id="extension_floating_depth" class="text_pole widthUnset" type="number" min="0" max="999" />
<label class="checkbox_label alignItemsCenter" for="extension_floating_position_depth">
<input type="radio" id="extension_floating_position_depth" name="extension_floating_position" value="1" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
<input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
<span data-i18n="as">as</span>
<select id="extension_floating_role" class="text_pole widthNatural">
<option value="0">System</option>
<option value="1">User</option>
<option value="2">Assistant</option>
</select>
</label>
</div>
<!--<label for="extension_floating_interval">In-Chat Insertion Depth</label>-->
<label for="extension_floating_interval">Insertion Frequency</label>
<input id="extension_floating_interval" class="text_pole widthUnset" type="number" min="0" max="999" /><small> (0 = Disable, 1 = Always)</small>
<div class="flex-container">
<label for="extension_floating_interval" class="flex-container flexNoGap flexFlowColumn">
<span data-i18n="Insertion Frequency">Insertion Frequency</span>
<small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
</label>
<input id="extension_floating_interval" class="text_pole widthUnset" type="number" min="0" max="999" />
</div>
<br>
<span>User inputs until next insertion: <span id="extension_floating_counter">(disabled)</span></span>
</div>
@ -5247,7 +5259,7 @@
<div class="inline-drawer-content">
<small>Will be automatically added as the author's note for this character. Will be used in groups, but
can't be modified when a group chat is open.</small>
<textarea id="extension_floating_chara" class="text_pole" rows="8" maxlength="50000" placeholder="Example:&#10;[Scenario: wacky adventures; Genre: romantic comedy; Style: verbose, creative]"></textarea>
<textarea id="extension_floating_chara" class="text_pole textarea_compact" rows="8" maxlength="50000" placeholder="Example:&#10;[Scenario: wacky adventures; Genre: romantic comedy; Style: verbose, creative]"></textarea>
<div class="extension_token_counter">
Tokens: <span id="extension_floating_chara_token_counter">0</span>
</div>
@ -5279,22 +5291,38 @@
</div>
<div class="inline-drawer-content">
<small>Will be automatically added as the Author's Note for all new chats.</small>
<textarea id="extension_floating_default" class="text_pole" rows="8" maxlength="50000" placeholder="Example:&#10;[Scenario: wacky adventures; Genre: romantic comedy; Style: verbose, creative]"></textarea>
<textarea id="extension_floating_default" class="text_pole textarea_compact" rows="8" maxlength="50000" placeholder="Example:&#10;[Scenario: wacky adventures; Genre: romantic comedy; Style: verbose, creative]"></textarea>
<div class="extension_token_counter">
Tokens: <span id="extension_floating_default_token_counter">0</span>
</div>
<div class="floating_prompt_radio_group">
<label>
<input type="radio" name="extension_default_position" value="0" />
After Main Prompt / Story String
<label class="checkbox_label" for="extension_default_position_before">
<input type="radio" id="extension_default_position_before" name="extension_default_position" value="2" />
<span data-i18n="Before Main Prompt / Story String">Before Main Prompt / Story String</span>
</label>
<label>
<input type="radio" name="extension_default_position" value="1" />
In-chat @ Depth <input id="extension_default_depth" class="text_pole widthUnset" type="number" min="0" max="999" />
<label class="checkbox_label" for="extension_default_position_after">
<input type="radio" id="extension_default_position_after" name="extension_default_position" value="0" />
<span data-i18n="After Main Prompt / Story String">After Main Prompt / Story String</span>
</label>
<label class="checkbox_label alignItemsCenter" for="extension_default_position_depth">
<input type="radio" id="extension_default_position_depth" name="extension_default_position" value="1" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
<input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
<span data-i18n="as">as</span>
<select id="extension_default_role" class="text_pole widthNatural">
<option value="0">System</option>
<option value="1">User</option>
<option value="2">Assistant</option>
</select>
</label>
</div>
<label for="extension_default_interval">Insertion Frequency</label>
<input id="extension_default_interval" class="text_pole widthUnset" type="number" min="0" max="999" /><small> (0 = Disable, 1 = Always)</small>
<div class="flex-container">
<label for="extension_default_interval" class="flex-container flexNoGap flexFlowColumn">
<span data-i18n="Insertion Frequency">Insertion Frequency</span>
<small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
</label>
<input id="extension_default_interval" class="text_pole widthUnset" type="number" min="0" max="999" />
</div>
</div>
</div>
</div>

View File

@ -2454,7 +2454,7 @@ function addPersonaDescriptionExtensionPrompt() {
? `${power_user.persona_description}\n${originalAN}`
: `${originalAN}\n${power_user.persona_description}`;
setExtensionPrompt(NOTE_MODULE_NAME, ANWithDesc, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth], extension_settings.note.allowWIScan);
setExtensionPrompt(NOTE_MODULE_NAME, ANWithDesc, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth], extension_settings.note.allowWIScan, chat_metadata[metadata_keys.role]);
}
}

View File

@ -3,6 +3,7 @@ import {
chat_metadata,
eventSource,
event_types,
extension_prompt_roles,
saveSettingsDebounced,
this_chid,
} from '../script.js';
@ -22,6 +23,7 @@ export const metadata_keys = {
interval: 'note_interval',
depth: 'note_depth',
position: 'note_position',
role: 'note_role',
};
const chara_note_position = {
@ -140,6 +142,16 @@ async function onDefaultIntervalInput() {
saveSettingsDebounced();
}
function onExtensionFloatingRoleInput(e) {
chat_metadata[metadata_keys.role] = Number(e.target.value);
updateSettings();
}
function onExtensionDefaultRoleInput(e) {
extension_settings.note.defaultRole = Number(e.target.value);
saveSettingsDebounced();
}
async function onExtensionFloatingCharPositionInput(e) {
const value = e.target.value;
const charaNote = extension_settings.note.chara.find((e) => e.name === getCharaFilename());
@ -217,6 +229,7 @@ function loadSettings() {
const DEFAULT_DEPTH = 4;
const DEFAULT_POSITION = 1;
const DEFAULT_INTERVAL = 1;
const DEFAULT_ROLE = extension_prompt_roles.SYSTEM;
if (extension_settings.note.defaultPosition === undefined) {
extension_settings.note.defaultPosition = DEFAULT_POSITION;
@ -230,14 +243,20 @@ function loadSettings() {
extension_settings.note.defaultInterval = DEFAULT_INTERVAL;
}
if (extension_settings.note.defaultRole === undefined) {
extension_settings.note.defaultRole = DEFAULT_ROLE;
}
chat_metadata[metadata_keys.prompt] = chat_metadata[metadata_keys.prompt] ?? extension_settings.note.default ?? '';
chat_metadata[metadata_keys.interval] = chat_metadata[metadata_keys.interval] ?? extension_settings.note.defaultInterval ?? DEFAULT_INTERVAL;
chat_metadata[metadata_keys.position] = chat_metadata[metadata_keys.position] ?? extension_settings.note.defaultPosition ?? DEFAULT_POSITION;
chat_metadata[metadata_keys.depth] = chat_metadata[metadata_keys.depth] ?? extension_settings.note.defaultDepth ?? DEFAULT_DEPTH;
chat_metadata[metadata_keys.role] = chat_metadata[metadata_keys.role] ?? extension_settings.note.defaultRole ?? DEFAULT_ROLE;
$('#extension_floating_prompt').val(chat_metadata[metadata_keys.prompt]);
$('#extension_floating_interval').val(chat_metadata[metadata_keys.interval]);
$('#extension_floating_allow_wi_scan').prop('checked', extension_settings.note.allowWIScan ?? false);
$('#extension_floating_depth').val(chat_metadata[metadata_keys.depth]);
$('#extension_floating_role').val(chat_metadata[metadata_keys.role]);
$(`input[name="extension_floating_position"][value="${chat_metadata[metadata_keys.position]}"]`).prop('checked', true);
if (extension_settings.note.chara && getContext().characterId) {
@ -255,6 +274,7 @@ function loadSettings() {
$('#extension_floating_default').val(extension_settings.note.default);
$('#extension_default_depth').val(extension_settings.note.defaultDepth);
$('#extension_default_interval').val(extension_settings.note.defaultInterval);
$('#extension_default_role').val(extension_settings.note.defaultRole);
$(`input[name="extension_default_position"][value="${extension_settings.note.defaultPosition}"]`).prop('checked', true);
}
@ -274,6 +294,10 @@ export function setFloatingPrompt() {
------
lastMessageNumber = ${lastMessageNumber}
metadata_keys.interval = ${chat_metadata[metadata_keys.interval]}
metadata_keys.position = ${chat_metadata[metadata_keys.position]}
metadata_keys.depth = ${chat_metadata[metadata_keys.depth]}
metadata_keys.role = ${chat_metadata[metadata_keys.role]}
------
`);
// interval 1 should be inserted no matter what
@ -313,7 +337,14 @@ export function setFloatingPrompt() {
}
}
}
context.setExtensionPrompt(MODULE_NAME, prompt, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth], extension_settings.note.allowWIScan);
context.setExtensionPrompt(
MODULE_NAME,
prompt,
chat_metadata[metadata_keys.position],
chat_metadata[metadata_keys.depth],
extension_settings.note.allowWIScan,
chat_metadata[metadata_keys.role],
);
$('#extension_floating_counter').text(shouldAddPrompt ? '0' : messagesTillInsertion);
}
@ -410,6 +441,8 @@ export function initAuthorsNote() {
$('#extension_default_depth').on('input', onDefaultDepthInput);
$('#extension_default_interval').on('input', onDefaultIntervalInput);
$('#extension_floating_allow_wi_scan').on('input', onAllowWIScanCheckboxChanged);
$('#extension_floating_role').on('input', onExtensionFloatingRoleInput);
$('#extension_default_role').on('input', onExtensionDefaultRoleInput);
$('input[name="extension_floating_position"]').on('change', onExtensionFloatingPositionInput);
$('input[name="extension_default_position"]').on('change', onDefaultPositionInput);
$('input[name="extension_floating_char_position"]').on('change', onExtensionFloatingCharPositionInput);

View File

@ -2285,7 +2285,7 @@ async function checkWorldInfo(chat, maxContext) {
if (shouldWIAddPrompt) {
const originalAN = context.extensionPrompts[NOTE_MODULE_NAME].value;
const ANWithWI = `${ANTopEntries.join('\n')}\n${originalAN}\n${ANBottomEntries.join('\n')}`;
context.setExtensionPrompt(NOTE_MODULE_NAME, ANWithWI, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth], extension_settings.note.allowWIScan);
context.setExtensionPrompt(NOTE_MODULE_NAME, ANWithWI, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth], extension_settings.note.allowWIScan, chat_metadata[metadata_keys.role]);
}
return { worldInfoBefore, worldInfoAfter, WIDepthEntries, allActivatedEntries };