Skip to content

Commit

Permalink
updated lite
Browse files Browse the repository at this point in the history
  • Loading branch information
LostRuins committed Feb 16, 2024
1 parent 01b7daf commit 2338e95
Showing 1 changed file with 75 additions and 26 deletions.
101 changes: 75 additions & 26 deletions klite.embd
Original file line number Diff line number Diff line change
Expand Up @@ -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
-->

Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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 + '</p></div></div>'; // 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.
Expand All @@ -12482,7 +12521,10 @@ Current version: 112
});
}
internalHTMLparts.forEach((part, index) => { newbodystr = newbodystr.replace(`<internal_html_${index}>`, part); }); // Bring back the embedded HTML parts.
newbodystr = applyStylizedCodeBlocks(); // Then, apply the code-block styling, if markdown is used.
for(let i=0;i<codestashes.length;++i)
{
newbodystr = newbodystr.replace(`%CodeStash${i}%`,codestashes[i]);
}
}
newbodystr = newbodystr.replace(/\[<\|p\|.+?\|p\|>\]/g, function (m) {
// m here means the whole matched string
Expand Down Expand Up @@ -12523,16 +12565,21 @@ Current version: 112
}
function applyStylizedCodeBlocks() {
let blocks = newbodystr.split(/(```[\s\S]*?\n[\s\S]*?```)/g);
let codestashes = [];
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].startsWith('```')) {
blocks[i] = blocks[i].replace(/```[\s\S]*?\n([\s\S]*?)```/g,
function (m,m2) {return `</p><pre style='min-width:80%;white-space:pre-wrap;margin:0px 30px 0px 20px;background-color:${as.code_block_background};color:${as.code_block_foreground}'>${m2.replace(/[“”]/g, "\"")}</pre><p>`});
function (m,m2) {
let idx = codestashes.length;
codestashes.push(`<pre style='min-width:80%;white-space:pre-wrap;margin:0px 30px 0px 20px;background-color:${as.code_block_background};color:${as.code_block_foreground}'>${m2.replace(/[“”]/g, "\"")}</pre>`);
return `</p>%CodeStash${idx}%<p>`
});
}
else {
blocks[i] = blocks[i].replaceAll('```', '`').replaceAll('``', '`').replace(/`(.*?)`/g, function (m,m2) {return `<code style='background-color:black'>${m2.replace(/[“”]/g, "\"")}</code>`;}); //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('"') ? '"' : ''}`);
Expand Down Expand Up @@ -12916,10 +12963,7 @@ Current version: 112
Model Choice:<br>
<select style="padding:4px;display:inline;width:calc(100% - 220px)" class="form-control" id="custom_oai_model" onchange="oai_model_change()">
<option value="gpt-3.5-turbo-instruct" selected="selected">gpt-3.5-turbo-instruct</option>
<option value="text-davinci-003">text-davinci-003</option>
<option value="text-davinci-002">text-davinci-002</option>
<option value="text-davinci-001">text-davinci-001</option>
<option value="davinci">davinci</option>
<option value="davinci-002">davinci-002</option>
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>
<option value="gpt-3.5-turbo-16k">gpt-3.5-turbo-16k</option>
<option value="gpt-4">gpt-4</option>
Expand Down Expand Up @@ -13583,6 +13627,11 @@ Current version: 112
class="helptext">If enabled, uses universal {{user}} and {{[INPUT]}} placeholders that get swapped on submit. If disabled, uses plaintext chat or instruct tags verbatim.</span></span></div>
<input type="checkbox" id="placeholder_tags" style="margin:0px 0px 0px auto;">
</div>
<div class="settinglabel">
<div class="justifyleft settingsmall">Run In Background <span class="helpicon">?<span
class="helptext">Prevents the browser from suspending Kobold Lite by playing a silent audio track. This setting cannot be saved.</span></span></div>
<input type="checkbox" id="run_in_background" style="margin:0px 0px 0px auto;">
</div>
</div>


Expand Down

0 comments on commit 2338e95

Please sign in to comment.