Skip to content

Commit 4602f1b

Browse files
author
prima
committed
ci: Store original data along with WI as a backup. Use lorebook name if it is present. Small fix for embedding model error.
1 parent 84a64ba commit 4602f1b

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

klite.embd

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5282,12 +5282,13 @@ Current version indicated by LITEVER below.
52825282
}
52835283
}
52845284

5285-
function saveLorebookToIndexDB(filename, data)
5285+
function saveLorebookToIndexDB(filename, data, originalData)
52865286
{
52875287
let charName = filename.replaceAll(/[^\w()_\-'",!\[\].]/g, " ").replaceAll(/\s+/g, " ").trim();
52885288
let dataToSave = {
52895289
name: charName,
5290-
data: data
5290+
data: data,
5291+
originalData: originalData
52915292
}
52925293
indexeddb_save(`character_${charName}`, JSON.stringify(dataToSave)).then(() => {
52935294
allCharacterNames.push({name: charName, type: "World Info"})
@@ -36423,11 +36424,14 @@ let checkFinalThoughtsPrompt = `Action: {"command":{"name":"thought","args":{"me
3642336424
}
3642436425

3642536426
let getEmbeddingPresetFromModel = () => {
36426-
let embeddingPreset = embeddingPresets[Object.keys(embeddingPresets).filter(presetName => !!get_kcpp_embedding_model()?.includes(presetName))]
36427-
if (!!embeddingPreset && (!documentdb_sqPrefix && !documentdb_cPrefix))
36427+
if (get_kcpp_embedding_model() !== false)
3642836428
{
36429-
documentdb_sqPrefix = embeddingPreset.query_prompt
36430-
documentdb_cPrefix = embeddingPreset.document_prompt
36429+
let embeddingPreset = embeddingPresets[Object.keys(embeddingPresets).filter(presetName => !!get_kcpp_embedding_model()?.includes(presetName))]
36430+
if (!!embeddingPreset && (!documentdb_sqPrefix && !documentdb_cPrefix))
36431+
{
36432+
documentdb_sqPrefix = embeddingPreset.query_prompt
36433+
documentdb_cPrefix = embeddingPreset.document_prompt
36434+
}
3643136435
}
3643236436
}
3643336437

@@ -37586,7 +37590,7 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3758637590
charIcon.onclick = async () => {
3758737591
if (type === "Character")
3758837592
{
37589-
let contents = "<span />";
37593+
let contents = document.createElement("span");
3759037594
try
3759137595
{
3759237596
let data = await getCharacterData(name), {image} = data;
@@ -37634,11 +37638,11 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3763437638
}
3763537639
else if (type === "World Info")
3763637640
{
37637-
let contents = "<span />";
37641+
let contents = document.createElement("span");
3763837642
try
3763937643
{
3764037644
let data = await getCharacterData(name);
37641-
let contents = createDetailsContent(name);
37645+
contents = createDetailsContent(name);
3764237646
createSection(contents, "World info", data?.data?.map(entry => {
3764337647
return wiEntryToString(entry);
3764437648
}));
@@ -37647,7 +37651,7 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3764737651
{
3764837652
console.error(e)
3764937653
}
37650-
37654+
3765137655
popupUtils.reset().title("World Info Options").content(contents).button("Add to WI", async () => {
3765237656
popupUtils.reset()
3765337657
let charData = await getCharacterData(name)
@@ -37689,21 +37693,44 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3768937693
else
3769037694
{
3769137695
let wiToAdd = JSON.parse(plaintext);
37692-
let has_tav_wi_check = has_tavern_wi_check(wiToAdd);
37696+
let has_tav_wi_check = has_tavern_wi_check(wiToAdd), wiName = fileName;
3769337697
if(has_tav_wi_check)
3769437698
{
37699+
if (wiToAdd?.name !== undefined)
37700+
{
37701+
wiName = wiToAdd.name
37702+
}
3769537703
wiToAdd = load_tavern_wi(wiToAdd);
3769637704
if(wiToAdd && wiToAdd.length > 0)
3769737705
{
3769837706
wiToAdd.forEach(wi => wi.wigroup = fileName.replace("'", ""))
3769937707
}
3770037708
}
37709+
else
37710+
{
37711+
try
37712+
{
37713+
let hasNoGeneralWI = wiToAdd.length === 0 || wiToAdd.find(wi => wi?.wigroup === undefined || wi.wigroup.trim() === null || wi.wigroup === "" || wi.wigroup === "General") === undefined;
37714+
if (hasNoGeneralWI)
37715+
{
37716+
let wiAllHaveSameGroup = wiToAdd.find((e, p, a) => a.find(c => c?.wigroup !== e.wigroup)) === undefined
37717+
if (wiAllHaveSameGroup)
37718+
{
37719+
wiName = wiToAdd[0].wigroup
37720+
}
37721+
}
37722+
}
37723+
catch (e)
37724+
{
37725+
console.error(e)
37726+
}
37727+
}
3770137728
if (Array.isArray(wiToAdd))
3770237729
{
3770337730
wiToAdd = wiToAdd.filter(wi => wi?.key !== undefined)
3770437731
if (wiToAdd.length > 0)
3770537732
{
37706-
saveLorebookToIndexDB(fileName, wiToAdd)
37733+
saveLorebookToIndexDB(wiName, wiToAdd, JSON.parse(plaintext))
3770737734
}
3770837735
}
3770937736
}

0 commit comments

Comments
 (0)