Skip to content

Commit 36b28b7

Browse files
author
prima
committed
feat: Added temp memory
1 parent b1484a8 commit 36b28b7

File tree

1 file changed

+58
-23
lines changed

1 file changed

+58
-23
lines changed

klite.embd

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,7 @@ Current version indicated by LITEVER below.
36363636
var pending_context_postinjection = ""; //this will be injected after the AI's next RESPONSE
36373637
var last_reply_was_empty = false; //set to true if last reply is empty
36383638
var current_memory = ""; //stored memory
3639+
var current_temp_memory = "";
36393640
var current_anote = ""; //stored author note
36403641
var current_anotetemplate = "[Author\'s note: <|>]";
36413642

@@ -8309,6 +8310,7 @@ Current version indicated by LITEVER below.
83098310
new_save_storyobj.anotetemplate = current_anotetemplate;
83108311
new_save_storyobj.authorsnote = current_anote;
83118312
new_save_storyobj.memory = current_memory;
8313+
new_save_storyobj.tempmemory = current_temp_memory;
83128314
new_save_storyobj.worldinfo = current_wi;
83138315

83148316
//extra unofficial fields for the story
@@ -8519,7 +8521,7 @@ Current version indicated by LITEVER below.
85198521
{
85208522
return true;
85218523
}
8522-
return (gametext_arr.length == 0 && current_memory == "" && current_anote == "" && current_wi.length == 0 && redo_arr.length == 0);
8524+
return (gametext_arr.length == 0 && current_memory == "" && current_temp_memory == "" && current_anote == "" && current_wi.length == 0 && redo_arr.length == 0);
85238525
}
85248526

85258527
function is_kai_json(obj)
@@ -8537,6 +8539,7 @@ Current version indicated by LITEVER below.
85378539
let old_current_anote = current_anote;
85388540
let old_current_anotetemplate = current_anotetemplate;
85398541
let old_current_memory = current_memory;
8542+
let old_current_temp_memory = current_temp_memory;
85408543
let old_current_wi = current_wi;
85418544
let old_notes = personal_notes;
85428545
let old_newlineaftermemory = newlineaftermemory;
@@ -8597,6 +8600,9 @@ Current version indicated by LITEVER below.
85978600
if (storyobj.memory) {
85988601
current_memory = storyobj.memory;
85998602
}
8603+
if (storyobj.tempmemory) {
8604+
current_temp_memory = storyobj.tempmemory;
8605+
}
86008606
if (storyobj.worldinfo) {
86018607
current_wi = storyobj.worldinfo;
86028608
}
@@ -8721,6 +8727,9 @@ Current version indicated by LITEVER below.
87218727
if (storyobj.memory) {
87228728
current_memory = storyobj.memory;
87238729
}
8730+
if (storyobj.tempmemory) {
8731+
current_temp_memory = storyobj.tempmemory;
8732+
}
87248733
if (storyobj.worldinfo_v2 != null && storyobj.worldinfo_v2.entries != null) {
87258734
for (var key in storyobj.worldinfo_v2.entries) {
87268735
var itm = storyobj.worldinfo_v2.entries[key];
@@ -8755,6 +8764,7 @@ Current version indicated by LITEVER below.
87558764
current_anote = old_current_anote;
87568765
current_anotetemplate = old_current_anotetemplate;
87578766
current_memory = old_current_memory;
8767+
current_temp_memory = old_current_temp_memory;
87588768
personal_notes = old_notes;
87598769
newlineaftermemory = old_newlineaftermemory;
87608770
}
@@ -9124,6 +9134,7 @@ Current version indicated by LITEVER below.
91249134
memory += obj.personality?("\nPersonality: "+obj.personality):"";
91259135
let scenario = obj.scenario?obj.scenario:"";
91269136
let examplemsg = obj.mes_example?obj.mes_example:"";
9137+
examplemsg = formatExampleMessages(examplemsg);
91279138
let sysprompt = obj.system_prompt?obj.system_prompt:"";
91289139
let greeting = selectedgreeting;
91299140

@@ -9132,15 +9143,11 @@ Current version indicated by LITEVER below.
91329143
{
91339144
scenario = "\n[Scenario: "+scenario+"]";
91349145
}
9135-
if(examplemsg!="")
9136-
{
9137-
examplemsg = "\n"+examplemsg;
9138-
}
91399146
if(sysprompt!="")
91409147
{
91419148
sysprompt = sysprompt+"\n";
91429149
}
9143-
let combinedmem = sysprompt + memory + scenario + examplemsg;
9150+
let combinedmem = sysprompt + memory + scenario;
91449151
let agnaidatafieldsempty = scenario + examplemsg + (obj.personality?obj.personality:"") + greeting;
91459152
let has_tav_wi_check = has_tavern_wi_check(obj);
91469153
//check if it's a world info only card, if so, do not restart game
@@ -9163,6 +9170,7 @@ Current version indicated by LITEVER below.
91639170
localsettings.chatname = myname;
91649171
localsettings.chatopponent = chatopponent;
91659172
current_memory = combinedmem + "\n***";
9173+
current_temp_memory = examplemsg + "\n***";
91669174
localsettings.multiline_replies = true;
91679175
if(usechatmode)
91689176
{
@@ -9230,15 +9238,12 @@ Current version indicated by LITEVER below.
92309238
{
92319239
scenario = "\n[Scenario: "+scenario+"]";
92329240
}
9233-
if(examplemsg!="")
9234-
{
9235-
examplemsg = "\n"+examplemsg;
9236-
}
92379241
restart_new_game(false);
92389242
localsettings.chatname = myname;
92399243
localsettings.chatopponent = chatopponent;
92409244
gametext_arr.push("\n"+chatopponent+": "+greeting);
9241-
current_memory = memory + scenario + examplemsg + "\n***";
9245+
current_memory = memory + scenario + "\n***";
9246+
current_temp_memory = examplemsg
92429247
localsettings.opmode = 3;
92439248
if(localsettings.gui_type_chat!=3)
92449249
{
@@ -9355,6 +9360,7 @@ Current version indicated by LITEVER below.
93559360
{
93569361
examplemsg = obj.mesExample;
93579362
}
9363+
examplemsg = formatExampleMessages(examplemsg);
93589364
if(greeting=="" && obj.firstMes!="")
93599365
{
93609366
greeting = obj.firstMes;
@@ -9364,22 +9370,19 @@ Current version indicated by LITEVER below.
93649370
{
93659371
scenario = "\n[Scenario: "+scenario+"]";
93669372
}
9367-
if(examplemsg!="")
9368-
{
9369-
examplemsg = "\n"+examplemsg;
9370-
}
93719373
if(sysprompt!="")
93729374
{
93739375
sysprompt = sysprompt+"\n";
93749376
}
9375-
let combinedmem = sysprompt + memory + scenario + examplemsg;
9377+
let combinedmem = sysprompt + memory + scenario;
93769378
temp_scenario.title = chatopponent;
93779379
let prev2 = replaceAll(obj.description,"{{char}}",chatopponent,true);
93789380
prev2 = replaceAll(prev2,"{{user}}","User",true);
93799381
temp_scenario.desc = prev2;
93809382
temp_scenario.chatopponent = chatopponent;
93819383
temp_scenario.prompt = ("\n{{char}}: "+ greeting);
93829384
temp_scenario.memory = combinedmem;
9385+
temp_scenario.tempmemory = examplemsg;
93839386

93849387
//since cai format has no wi, try to grab it from tavern format
93859388
let myname = ((localsettings.chatname && localsettings.chatname!="")?localsettings.chatname:"User");
@@ -9639,6 +9642,13 @@ Current version indicated by LITEVER below.
96399642
current_memory = replace_placeholders(current_memory, false, true, false);
96409643
}
96419644
}
9645+
if (temp_scenario.tempmemory != "") {
9646+
current_temp_memory = temp_scenario.tempmemory;
9647+
if(!localsettings.placeholder_tags)
9648+
{
9649+
current_temp_memory = replace_placeholders(current_temp_memory, false, true, false);
9650+
}
9651+
}
96429652
if (temp_scenario.image && temp_scenario.image != "") {
96439653
aestheticInstructUISettings.AI_portrait = temp_scenario.image;
96449654
document.getElementById('portrait_ratio_AI').value = (temp_scenario.image_aspect?temp_scenario.image_aspect:1).toFixed(2);
@@ -14907,6 +14917,7 @@ Current version indicated by LITEVER below.
1490714917

1490814918
function confirm_memory() {
1490914919
current_memory = document.getElementById("memorytext").value;
14920+
current_temp_memory = document.getElementById("tempmemorytext").value;
1491014921
current_anote = document.getElementById("anotetext").value;
1491114922
current_anotetemplate = document.getElementById("anotetemplate").value;
1491214923
anote_strength = document.getElementById("anote_strength").value;
@@ -15360,6 +15371,7 @@ Current version indicated by LITEVER below.
1536015371
{
1536115372
personal_notes = "";
1536215373
current_memory = "";
15374+
current_temp_memory = "";
1536315375
current_anote = "";
1536415376
current_wi = [];
1536515377
anote_strength = 320;
@@ -17083,7 +17095,7 @@ Current version indicated by LITEVER below.
1708317095
const user_input_empty = (newgen.trim()=="");
1708417096
pending_context_postinjection = "";
1708517097

17086-
if (!user_input_empty || gametext_arr.length > 0 || current_memory != "" || current_anote != "")
17098+
if (!user_input_empty || gametext_arr.length > 0 || current_memory != "" || current_temp_memory != "" || current_anote != "")
1708717099
{
1708817100
waiting_for_tool_call = 0;
1708917101
idle_timer = 0;
@@ -17195,7 +17207,7 @@ Current version indicated by LITEVER below.
1719517207
}
1719617208
}
1719717209

17198-
let truncated_context = concat_gametext(true, "","","",false,true); //no need to truncate if memory is empty
17210+
let truncated_context = `${current_temp_memory}${concat_gametext(true, "","","",false,true)}`; //no need to truncate if memory is empty
1719917211
truncated_context = truncated_context.replace(/\xA0/g,' '); //replace non breaking space nbsp
1720017212

1720117213
//remove past thoughts
@@ -23266,6 +23278,7 @@ Current version indicated by LITEVER below.
2326623278

2326723279
//setup memory tab
2326823280
document.getElementById("memorytext").value = current_memory;
23281+
document.getElementById("tempmemorytext").value = current_temp_memory;
2326923282
document.getElementById("anotetext").value = current_anote;
2327023283
document.getElementById("anotetemplate").value = current_anotetemplate;
2327123284
document.getElementById("anote_strength").value = anote_strength;
@@ -23824,7 +23837,7 @@ Current version indicated by LITEVER below.
2382423837
let memory = charData.description
2382523838
if (!!charData?.mes_example)
2382623839
{
23827-
memory += `\n\n${charData?.mes_example}`
23840+
memory += `\n\n${formatExampleMessages(charData?.mes_example)}`
2382823841
}
2382923842
let firstMessage = charData.first_mes
2383023843
let alternateGreetings = !!charData?.alternate_greetings ? charData?.alternate_greetings : []
@@ -24011,7 +24024,7 @@ Current version indicated by LITEVER below.
2401124024

2401224025
function btn_retry() {
2401324026
if (!document.getElementById("btnsend").disabled && pending_response_id == "" && (gametext_arr.length > 1 ||
24014-
(gametext_arr.length > 0 && (current_memory != "" || current_anote != "")))) {
24027+
(gametext_arr.length > 0 && (current_memory != "" || current_temp_memory != "" || current_anote != "")))) {
2401524028
warn_unsaved = true;
2401624029
last_reply_was_empty = false;
2401724030
let boxtextstash = document.getElementById("input_text").value;
@@ -25867,6 +25880,19 @@ Current version indicated by LITEVER below.
2586725880
</div>
2586825881
<textarea title="Edit Memory" class="form-control menuinput_multiline" id="memorytext" style="height: 160px;"
2586925882
placeholder="Edit the memory to be sent with each request to the AI."></textarea>
25883+
<div class="settinglabel">
25884+
<span class="justifyleft">Temporary Memory<span class="helpicon">?<span
25885+
class="helptext">Put the information you want the AI to know at the start (until you fill the context). Placeholder tags can be used.</span></span>
25886+
</span>
25887+
<span class="justifyright flex-push-right" >
25888+
<div class="settinglabel" style="padding-top: 4px;">
25889+
<div class="justifyleft settingsmall" title="Add newline after injecting memory text">Newline After Memory </div>
25890+
<input type="checkbox" title="Add Newline After Memory" id="newlineaftermemory" style="margin:0px 0 0;" checked>
25891+
</div>
25892+
</span>
25893+
</div>
25894+
<textarea title="Edit Temporary Memory" class="form-control menuinput_multiline" id="tempmemorytext" style="height: 160px;"
25895+
placeholder="Edit the temporary memory at the top of the context."></textarea>
2587025896
<div class="settinglabel">
2587125897
<div class="justifyleft"><br>Author's Note<span class="helpicon">?<span
2587225898
class="helptext">Similar to Memory, but inserted near the end of the text instead of the start. A good way to control the mood/behavior of the AI.</span></span></div>
@@ -35703,11 +35729,11 @@ let checkFinalThoughtsPrompt = `Action: {"command":{"name":"thought","args":{"me
3570335729
if (wi_insertlocation === "0") // WI after memory
3570435730
{
3570535731
history += wiToInclude
35706-
history += cotAsText
35732+
history += substring_to_boundary(current_temp_memory + cotAsText, maxLengthOfCot)
3570735733
}
3570835734
else
3570935735
{
35710-
history += cotAsText
35736+
history += substring_to_boundary(current_temp_memory + cotAsText, maxLengthOfCot)
3571135737
history += wiToInclude
3571235738
}
3571335739
history += anToInclude
@@ -38053,7 +38079,7 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3805338079
try
3805438080
{
3805538081
let data = await getCharacterData(name), {image} = data;
38056-
let {description, first_mes, alternate_greetings, character_book, tags, creator, creator_notes, personality } = (data)?.data;
38082+
let {description, first_mes, mes_example, alternate_greetings, character_book, tags, creator, creator_notes, personality } = (data)?.data;
3805738083
contents = createDetailsContent(name);
3805838084
if (!!image)
3805938085
{
@@ -38068,6 +38094,7 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3806838094
createSection(contents, "Tags", tags);
3806938095
createSection(contents, "Creators notes", creator_notes);
3807038096
createSection(contents, "Memory", description);
38097+
createSection(contents, "Temporary memory", formatExampleMessages(mes_example));
3807138098
createSection(contents, "Alternative greetings", [first_mes, ...(alternate_greetings || [])]);
3807238099
createSection(contents, "Personality", personality);
3807338100
createSection(contents, "World info", character_book?.entries?.map(entry => {
@@ -38457,6 +38484,14 @@ flowchart TD\n${treeToViewOutput.outputText.trim()}`
3845738484
handleError(e);
3845838485
}
3845938486
}
38487+
38488+
window.extractExampleMessages = (messagesText) => {
38489+
return messagesText.split("<START>").filter(c => !!c).map(c => c.trim())
38490+
}
38491+
38492+
window.formatExampleMessages = (messageText) => {
38493+
return extractExampleMessages(messageText).map(c => `Example messages:\n\n${c}`).join("\n\n")
38494+
}
3846038495
</script>
3846138496
<script>
3846238497
let addFullScreenEditorButtons = () => {

0 commit comments

Comments
 (0)