mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix LLAMA tokenization. Add case-sensitive WI matching
This commit is contained in:
@ -1458,7 +1458,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex1 range-block">
|
<div class="flex1 range-block flex-container flexFlowColumn">
|
||||||
<label title="Entries can activate other entries by mentioning their keywords" class="checkbox_label">
|
<label title="Entries can activate other entries by mentioning their keywords" class="checkbox_label">
|
||||||
<input id="world_info_recursive" type="checkbox" />
|
<input id="world_info_recursive" type="checkbox" />
|
||||||
<span>
|
<span>
|
||||||
@ -1468,6 +1468,15 @@
|
|||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label title="Lookup for the entry keys in the context will respect the case" class="checkbox_label">
|
||||||
|
<input id="world_info_case_sensitive" type="checkbox" />
|
||||||
|
<span>
|
||||||
|
Case-sensitive keys
|
||||||
|
<a href="/notes#casesensitivekeys" class="notes-link" target="_blank">
|
||||||
|
<span class="note-link-span">?</span>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ _It is important to note that while World Info helps guide the AI towards your d
|
|||||||
|
|
||||||
#### Key
|
#### Key
|
||||||
|
|
||||||
A list of keywords that trigger the activation of a World Info entry.
|
A list of keywords that trigger the activation of a World Info entry. Keys are not case-sensitive by default (this is [configurable](#casesensitivekeys)).
|
||||||
|
|
||||||
#### Secondary Key
|
#### Secondary Key
|
||||||
|
|
||||||
@ -234,6 +234,14 @@ Content: Rufus is a dog.
|
|||||||
|
|
||||||
**Both** of them will be pulled into the context if the message text mentions **just Bessie**.
|
**Both** of them will be pulled into the context if the message text mentions **just Bessie**.
|
||||||
|
|
||||||
|
### Case-sensitive keys
|
||||||
|
|
||||||
|
**To get pulled into the context, entry keys need to match the case as they are defined in the World Info entry.**
|
||||||
|
|
||||||
|
This is useful when your keys are common words or parts of common words.
|
||||||
|
|
||||||
|
For example, when this setting is active, keys 'rose' and 'Rose' will be treated differently, depending on the inputs.
|
||||||
|
|
||||||
## KoboldAI
|
## KoboldAI
|
||||||
|
|
||||||
### Basic Settings
|
### Basic Settings
|
||||||
|
@ -458,7 +458,7 @@ function getTokenCount(str, padding = undefined) {
|
|||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
async: false,
|
async: false,
|
||||||
type: 'POST', //
|
type: 'POST', //
|
||||||
url: `/ tokenize_llama`,
|
url: `/tokenize_llama`,
|
||||||
data: JSON.stringify({ text: str }),
|
data: JSON.stringify({ text: str }),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
@ -3852,6 +3852,7 @@ async function saveSettings(type) {
|
|||||||
world_info_depth: world_info_depth,
|
world_info_depth: world_info_depth,
|
||||||
world_info_budget: world_info_budget,
|
world_info_budget: world_info_budget,
|
||||||
world_info_recursive: world_info_recursive,
|
world_info_recursive: world_info_recursive,
|
||||||
|
world_info_case_sensitive: world_info_case_sensitive,
|
||||||
textgenerationwebui_settings: textgenerationwebui_settings,
|
textgenerationwebui_settings: textgenerationwebui_settings,
|
||||||
swipes: swipes,
|
swipes: swipes,
|
||||||
horde_settings: horde_settings,
|
horde_settings: horde_settings,
|
||||||
|
@ -7,6 +7,7 @@ export {
|
|||||||
world_info_budget,
|
world_info_budget,
|
||||||
world_info_depth,
|
world_info_depth,
|
||||||
world_info_recursive,
|
world_info_recursive,
|
||||||
|
world_info_case_sensitive,
|
||||||
world_names,
|
world_names,
|
||||||
imported_world_name,
|
imported_world_name,
|
||||||
checkWorldInfo,
|
checkWorldInfo,
|
||||||
@ -23,6 +24,7 @@ let world_info_depth = 2;
|
|||||||
let world_info_budget = 128;
|
let world_info_budget = 128;
|
||||||
let is_world_edit_open = false;
|
let is_world_edit_open = false;
|
||||||
let world_info_recursive = false;
|
let world_info_recursive = false;
|
||||||
|
let world_info_case_sensitive = false;
|
||||||
let imported_world_name = "";
|
let imported_world_name = "";
|
||||||
const saveWorldDebounced = debounce(async () => await _save(), 500);
|
const saveWorldDebounced = debounce(async () => await _save(), 500);
|
||||||
const saveSettingsDebounced = debounce(() => saveSettings(), 500);
|
const saveSettingsDebounced = debounce(() => saveSettings(), 500);
|
||||||
@ -51,6 +53,8 @@ function setWorldInfoSettings(settings, data) {
|
|||||||
world_info_budget = Number(settings.world_info_budget);
|
world_info_budget = Number(settings.world_info_budget);
|
||||||
if (settings.world_info_recursive !== undefined)
|
if (settings.world_info_recursive !== undefined)
|
||||||
world_info_recursive = Boolean(settings.world_info_recursive);
|
world_info_recursive = Boolean(settings.world_info_recursive);
|
||||||
|
if (settings.world_info_case_sensitive !== undefined)
|
||||||
|
world_info_case_sensitive = Boolean(settings.world_info_case_sensitive);
|
||||||
|
|
||||||
$("#world_info_depth_counter").text(world_info_depth);
|
$("#world_info_depth_counter").text(world_info_depth);
|
||||||
$("#world_info_depth").val(world_info_depth);
|
$("#world_info_depth").val(world_info_depth);
|
||||||
@ -59,6 +63,7 @@ function setWorldInfoSettings(settings, data) {
|
|||||||
$("#world_info_budget").val(world_info_budget);
|
$("#world_info_budget").val(world_info_budget);
|
||||||
|
|
||||||
$("#world_info_recursive").prop('checked', world_info_recursive);
|
$("#world_info_recursive").prop('checked', world_info_recursive);
|
||||||
|
$("#world_info_case_sensitive").prop('checked', world_info_case_sensitive);
|
||||||
|
|
||||||
world_names = data.world_names?.length ? data.world_names : [];
|
world_names = data.world_names?.length ? data.world_names : [];
|
||||||
|
|
||||||
@ -476,13 +481,18 @@ async function createNewWorldInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets a string that respects the case sensitivity setting
|
||||||
|
function transformString(str) {
|
||||||
|
return world_info_case_sensitive ? str : str.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
function checkWorldInfo(chat) {
|
function checkWorldInfo(chat) {
|
||||||
if (world_info_data.entries.length == 0) {
|
if (world_info_data.entries.length == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const messagesToLookBack = world_info_depth * 2;
|
const messagesToLookBack = world_info_depth * 2;
|
||||||
let textToScan = chat.slice(0, messagesToLookBack).join("").toLowerCase();
|
let textToScan = transformString(chat.slice(0, messagesToLookBack).join(""));
|
||||||
let worldInfoBefore = "";
|
let worldInfoBefore = "";
|
||||||
let worldInfoAfter = "";
|
let worldInfoAfter = "";
|
||||||
let needsToScan = true;
|
let needsToScan = true;
|
||||||
@ -507,7 +517,7 @@ function checkWorldInfo(chat) {
|
|||||||
if (Array.isArray(entry.key) && entry.key.length) {
|
if (Array.isArray(entry.key) && entry.key.length) {
|
||||||
primary: for (let key of entry.key) {
|
primary: for (let key of entry.key) {
|
||||||
const substituted = substituteParams(key);
|
const substituted = substituteParams(key);
|
||||||
if (substituted && textToScan.includes(substituted.trim().toLowerCase())) {
|
if (substituted && textToScan.includes(transformString(substituted.trim()))) {
|
||||||
if (
|
if (
|
||||||
entry.selective &&
|
entry.selective &&
|
||||||
Array.isArray(entry.keysecondary) &&
|
Array.isArray(entry.keysecondary) &&
|
||||||
@ -517,7 +527,7 @@ function checkWorldInfo(chat) {
|
|||||||
const secondarySubstituted = substituteParams(keysecondary);
|
const secondarySubstituted = substituteParams(keysecondary);
|
||||||
if (
|
if (
|
||||||
secondarySubstituted &&
|
secondarySubstituted &&
|
||||||
textToScan.includes(secondarySubstituted.trim().toLowerCase())
|
textToScan.includes(transformString(secondarySubstituted.trim()))
|
||||||
) {
|
) {
|
||||||
activatedNow.add(entry.uid);
|
activatedNow.add(entry.uid);
|
||||||
break secondary;
|
break secondary;
|
||||||
@ -557,11 +567,7 @@ function checkWorldInfo(chat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needsToScan) {
|
if (needsToScan) {
|
||||||
textToScan =
|
textToScan = (transformString(newEntries.map(x => x.content).join('\n')) + textToScan);
|
||||||
newEntries
|
|
||||||
.map((x) => x.content)
|
|
||||||
.join("\n")
|
|
||||||
.toLowerCase() + textToScan;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allActivatedEntries = new Set([...allActivatedEntries, ...activatedNow]);
|
allActivatedEntries = new Set([...allActivatedEntries, ...activatedNow]);
|
||||||
@ -583,7 +589,7 @@ function selectImportedWorldInfo() {
|
|||||||
imported_world_name = "";
|
imported_world_name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
jQuery(() => {
|
||||||
$("#world_info").change(async function () {
|
$("#world_info").change(async function () {
|
||||||
const selectedWorld = $("#world_info").find(":selected").val();
|
const selectedWorld = $("#world_info").find(":selected").val();
|
||||||
world_info = null;
|
world_info = null;
|
||||||
@ -688,4 +694,9 @@ $(document).ready(() => {
|
|||||||
world_info_recursive = !!$(this).prop('checked');
|
world_info_recursive = !!$(this).prop('checked');
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$('#world_info_case_sensitive').on('input', function () {
|
||||||
|
world_info_case_sensitive = !!$(this).prop('checked');
|
||||||
|
saveSettingsDebounced();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user