fixed bug in aesthetic ui

This commit is contained in:
Concedo 2025-01-05 18:04:02 +08:00
parent dca7ab5d9e
commit 9b32482089
2 changed files with 105 additions and 104 deletions

View file

@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
-->
<script>
const LITEVER = 200;
const LITEVER = 201;
const urlParams = new URLSearchParams(window.location.search);
var localflag = true;
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@ -3281,7 +3281,7 @@ Current version indicated by LITEVER below.
{
return !isNaN(parseFloat(n)) && isFinite(n);
}
function replace_all(str, find, replace, caseInsensitive=false) //replace all occurances in string with string
function replaceAll(str, find, replace, caseInsensitive=false) //replace all occurances in string with string
{
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
@ -3468,8 +3468,8 @@ Current version indicated by LITEVER below.
}
//inplace polyfill for replaceall
if (!String.prototype.replace_all) {
String.prototype.replace_all = function(str, newStr){
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function(str, newStr){
// If a regex pattern
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
return this.replace(str, newStr);
@ -3879,36 +3879,36 @@ initializeInstructUIFunctionality();
function get_instruct_starttag(doTrim=true)
{
if(doTrim){
return replace_all(localsettings.instruct_starttag, "\\n", "\n").trim();
return replaceAll(localsettings.instruct_starttag, "\\n", "\n").trim();
} else {
return replace_all(localsettings.instruct_starttag, "\\n", "\n");
return replaceAll(localsettings.instruct_starttag, "\\n", "\n");
}
}
function get_instruct_endtag(doTrim=true)
{
if(doTrim){
return replace_all(localsettings.instruct_endtag, "\\n", "\n").trim();
return replaceAll(localsettings.instruct_endtag, "\\n", "\n").trim();
} else {
return replace_all(localsettings.instruct_endtag, "\\n", "\n");
return replaceAll(localsettings.instruct_endtag, "\\n", "\n");
}
}
function get_instruct_systag(doTrim=true)
{
if(doTrim){
return replace_all(localsettings.instruct_systag, "\\n", "\n").trim();
return replaceAll(localsettings.instruct_systag, "\\n", "\n").trim();
} else {
return replace_all(localsettings.instruct_systag, "\\n", "\n");
return replaceAll(localsettings.instruct_systag, "\\n", "\n");
}
}
function replace_search_placeholders(text) {
// Remove any instruct tags as needed to ensure a more accurate search
text = replace_all(text, get_instruct_starttag(false), "");
text = replace_all(text, get_instruct_endtag(false), "");
text = replace_all(text, get_instruct_systag(false), "");
text = replace_all(text, get_instruct_starttag(false).trim(), "");
text = replace_all(text, get_instruct_endtag(false).trim(), "");
text = replace_all(text, get_instruct_systag(false).trim(), "");
text = replaceAll(text, get_instruct_starttag(false), "");
text = replaceAll(text, get_instruct_endtag(false), "");
text = replaceAll(text, get_instruct_systag(false), "");
text = replaceAll(text, get_instruct_starttag(false).trim(), "");
text = replaceAll(text, get_instruct_endtag(false).trim(), "");
text = replaceAll(text, get_instruct_systag(false).trim(), "");
text = text.replace(/\{\{\[INPUT\]\}\}/g, "").replace(/\{\{\[OUTPUT\]\}\}/g, "");
// Replace {{user}} and other placeholders
@ -3919,33 +3919,33 @@ initializeInstructUIFunctionality();
//we separate these 2 functions, as sometimes we only need to replace instruct
function replace_instruct_placeholders(inputtxt) //only for instruct placeholders first
{
inputtxt = replace_all(inputtxt,instructstartplaceholder,get_instruct_starttag(false));
inputtxt = replace_all(inputtxt,instructendplaceholder,get_instruct_endtag(false));
inputtxt = replace_all(inputtxt,instructsysplaceholder,get_instruct_systag(false));
inputtxt = replaceAll(inputtxt,instructstartplaceholder,get_instruct_starttag(false));
inputtxt = replaceAll(inputtxt,instructendplaceholder,get_instruct_endtag(false));
inputtxt = replaceAll(inputtxt,instructsysplaceholder,get_instruct_systag(false));
//failsafe to handle removing newline tags
inputtxt = replace_all(inputtxt,instructstartplaceholder.trim(),get_instruct_starttag(false));
inputtxt = replace_all(inputtxt,instructendplaceholder.trim(),get_instruct_endtag(false));
inputtxt = replace_all(inputtxt,instructsysplaceholder.trim(),get_instruct_systag(false));
inputtxt = replaceAll(inputtxt,instructstartplaceholder.trim(),get_instruct_starttag(false));
inputtxt = replaceAll(inputtxt,instructendplaceholder.trim(),get_instruct_endtag(false));
inputtxt = replaceAll(inputtxt,instructsysplaceholder.trim(),get_instruct_systag(false));
return inputtxt;
}
function replace_noninstruct_placeholders(inputtxt,escape=false)
{
if(escape)
{
inputtxt = replace_all(inputtxt,"{{user}}",escape_html(localsettings.chatname?localsettings.chatname:"User"),true);
inputtxt = replace_all(inputtxt,"{{char}}",escape_html(localsettings.chatopponent?localsettings.chatopponent:defaultchatopponent),true);
inputtxt = replaceAll(inputtxt,"{{user}}",escape_html(localsettings.chatname?localsettings.chatname:"User"),true);
inputtxt = replaceAll(inputtxt,"{{char}}",escape_html(localsettings.chatopponent?localsettings.chatopponent:defaultchatopponent),true);
}
else
{
inputtxt = replace_all(inputtxt,"{{user}}",(localsettings.chatname?localsettings.chatname:"User"),true);
inputtxt = replace_all(inputtxt,"{{char}}",(localsettings.chatopponent?localsettings.chatopponent:defaultchatopponent),true);
inputtxt = replaceAll(inputtxt,"{{user}}",(localsettings.chatname?localsettings.chatname:"User"),true);
inputtxt = replaceAll(inputtxt,"{{char}}",(localsettings.chatopponent?localsettings.chatopponent:defaultchatopponent),true);
}
for(let i=0;i<placeholder_tags_data.length;++i)
{
if(placeholder_tags_data[i].p && placeholder_tags_data[i].r)
{
inputtxt = replace_all(inputtxt,placeholder_tags_data[i].p,placeholder_tags_data[i].r);
inputtxt = replaceAll(inputtxt,placeholder_tags_data[i].p,placeholder_tags_data[i].r);
}
}
return inputtxt;
@ -5884,7 +5884,7 @@ initializeInstructUIFunctionality();
else
{
cstoryjson = share_plaintext();
cstoryjson = replace_all(cstoryjson,"\n","<br>",false);
cstoryjson = replaceAll(cstoryjson,"\n","<br>",false);
console.log("Export Len: " + cstoryjson.length);
document.getElementById("sharecontainertitle").innerText = "Share Story as Plaintext";
document.getElementById("sharestorytext").innerHTML = "<p>"+cstoryjson+"</p>";
@ -6999,8 +6999,8 @@ initializeInstructUIFunctionality();
}
let combinedmem = sysprompt + memory + scenario + examplemsg;
temp_scenario.title = chatopponent;
let prev2 = replace_all(obj.description,"{{char}}",chatopponent,true);
prev2 = replace_all(prev2,"{{user}}","User",true);
let prev2 = replaceAll(obj.description,"{{char}}",chatopponent,true);
prev2 = replaceAll(prev2,"{{user}}","User",true);
temp_scenario.desc = prev2;
temp_scenario.chatopponent = chatopponent;
temp_scenario.prompt = ("\n{{char}}: "+ greeting);
@ -7330,8 +7330,8 @@ initializeInstructUIFunctionality();
let cdef = data.definition?data.definition.replace("END_OF_DIALOG","").trim():"";
let cdesc = data.description?data.description:"";
let greeting = data.greeting?data.greeting:"";
let previewtxt = (data.title ? data.title + '\n\n' : '') + replace_all(cdesc,"{{char}}",botname,true);
previewtxt = replace_all(previewtxt,"{{user}}","User",true);
let previewtxt = (data.title ? data.title + '\n\n' : '') + replaceAll(cdesc,"{{char}}",botname,true);
previewtxt = replaceAll(previewtxt,"{{user}}","User",true);
temp_scenario.title = data.name?data.name:"";
temp_scenario.desc = previewtxt;
@ -8021,7 +8021,7 @@ initializeInstructUIFunctionality();
let clickinfo = "";
if(elem.info && elem.info!="")
{
clickinfo += escape_html(replace_all(elem.info,"\'","\\\'"));
clickinfo += escape_html(replaceAll(elem.info,"\'","\\\'"));
}
if(elem.threads>1)
{
@ -10146,11 +10146,11 @@ initializeInstructUIFunctionality();
document.getElementById("persist_session").checked = localsettings.persist_session;
document.getElementById("opmode").value = localsettings.opmode;
document.getElementById("chatname").value = localsettings.chatname;
document.getElementById("chatopponent").value = replace_all(localsettings.chatopponent,"||$||","\n");
document.getElementById("chatopponent").value = replaceAll(localsettings.chatopponent,"||$||","\n");
handle_bot_name_onchange();
document.getElementById("instruct_starttag").value = localsettings.instruct_starttag;
document.getElementById("instruct_systag").value = localsettings.instruct_systag;
let sp = replace_all(localsettings.instruct_sysprompt, "\n", "\\n");
let sp = replaceAll(localsettings.instruct_sysprompt, "\n", "\\n");
document.getElementById("instruct_sysprompt").value = sp;
document.getElementById("instruct_endtag").value = localsettings.instruct_endtag;
document.getElementById("min_p").value = localsettings.min_p;
@ -10480,7 +10480,7 @@ initializeInstructUIFunctionality();
if (localsettings.chatname == null || localsettings.chatname == "") {
localsettings.chatname = "User";
}
let newopps = replace_all(document.getElementById("chatopponent").value,"\n","||$||");
let newopps = replaceAll(document.getElementById("chatopponent").value,"\n","||$||");
if(localsettings.chatopponent!=newopps)
{
groupchat_removals = [];
@ -10489,7 +10489,7 @@ initializeInstructUIFunctionality();
localsettings.instruct_starttag = document.getElementById("instruct_starttag").value;
localsettings.instruct_systag = document.getElementById("instruct_systag").value;
localsettings.instruct_sysprompt = document.getElementById("instruct_sysprompt").value;
localsettings.instruct_sysprompt = replace_all(localsettings.instruct_sysprompt, "\\n", "\n");
localsettings.instruct_sysprompt = replaceAll(localsettings.instruct_sysprompt, "\\n", "\n");
if (localsettings.instruct_starttag == null || localsettings.instruct_starttag == "") {
localsettings.instruct_starttag = "\\n### Instruction:\\n";
}
@ -10758,7 +10758,7 @@ initializeInstructUIFunctionality();
function handle_bot_name_input()
{
let textarea = document.getElementById("chatopponent");
textarea.value = replace_all(textarea.value,"||$||","\n");
textarea.value = replaceAll(textarea.value,"||$||","\n");
let numberOfLineBreaks = (textarea.value.match(/\n/g) || []).length;
numberOfLineBreaks = numberOfLineBreaks>8?8:numberOfLineBreaks;
textarea.rows = numberOfLineBreaks+1;
@ -10766,7 +10766,7 @@ initializeInstructUIFunctionality();
function handle_bot_name_onchange()
{
let textarea = document.getElementById("chatopponent");
textarea.value = replace_all(textarea.value,"||$||","\n");
textarea.value = replaceAll(textarea.value,"||$||","\n");
textarea.value = textarea.value.replace(/[\r\n]+/g, '\n');
textarea.value = textarea.value.trim();
let numberOfLineBreaks = (textarea.value.match(/\n/g) || []).length;
@ -11148,7 +11148,7 @@ initializeInstructUIFunctionality();
waiting_for_autosummary = false;
gentxt = gentxt.trim();
gentxt = gentxt.split("###")[0];
gentxt = replace_all(gentxt,"\n\n","\n");
gentxt = replaceAll(gentxt,"\n\n","\n");
let gtar = gentxt.split("\n");
gentxt = gtar[0];
@ -11965,7 +11965,7 @@ initializeInstructUIFunctionality();
text = text.replace(italics_regex,"").trim();
let strippedtxt = "";
// Simply remove escaped quotes
text = replace_all(text,"\\\"","");
text = replaceAll(text,"\\\"","");
//match and extract remaining quotes
let matches = text.match(/"(.*?)"/g);
for(let m in matches)
@ -12594,7 +12594,7 @@ initializeInstructUIFunctionality();
//if we can infer the name of our chat opponent, inject it to force bot response after ours
if(co!="" && co.trim()!="")
{
co = replace_all(co,"\n","");
co = replaceAll(co,"\n","");
pending_context_preinjection = "\n"+co + ":";
if(localsettings.inject_timestamps)
{
@ -13074,7 +13074,7 @@ initializeInstructUIFunctionality();
}
}
if (extrastopseq != "") {
let rep = replace_all(extrastopseq, "\\n", "\n");
let rep = replaceAll(extrastopseq, "\\n", "\n");
let srep = rep.split("||$||");
if (srep.length > 0 && !seqs) {
seqs = [];
@ -13093,7 +13093,7 @@ initializeInstructUIFunctionality();
{
let seqs = [];
if (tokenbans != "") {
let rep = replace_all(tokenbans, "\\n", "\n");
let rep = replaceAll(tokenbans, "\\n", "\n");
let srep = rep.split("||$||");
if (srep.length > 0 && !seqs) {
seqs = [];
@ -14223,7 +14223,7 @@ initializeInstructUIFunctionality();
savedmeta.visionmode = 0;
}
let origprompt = (savedmeta.prompt?replace_all(savedmeta.prompt,"\n"," ") : "No Saved Description");
let origprompt = (savedmeta.prompt?replaceAll(savedmeta.prompt,"\n"," ") : "No Saved Description");
latest_orig_prompt = origprompt;
let hasllava = is_using_kcpp_with_llava();
let visionstatus = "";
@ -14368,7 +14368,7 @@ initializeInstructUIFunctionality();
{
if(extrastopseq!="")
{
let rep = replace_all(extrastopseq,"\\n","\n");
let rep = replaceAll(extrastopseq,"\\n","\n");
let srep = rep.split("||$||");
if (srep.length > 0) {
for (let i = 0; i < srep.length; ++i) {
@ -15803,9 +15803,9 @@ initializeInstructUIFunctionality();
let htmlstr = gametext_elem.innerHTML;
htmlstr = htmlstr.replace(/<span class="(.+?)">(.+?)<\/span>/g, "$2");
htmlstr = htmlstr.replace(/<span class="(.+?)">(.+?)<\/span>/g, "$2");
htmlstr = replace_all(htmlstr,"<div><br><br><br></div>", "<br><br><br>");
htmlstr = replace_all(htmlstr,"<div><br><br></div>", "<br><br>");
htmlstr = replace_all(htmlstr,"<div><br></div>", "<br>");
htmlstr = replaceAll(htmlstr,"<div><br><br><br></div>", "<br><br><br>");
htmlstr = replaceAll(htmlstr,"<div><br><br></div>", "<br><br>");
htmlstr = replaceAll(htmlstr,"<div><br></div>", "<br>");
gametext_elem.innerHTML = htmlstr;
//rather than dump it all into one history, let's split it into paragraphs
@ -15899,7 +15899,7 @@ initializeInstructUIFunctionality();
if(localsettings.opmode==3 && localsettings.chatname!="" && localsettings.chatopponent!="")
{
let a = escape_html(localsettings.chatname);
fulltxt = replace_all(fulltxt,a,localsettings.chatname);
fulltxt = replaceAll(fulltxt,a,localsettings.chatname);
//unescape other chat opponents too (match anything that is NOT us)
var regex = new RegExp("\n(?!" + localsettings.chatname + ").+?\: ", "gi");
@ -15911,8 +15911,8 @@ initializeInstructUIFunctionality();
{
let a = escape_html(get_instruct_starttag(false));
let b = escape_html(get_instruct_endtag(false));
fulltxt = replace_all(fulltxt,a,get_instruct_starttag(false));
fulltxt = replace_all(fulltxt,b,get_instruct_endtag(false));
fulltxt = replaceAll(fulltxt,a,get_instruct_starttag(false));
fulltxt = replaceAll(fulltxt,b,get_instruct_endtag(false));
}
}
if (stripimg)
@ -16201,14 +16201,14 @@ initializeInstructUIFunctionality();
if(localsettings.opmode==4 && !inEditMode)
{
//accept all newline formats for backwards compatibility
fulltxt = replace_all(fulltxt, "\n\n"+get_instruct_starttag(true)+"\n\n", `%SpcStg%`);
fulltxt = replace_all(fulltxt, "\n\n"+get_instruct_endtag(true)+"\n\n", `%SpcEtg%`);
fulltxt = replace_all(fulltxt, "\n"+get_instruct_starttag(true)+"\n", `%SpcStg%`);
fulltxt = replace_all(fulltxt, "\n"+get_instruct_endtag(true)+"\n", `%SpcEtg%`);
fulltxt = replace_all(fulltxt, get_instruct_starttag(false), `%SpcStg%`);
fulltxt = replace_all(fulltxt, get_instruct_endtag(false), `%SpcEtg%`);
fulltxt = replace_all(fulltxt, get_instruct_starttag(true), `%SpcStg%`);
fulltxt = replace_all(fulltxt, get_instruct_endtag(true), `%SpcEtg%`);
fulltxt = replaceAll(fulltxt, "\n\n"+get_instruct_starttag(true)+"\n\n", `%SpcStg%`);
fulltxt = replaceAll(fulltxt, "\n\n"+get_instruct_endtag(true)+"\n\n", `%SpcEtg%`);
fulltxt = replaceAll(fulltxt, "\n"+get_instruct_starttag(true)+"\n", `%SpcStg%`);
fulltxt = replaceAll(fulltxt, "\n"+get_instruct_endtag(true)+"\n", `%SpcEtg%`);
fulltxt = replaceAll(fulltxt, get_instruct_starttag(false), `%SpcStg%`);
fulltxt = replaceAll(fulltxt, get_instruct_endtag(false), `%SpcEtg%`);
fulltxt = replaceAll(fulltxt, get_instruct_starttag(true), `%SpcStg%`);
fulltxt = replaceAll(fulltxt, get_instruct_endtag(true), `%SpcEtg%`);
if(localsettings.instruct_has_markdown && synchro_pending_stream=="")
{
@ -16222,8 +16222,8 @@ initializeInstructUIFunctionality();
fulltxt = simpleMarkdown(fulltxt);
}
fulltxt = replace_all(fulltxt, `%SpcStg%`, `<hr style="margin-top: 12px; margin-bottom: 12px;"><span class="color_cyan"><img src="`+human_square+`" style="height:38px;width:auto;padding:3px 6px 3px 3px;border-radius: 8%;"/>`);
fulltxt = replace_all(fulltxt, `%SpcEtg%`, `</span><hr style="margin-top: 12px; margin-bottom: 12px;"><img src="`+niko_square+`" style="height:38px;width:auto;padding:3px 6px 3px 3px;border-radius: 8%;"/>`);
fulltxt = replaceAll(fulltxt, `%SpcStg%`, `<hr style="margin-top: 12px; margin-bottom: 12px;"><span class="color_cyan"><img src="`+human_square+`" style="height:38px;width:auto;padding:3px 6px 3px 3px;border-radius: 8%;"/>`);
fulltxt = replaceAll(fulltxt, `%SpcEtg%`, `</span><hr style="margin-top: 12px; margin-bottom: 12px;"><img src="`+niko_square+`" style="height:38px;width:auto;padding:3px 6px 3px 3px;border-radius: 8%;"/>`);
//apply stylization to time tags
if(localsettings.inject_timestamps && localsettings.instruct_has_markdown)
{
@ -16232,35 +16232,35 @@ initializeInstructUIFunctionality();
if(localsettings.inject_chatnames_instruct && localsettings.instruct_has_markdown)
{
let m_name = localsettings.chatname + ": ";
fulltxt = replace_all(fulltxt, m_name, `<b>` + escape_html(m_name) + `</b>`);
fulltxt = replaceAll(fulltxt, m_name, `<b>` + escape_html(m_name) + `</b>`);
let m_opps = localsettings.chatopponent.split("||$||");
for(let i=0;i<m_opps.length;++i)
{
if(m_opps[i] && m_opps[i].trim()!="")
{
let m_opp = m_opps[i] + ": ";
fulltxt = replace_all(fulltxt, m_opp, `<b>` + escape_html(m_opp) + `</b>`);
fulltxt = replaceAll(fulltxt, m_opp, `<b>` + escape_html(m_opp) + `</b>`);
}
}
}
}else{
fulltxt = replace_all(fulltxt, get_instruct_starttag(true), `%SclStg%`+escape_html(get_instruct_starttag(true))+`%SpnEtg%`);
fulltxt = replace_all(fulltxt, get_instruct_endtag(true), `%SclStg%`+escape_html(get_instruct_endtag(true))+`%SpnEtg%`);
fulltxt = replaceAll(fulltxt, get_instruct_starttag(true), `%SclStg%`+escape_html(get_instruct_starttag(true))+`%SpnEtg%`);
fulltxt = replaceAll(fulltxt, get_instruct_endtag(true), `%SclStg%`+escape_html(get_instruct_endtag(true))+`%SpnEtg%`);
//failsafe to handle removing newline tags
fulltxt = replace_all(fulltxt, instructstartplaceholder.trim(), `%SclStg%`+instructstartplaceholder.trim()+`%SpnEtg%`);
fulltxt = replace_all(fulltxt, instructendplaceholder.trim(), `%SclStg%`+instructendplaceholder.trim()+`%SpnEtg%`);
fulltxt = replaceAll(fulltxt, instructstartplaceholder.trim(), `%SclStg%`+instructstartplaceholder.trim()+`%SpnEtg%`);
fulltxt = replaceAll(fulltxt, instructendplaceholder.trim(), `%SclStg%`+instructendplaceholder.trim()+`%SpnEtg%`);
if(get_instruct_systag(true)!="")
{
fulltxt = replace_all(fulltxt, get_instruct_systag(true), `%SclStg%`+escape_html(get_instruct_systag(true))+`%SpnEtg%`);
fulltxt = replaceAll(fulltxt, get_instruct_systag(true), `%SclStg%`+escape_html(get_instruct_systag(true))+`%SpnEtg%`);
}
fulltxt = replace_all(fulltxt, instructsysplaceholder.trim(), `%SclStg%`+instructsysplaceholder.trim()+`%SpnEtg%`);
fulltxt = replaceAll(fulltxt, instructsysplaceholder.trim(), `%SclStg%`+instructsysplaceholder.trim()+`%SpnEtg%`);
}
//this is a hacky fix to handle instruct tags that use arrow brackets only
fulltxt = replace_all(fulltxt, `%SpnStg%`, `<span class=\"txtchunk\">`);
fulltxt = replace_all(fulltxt, `%SclStg%`,`<span class=\"color_gray\">`);
fulltxt = replace_all(fulltxt, `%SpnEtg%`, `</span>`);
fulltxt = replaceAll(fulltxt, `%SpnStg%`, `<span class=\"txtchunk\">`);
fulltxt = replaceAll(fulltxt, `%SclStg%`,`<span class=\"color_gray\">`);
fulltxt = replaceAll(fulltxt, `%SpnEtg%`, `</span>`);
if(localsettings.opmode==3)
{
@ -16285,7 +16285,7 @@ initializeInstructUIFunctionality();
}
return `<span class="`+colormap[onametrim]+`">` + oname + `</span>`;
});
fulltxt = replace_all(fulltxt,m_name, `<span class="color_blue">` + escape_html(m_name) + `</span>`);
fulltxt = replaceAll(fulltxt,m_name, `<span class="color_blue">` + escape_html(m_name) + `</span>`);
}
@ -18434,13 +18434,13 @@ initializeInstructUIFunctionality();
othernamesregex = new RegExp("(" + namePattern + "): ", "gi");
}
input = input.replace_all(mynameregex, '{{userplaceholder}}');
input = input.replace_all(mynameregex2, '{{userplaceholder}}');
input = input.replace_all(mynameregex3, '{{userplaceholder}}');
input = input.replaceAll(mynameregex, '{{userplaceholder}}');
input = input.replaceAll(mynameregex2, '{{userplaceholder}}');
input = input.replaceAll(mynameregex3, '{{userplaceholder}}');
if(as.show_chat_names)
{
input = input.replace_all("{{userplaceholder}}", `{{userplaceholder}}<p class='aui_nametag'>`+escape_html(localsettings.chatname)+`</p>`);
input = input.replace_all(othernamesregex, function(match) {
input = input.replaceAll("{{userplaceholder}}", `{{userplaceholder}}<p class='aui_nametag'>`+escape_html(localsettings.chatname)+`</p>`);
input = input.replaceAll(othernamesregex, function(match) {
//edge condition: if matched string already contains placeholders, something went wrong. return original string
if(match.includes("{{userplaceholder}}"))
{
@ -18451,7 +18451,7 @@ initializeInstructUIFunctionality();
}
else
{
input = input.replace_all(othernamesregex, function(match) {
input = input.replaceAll(othernamesregex, function(match) {
//edge condition: if matched string already contains placeholders, something went wrong. return original string
if(match.includes("{{userplaceholder}}"))
{
@ -18467,7 +18467,7 @@ initializeInstructUIFunctionality();
if(localsettings.opmode==4 && localsettings.inject_chatnames_instruct && localsettings.chatname!="" && localsettings.chatopponent!="")
{
let m_name = localsettings.chatname + ": ";
input = replace_all(input, m_name, `<p class='aui_nametag'>` + escape_html(localsettings.chatname) + `</p>`);
input = replaceAll(input, m_name, `<p class='aui_nametag'>` + escape_html(localsettings.chatname) + `</p>`);
let m_opps = localsettings.chatopponent.split("||$||");
for(let i=0;i<m_opps.length;++i)
@ -18475,7 +18475,7 @@ initializeInstructUIFunctionality();
if(m_opps[i] && m_opps[i].trim()!="")
{
let m_opp = m_opps[i] + ": ";
input = replace_all(input, m_opp, `<p class='aui_nametag'>` + escape_html(m_opps[i]) + `</p>`);
input = replaceAll(input, m_opp, `<p class='aui_nametag'>` + escape_html(m_opps[i]) + `</p>`);
}
}
}
@ -18540,7 +18540,7 @@ initializeInstructUIFunctionality();
inner = render_image_html(inner, "",false,true);
return inner;
});
return portraitsStyling + newbodystr.replace_all(/(\r\n|\r|\n)/g,'<br>'); // Finally, convert newlines to HTML format and return the stylized string.
return portraitsStyling + newbodystr.replaceAll(/(\r\n|\r|\n)/g,'<br>'); // Finally, convert newlines to HTML format and return the stylized string.
// Helper functions to allow styling the chat log properly. These affect both the background of the chat bubbles and its content.
@ -18578,14 +18578,14 @@ initializeInstructUIFunctionality();
});
}
else {
blocks[i] = blocks[i].replace_all('```', '`').replace_all('``', '`').replace(/`(.*?)`/g, function (m,m2) {return `<code style='background-color:black'>${m2.replace(/[“”]/g, "\"")}</code>`;}); //remove fancy quotes too
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(''),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.replace_all(you + '\n', you).replace_all(you + ' ', you).replace_all(you, style('you') + `${you.endsWith('*') ? '*' : ''}` + `${you.endsWith('"') ? '"' : ''}`);
bodyStr = bodyStr.replace_all(bot + '\n', bot).replace_all(bot + ' ', bot).replace_all(bot, style('AI') + `${bot.endsWith('*') ? '*' : ''}` + `${bot.endsWith('"') ? '"' : ''}`);
bodyStr = bodyStr.replaceAll(you + '\n', you).replaceAll(you + ' ', you).replaceAll(you, style('you') + `${you.endsWith('*') ? '*' : ''}` + `${you.endsWith('"') ? '"' : ''}`);
bodyStr = bodyStr.replaceAll(bot + '\n', bot).replaceAll(bot + ' ', bot).replaceAll(bot, style('AI') + `${bot.endsWith('*') ? '*' : ''}` + `${bot.endsWith('"') ? '"' : ''}`);
//for adventure mode, highlight our actions with blockquotes
if (localsettings.opmode == 2) {
@ -18601,7 +18601,7 @@ initializeInstructUIFunctionality();
}
else
{
return bodyStr.replace_all('"', '&quot;');
return bodyStr.replaceAll('"', '&quot;');
}
}
@ -18616,22 +18616,22 @@ initializeInstructUIFunctionality();
if(localsettings.opmode==3)
{
preview = replace_all(preview,'\n[USER_REPLY]\n', "{{userplaceholder}}");
preview = replaceAll(preview,'\n[USER_REPLY]\n', "{{userplaceholder}}");
if(aestheticInstructUISettings.show_chat_names){
preview = replace_all(preview,'\n[AI_REPLY]\n', "{{botplaceholder}}<p class='aui_nametag'>Bot</p>");
preview = replaceAll(preview,'\n[AI_REPLY]\n', "{{botplaceholder}}<p class='aui_nametag'>Bot</p>");
}else{
preview = replace_all(preview,'\n[AI_REPLY]\n', "{{botplaceholder}}");
preview = replaceAll(preview,'\n[AI_REPLY]\n', "{{botplaceholder}}");
}
}
else if(localsettings.opmode==4)
{
preview = replace_all(preview,'\n[USER_REPLY]\n', get_instruct_starttag());
preview = replace_all(preview,'\n[AI_REPLY]\n', get_instruct_endtag());
preview = replaceAll(preview,'\n[USER_REPLY]\n', get_instruct_starttag());
preview = replaceAll(preview,'\n[AI_REPLY]\n', get_instruct_endtag());
}
else
{
preview = replace_all(preview,'\n[USER_REPLY]\n', "");
preview = replace_all(preview,'\n[AI_REPLY]\n', "");
preview = replaceAll(preview,'\n[USER_REPLY]\n', "");
preview = replaceAll(preview,'\n[AI_REPLY]\n', "");
}
document.getElementById('aesthetic_text_preview').innerHTML = render_aesthetic_ui(preview,true);
}
@ -18788,7 +18788,7 @@ initializeInstructUIFunctionality();
//step 1: chunk the dbtext into paragraph chunks
let paragraphs = [];
let allText = cleanupSpecialTags(dbText);
allText = replace_all(allText,recentTextStr,"");
allText = replaceAll(allText,recentTextStr,"");
// Ensure placeholders are replaced to allow searching for user / character
allText = replace_search_placeholders(allText)

View file

@ -58,7 +58,7 @@ maxhordelen = 400
modelbusy = threading.Lock()
requestsinqueue = 0
defaultport = 5001
KcppVersion = "1.81"
KcppVersion = "1.81.1"
showdebug = True
guimode = False
showsamplerwarning = True
@ -1281,6 +1281,7 @@ def detokenize_ids(tokids):
def websearch(query):
global websearch_lastquery
global websearch_lastresponse
global nocertify
# sanitize query
query = re.sub(r'[+\-\"\\/*^|<>~`]', '', query) # Remove blacklisted characters
query = re.sub(r'\s+', ' ', query).strip() # Replace multiple spaces with a single space
@ -1312,6 +1313,9 @@ def websearch(query):
if args.debugmode:
utfprint(f"WebSearch URL: {url}")
try:
ssl_cert_dir = os.environ.get('SSL_CERT_DIR')
if not ssl_cert_dir and not nocertify and os.name != 'nt':
os.environ['SSL_CERT_DIR'] = '/etc/ssl/certs'
req = urllib.request.Request(url, headers={'User-Agent': uagent})
with urllib.request.urlopen(req, timeout=15) as response:
html_content = response.read().decode('utf-8', errors='ignore')
@ -4042,17 +4046,12 @@ def print_with_time(txt):
def make_url_request(url, data, method='POST', headers={}):
import urllib.request
import ssl
global nocertify
try:
request = None
ssl_cert_dir = os.environ.get('SSL_CERT_DIR')
if not ssl_cert_dir and not nocertify and os.name != 'nt':
os.environ['SSL_CERT_DIR'] = '/etc/ssl/certs'
ssl_context = ssl.create_default_context()
if nocertify:
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
if method=='POST':
json_payload = json.dumps(data).encode('utf-8')
request = urllib.request.Request(url, data=json_payload, headers=headers, method=method)
@ -4060,7 +4059,7 @@ def make_url_request(url, data, method='POST', headers={}):
else:
request = urllib.request.Request(url, headers=headers, method=method)
response_data = ""
with urllib.request.urlopen(request,context=ssl_context,timeout=300) as response:
with urllib.request.urlopen(request,timeout=300) as response:
response_data = response.read().decode('utf-8',"ignore")
json_response = json.loads(response_data)
return json_response
@ -4741,8 +4740,10 @@ def main(launch_args,start_server=True):
maxctx = args.contextsize
if args.nocertify:
import ssl
global nocertify
nocertify = True
ssl._create_default_https_context = ssl._create_unverified_context
if args.gpulayers:
shouldavoidgpu = False