Add order of entries.

This commit is contained in:
SillyLossy
2023-02-21 23:31:19 +02:00
parent 406724f200
commit 3686971848
6 changed files with 76 additions and 34 deletions

View File

@@ -730,17 +730,17 @@
let needsToScan = true;
let allActivatedEntries = new Set();
const sortedEntries = Object.keys(world_info_data.entries).map(x => world_info_data.entries[x]).sort((a, b) => (b.constant - a.constant) || (b.order - a.order));
while (needsToScan) {
let activatedNow = [];
let activatedNow = new Set();
for (let entryUid in world_info_data.entries) {
const entry = world_info_data.entries[entryUid];
for (let entry of sortedEntries) {
if (allActivatedEntries.has(entry.uid)) {
continue;
}
if (entry.constant) {
activatedNow.push(entry.uid);
activatedNow.add(entry.uid);
}
if (Array.isArray(entry.key) && entry.key.length) {
@@ -749,12 +749,12 @@
if (entry.selective && Array.isArray(entry.keysecondary) && entry.keysecondary.length) {
secondary: for (let keysecondary of entry.keysecondary) {
if (keysecondary && textToScan.includes(keysecondary.trim().toLowerCase())) {
activatedNow.push(entry.uid);
activatedNow.add(entry.uid);
break secondary;
}
}
} else {
activatedNow.push(entry.uid);
activatedNow.add(entry.uid);
break primary;
}
}
@@ -762,8 +762,11 @@
}
}
needsToScan = activatedNow.length > 0;
const newContents = activatedNow.map(x => world_info_data.entries[x]).map(x => x.content);
needsToScan = activatedNow.size > 0;
const newContents = [...activatedNow]
.map(x => world_info_data.entries[x])
.sort((a, b) => sortedEntries.indexOf(a) - sortedEntries.indexOf(b))
.map(x => x.content);
for (const content of newContents) {
worldInfo = `${worldInfo}${content}\n`;
@@ -3336,7 +3339,7 @@
contentInput.val(entry.content).trigger('input');
// selective
const selectiveInput = template.find('input[name="selective"]')
const selectiveInput = template.find('input[name="selective"]');
selectiveInput.data('uid', entry.uid);
selectiveInput.on('input', function() {
const uid = $(this).data('uid');
@@ -3354,7 +3357,7 @@
// constant
const constantInput = template.find('input[name="constant"]')
const constantInput = template.find('input[name="constant"]');
constantInput.data('uid', entry.uid);
constantInput.on('input', function() {
const uid = $(this).data('uid');
@@ -3367,6 +3370,17 @@
$(this).siblings('input').click();
});
// order
const orderInput = template.find('input[name="order"]');
orderInput.data('uid', entry.uid);
orderInput.on('input', function() {
const uid = $(this).data('uid');
const value = Number($(this).val());
world_info_data.entries[uid].order = !isNaN(value) ? value : 0;
saveWorldInfo();
});
orderInput.val(entry.order).trigger('input');
// display uid
template.find('.world_entry_form_uid_value').html(entry.uid);
@@ -3400,6 +3414,7 @@
content: '',
constant: false,
selective: false,
order: 0,
};
const newUid = getFreeWorldEntryUid();
@@ -3654,26 +3669,37 @@
<div id="entry_edit_template">
<div class="world_entry">
<form class="world_entry_form">
<div class="world_entry_form_control">
<label for="key">
<h4>Key</h4>
<h5>Comma-separated list of keywords (e.g: foo,bar).</h5>
</label>
<input class="text_pole" type="text" name="key" placeholder=""/>
<div class="world_entry_thin_controls">
<div class="world_entry_form_control">
<label for="key">
<h4>Key</h4>
<h5>Comma-separated list of keywords (e.g: foo,bar).</h5>
</label>
<input class="text_pole" type="text" name="key" placeholder=""/>
</div>
<div class="world_entry_form_control keysecondary">
<label for="keysecondary">
<h4>Secondary Key</h4>
<h5>Comma-separated list of additional keywords.</h5>
</label>
<input class="text_pole" type="text" name="keysecondary" placeholder=""/>
</div>
</div>
<div class="world_entry_form_control keysecondary">
<label for="keysecondary">
<h4>Secondary Key</h4>
<h5>Comma-separated list of additional keywords (e.g: foo,bar).</h5>
</label>
<input class="text_pole" type="text" name="keysecondary" placeholder=""/>
</div>
<div class="world_entry_form_control">
<label for="comment">
<h4>Comment</h4>
<h5>Optional comment (doesn't affect the AI).</h5>
</label>
<input class="text_pole" type="text" name="comment" placeholder=""/>
<div class="world_entry_thin_controls">
<div class="world_entry_form_control">
<label for="order">
<h4>Insertion Order</h4>
<h5>Higher order number entries will be inserted first.</h5>
</label>
<input class="text_pole" type="number" name="order" placeholder=""/>
</div>
<div class="world_entry_form_control">
<label for="comment">
<h4>Comment</h4>
<h5>Optional comment (doesn't affect the AI).</h5>
</label>
<input class="text_pole" type="text" name="comment" placeholder=""/>
</div>
</div>
<div class="world_entry_form_control">
<label for="content">
@@ -3934,11 +3960,11 @@
Scan Depth (<a href="/notes/13_1.html" target="_blank">?</a>)
</h4>
<h5 id="world_info_depth_counter">depth</h5>
<input type="range" id="world_info_depth" name="volume" min="1" max="5" step="1">
<input type="range" id="world_info_depth" name="volume" min="1" max="10" step="1">
</div>
<div id="world_info_budget_block">
<h4>
Budget (<a href="/notes/13_2.html" target="_blank">?</a>)
Token Budget (<a href="/notes/13_2.html" target="_blank">?</a>)
</h4>
<h5 id="world_info_budget_counter">budget</h5>
<input type="range" id="world_info_budget" name="volume" min="100" max="500" step="1">

View File

@@ -29,6 +29,8 @@
<dd>A list of supplementary keywords that are used in conjunction with the main keywords (see <a href="#Selective">Selective</a>).</dd>
<dt>Content</dt>
<dd>The text that is inserted into the prompt upon entry activation.</dd>
<dt>Insertion Order</dt>
<dd>Numeric value. Defines a priority of the entry if multiple were activated at once. Entries with higher order number will be inserted first.</dd>
<dt>Comment</dt>
<dd>A supplemental text comment for the your convenience, which is not utilized by the AI.</dd>
<dt>Constant</dt>

View File

@@ -13,7 +13,7 @@
<h2>Scan Depth</h2>
<h4>Defines how many messages in the chat history should be scanned for World Info keys.</h4>
<p>If set to 1, then TavernAI only scans the message you send and the most recent reply.</p>
<p>This stacks up to 5 message pairs it total.</p>
<p>This stacks up to 10 message pairs it total.</p>
</div>
</div>
</body>

View File

@@ -13,7 +13,8 @@
<h2>World Info Budget</h2>
<h4>Defines how many tokens could be used by World Info entries at once.</h4>
<p>If the budget was exhausted, then no more entries are activated even if the keys are present in the prompt.</p>
<p>Constant entries always take the priority.</p>
<p>Constant entries will be inserted first. Then entries with higher order numbers.</p>
<p>Entries inserted by direct mentioning of their keys have higher priority than those that were mentioned in other entries contents.</p>
</div>
</div>
</body>

View File

@@ -1315,6 +1315,19 @@ input[type=button] {
margin: 0 10px;
}
.world_entry_thin_controls {
display: flex;
flex-direction: row;
}
.world_entry_thin_controls > div {
flex: 1;
}
.checkbox_fancy {
cursor: pointer;
}
.world_entry_form_control label {
margin-left: 10px;
}

File diff suppressed because one or more lines are too long