From 2338e95c6d5167492a44a750daa1a288bd0b7ac8 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Fri, 16 Feb 2024 23:08:58 +0800 Subject: [PATCH] updated lite --- klite.embd | 101 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 26 deletions(-) diff --git a/klite.embd b/klite.embd index 4bf6f7f4728c4..22a2c565e9560 100644 --- a/klite.embd +++ b/klite.embd @@ -6,7 +6,7 @@ It requires no dependencies, installation or setup. Just copy this single static HTML file anywhere and open it in a browser, or from a webserver. Please go to https://github.com/LostRuins/lite.koboldai.net for updates on Kobold Lite. Kobold Lite is under the AGPL v3.0 License unless otherwise exempted. Please do not remove this line. -Current version: 112 +Current version: 113 -Concedo --> @@ -3154,6 +3154,29 @@ Current version: 112 console.log("beep sound"); } + var bg_silence = null; + var run_in_background = false; + function background_audio_loop(play=false) { + if(play) + { + if(!bg_silence) + { + bg_silence = new Audio("data:audio/wav;base64,UklGRmQBAABXQVZFZm10IBAAAAABAAEAQB8AAIA+AAACABAAZGF0YUABAAAAAAEABQAKABEAHAAoADYARQBaAGoAhQCYALYAzQDuAAgBLAFKAW0BkgGyAdwB/gEnAkwCdAKbAsIC6wIPAzkDXQOEA6gDywPxAw4EMgRPBGwEigSgBLkEzwThBPMEAQUMBRYFHAUfBSEFHAUYBQ8FAwX0BOAEtgSKBFkELgT0A8oDjQNcAyID6QKwAnUCOAL8Ab0BgAFAAQEBwgB+AEQA/f/B/3//Pv8B/77+gf5C/gb+xv2N/U/9F/3e/Kb8bvw9/AX81/ul+3X7Tfsy+yX7EvsK+wD7+/r7+vj6APsD+xD7Gvsp+zn7T/th+337k/uv+8/76fsN/C78Tvx1/Jf8vvzj/An9Mf1V/YD9ov3O/e/9GP46/mL+gv6p/sP+7P4C/yj/Pf9b/3L/if+g/7D/xf/P/+H/6f/y//v//P8CAA=="); + bg_silence.loop = true; + bg_silence.play(); + } + } + else + { + if(bg_silence) + { + bg_silence.loop = false; + bg_silence.pause(); + bg_silence = null; + } + } + } + let notify_allowed = false; function shownotify() { @@ -6368,7 +6391,7 @@ Current version: 112 { let isOpenrouter = (document.getElementById("customapidropdown").value==5); let dropdown = (isOpenrouter?document.getElementById("custom_openrouter_model"):document.getElementById("custom_oai_model")); - let non_completions = (dropdown.value.includes("text-davinci-003") || dropdown.value.includes("text-davinci-002") + let non_completions = (dropdown.value.includes("davinci-002") || dropdown.value.includes("text-davinci-003") || dropdown.value.includes("text-davinci-002") || dropdown.value.includes("text-davinci-001") || dropdown.value.includes("gpt-3.5-turbo-instruct") || dropdown.value == "davinci"); if(isOpenrouter || dropdown.selectedIndex==dropdown.options.length-1) { @@ -7543,6 +7566,7 @@ Current version: 112 document.getElementById("adventure_context_mod").checked = localsettings.adventure_context_mod; document.getElementById("instruct_has_markdown").checked = localsettings.instruct_has_markdown; document.getElementById("placeholder_tags").checked = localsettings.placeholder_tags; + document.getElementById("run_in_background").checked = run_in_background; document.getElementById("auto_ctxlen").checked = localsettings.auto_ctxlen; document.getElementById("auto_genamt").checked = localsettings.auto_genamt; if(localflag) @@ -7749,6 +7773,8 @@ Current version: 112 localsettings.adventure_context_mod = (document.getElementById("adventure_context_mod").checked ? true : false); localsettings.instruct_has_markdown = (document.getElementById("instruct_has_markdown").checked ? true : false); localsettings.placeholder_tags = (document.getElementById("placeholder_tags").checked ? true : false); + run_in_background = (document.getElementById("run_in_background").checked ? true : false); + background_audio_loop(run_in_background); localsettings.generate_images_model = document.getElementById("generate_images_model").value; localsettings.generate_images_mode = document.getElementById("generate_images_mode").value; localsettings.opmode = document.getElementById("opmode").value; @@ -8344,13 +8370,18 @@ Current version: 112 if (p2 > 0 && p2 < first) { first = p2; } if (p3 > 0 && p3 < first) { first = p3; } if (p4 > 0 && p4 < first) { first = p4; skip1 = true; } + let ret = input; if (first > 0) { if (skip1) { - return input.substring(first + 1); + ret = input.substring(first + 1); } else { - return input.substring(first + 2); + ret = input.substring(first + 2); } } + if(ret!="") + { + return ret; + } return input; } @@ -8503,19 +8534,27 @@ Current version: 112 }, 10000); } + function do_auto_gen_image(truncated_context) + { + var tclen = truncated_context.length; + var sentence = truncated_context.substring(tclen - 300, tclen); + sentence = start_trim_to_sentence(sentence); + sentence = end_trim_to_sentence(sentence,true); + if (sentence.length > 0) { + nextgeneratedimagemilestone = tclen + generateimagesinterval; + do_manual_gen_image(sentence); + } + } + function add_img_btn_auto() { let truncated_context = concat_gametext(true, ""); truncated_context = replace_placeholders(truncated_context); var tclen = truncated_context.length; if (tclen > 0) { - var sentence = truncated_context.substring(tclen - 300, tclen); - sentence = start_trim_to_sentence(sentence); - sentence = end_trim_to_sentence(sentence,true); - if (sentence.length > 0) { - nextgeneratedimagemilestone = tclen + generateimagesinterval; - do_manual_gen_image(sentence); - } - }else{ + do_auto_gen_image(truncated_context); + } + else + { msgbox("Error: Your current story is blank.\nAdd some text, or try generating from custom prompt instead.","Story is Blank") } document.getElementById("addimgcontainer").classList.add("hidden"); @@ -9006,12 +9045,7 @@ Current version: 112 //generate every few hundred chars var tclen = truncated_context.length; if (tclen > nextgeneratedimagemilestone) { - nextgeneratedimagemilestone = tclen + generateimagesinterval; //set next milestone and trigger generation, using the last 300 characters advanced to the nearest sentence. - var sentence = truncated_context.substring(tclen - 300, tclen); - sentence = start_trim_to_sentence(sentence); - sentence = end_trim_to_sentence(sentence, true); - generate_new_image(sentence); - + do_auto_gen_image(truncated_context); } } } @@ -12469,7 +12503,12 @@ Current version: 112 newbodystr += getStreamingText(); } // Add the pending stream if it's needed. This will add any streamed text to a new bubble for the AI. newbodystr += contextDict.closeTag + '
'; // Lastly, append the closing div so our body's raw form is completed. - if (aestheticInstructUISettings.use_markdown) { // If markdown is enabled, style the content of each bubble as well. + if (aestheticInstructUISettings.use_markdown) { + + let md = applyStylizedCodeBlocks(); // apply the code-block styling, if markdown is used. + newbodystr = md[0]; + let codestashes = md[1]; + // If markdown is enabled, style the content of each bubble as well. let internalHTMLparts = []; // We'll cache the embedded HTML parts here to keep them intact. for (let role of aestheticTextStyleRoles) { // ..starting by the "speech" and *actions* for each role. let styleRole = aestheticInstructUISettings.use_uniform_colors ? 'uniform' : role; // Uniform role is preferred if it's active on the settings. @@ -12482,7 +12521,10 @@ Current version: 112 }); } internalHTMLparts.forEach((part, index) => { newbodystr = newbodystr.replace(`${m2.replace(/[“”]/g, "\"")}
`}); + function (m,m2) { + let idx = codestashes.length; + codestashes.push(`
${m2.replace(/[“”]/g, "\"")}`); + return `%CodeStash${idx}%
`
+ });
}
else {
blocks[i] = blocks[i].replaceAll('```', '`').replaceAll('``', '`').replace(/`(.*?)`/g, function (m,m2) {return `${m2.replace(/[“”]/g, "\"")}
`;}); //remove fancy quotes too
}
}
- return blocks.join('');
+ return [blocks.join(''),codestashes];
}
function transformInputToAestheticStyle(bodyStr, isPreview) { // Trim unnecessary empty space and new lines, and append * or " to each bubble if start/end sequence ends with * or ", to preserve styling.
bodyStr = bodyStr.replaceAll(you + '\n', you).replaceAll(you + ' ', you).replaceAll(you, style('you') + `${you.endsWith('*') ? '*' : ''}` + `${you.endsWith('"') ? '"' : ''}`);
@@ -12916,10 +12963,7 @@ Current version: 112
Model Choice: