Skip to content

Commit 930cdfb

Browse files
committed
updated lite, added patch that links to noscript mode
1 parent c751152 commit 930cdfb

File tree

2 files changed

+115
-43
lines changed

2 files changed

+115
-43
lines changed

Diff for: klite.embd

+107-41
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,7 @@ Current version: 99
35323532
}
35333533

35343534
console.log("Init started");
3535+
let loadok = false;
35353536
try {
35363537
let loadedsettingsjson = localStorage.getItem(STORAGE_PREFIX + "settings");
35373538
let loadedstorycompressed = localStorage.getItem(STORAGE_PREFIX + "story");
@@ -3558,12 +3559,41 @@ Current version: 99
35583559
//toggle persistence off to prevent it from turning on again
35593560
localsettings.persist_session = false;
35603561
}
3562+
loadok = true;
35613563
} else {
35623564
console.log("Skipped missing local save");
3565+
loadok = false;
35633566
}
35643567

35653568
} catch (e) {
35663569
console.log("Discarded invalid local save: " + e);
3570+
loadok = false;
3571+
}
3572+
3573+
3574+
if(!loadok && !localflag && selected_models.length==0 && !is_using_custom_ep()) //nothing was loaded. this is a brand new state, in web lite
3575+
{
3576+
console.log("Autopick some good default models...");
3577+
//attempt to autopick some good default models
3578+
fetch_models((mdls) => {
3579+
//can we find the model that's used? if yes load it, otherwise load the first one
3580+
if (mdls.length > 0)
3581+
{
3582+
for (var i = 0; i < mdls.length; ++i) {
3583+
for (var j = 0; j < defaultmodels.length; ++j) {
3584+
if (mdls[i].name.trim().toLowerCase().includes(defaultmodels[j].trim().toLowerCase()) ||
3585+
defaultmodels[j].trim().toLowerCase().includes(mdls[i].name.trim().toLowerCase())) {
3586+
selected_models.push(mdls[i]);
3587+
}
3588+
}
3589+
}
3590+
if (selected_models.length == 0) //no matching models, just assign one
3591+
{
3592+
selected_models.push(mdls[0]);
3593+
}
3594+
render_gametext();
3595+
}
3596+
});
35673597
}
35683598

35693599
const tokenstreaming = urlParams.get('streaming');
@@ -3636,6 +3666,17 @@ Current version: 99
36363666
window.clipboardData
36373667
? window.clipboardData.getData('Text')
36383668
: '';
3669+
3670+
let elem = document.getElementById("gametext")
3671+
let selection = window.getSelection();
3672+
let fullySelected = (elem.innerText!="" && selection.toString() === elem.innerText);
3673+
if(fullySelected || elem.innerText.trim()=="")
3674+
{
3675+
document.execCommand('selectAll', false, null);
3676+
document.execCommand('insertText', false, "");
3677+
elem.innerHTML = "";
3678+
}
3679+
36393680
text = escapeHtml(text);
36403681
text = text.replace(/\r?\n/g, '<br>');
36413682
document.execCommand("insertHTML", false, text);
@@ -4816,7 +4857,7 @@ Current version: 99
48164857
function load_agnai_wi(obj,chatopponent,myname)
48174858
{
48184859
console.log("Append Agnai WI");
4819-
current_wi = [];
4860+
let loadedwi = [];
48204861
for (let key in obj.entries) {
48214862
var itm = obj.entries[key];
48224863
var karr = itm.keywords;
@@ -4829,13 +4870,14 @@ Current version: 99
48294870
"selective": false,
48304871
"constant": false
48314872
};
4832-
current_wi.push(nwi);
4873+
loadedwi.push(nwi);
48334874
}
4875+
return loadedwi;
48344876
}
48354877
function load_tavern_wi(obj,chatopponent,myname)
48364878
{
48374879
console.log("Append Tavern WI");
4838-
current_wi = [];
4880+
let loadedwi = [];
48394881
for (let key in obj.entries) {
48404882
var itm = obj.entries[key];
48414883
var karr = itm.key;
@@ -4857,8 +4899,9 @@ Current version: 99
48574899
"selective": itm.selective,
48584900
"constant": itm.constant
48594901
};
4860-
current_wi.push(nwi);
4902+
loadedwi.push(nwi);
48614903
}
4904+
return loadedwi;
48624905
}
48634906
function load_tavern_obj(obj)
48644907
{
@@ -4894,11 +4937,11 @@ Current version: 99
48944937
//check if it's a world info only card, if so, do not restart game
48954938
if(combinedmem.trim()=="" && greeting=="" && obj.entries)
48964939
{
4897-
load_tavern_wi(obj,chatopponent,myname);
4940+
current_wi = load_tavern_wi(obj,chatopponent,myname);
48984941
}
48994942
else if(agnaidatafieldsempty.trim()=="" && obj.entries && obj.kind=="memory")
49004943
{
4901-
load_agnai_wi(obj,chatopponent,myname);
4944+
current_wi = load_agnai_wi(obj,chatopponent,myname);
49024945
}
49034946
else
49044947
{
@@ -4913,11 +4956,11 @@ Current version: 99
49134956
//handle character book
49144957
if(obj.character_book && obj.character_book.entries && obj.character_book.entries.length>0)
49154958
{
4916-
load_tavern_wi(obj.character_book,chatopponent,myname);
4959+
current_wi = load_tavern_wi(obj.character_book,chatopponent,myname);
49174960
}
49184961
else if(obj.entries && obj.entries.length>0)
49194962
{
4920-
load_agnai_wi(obj,chatopponent,myname);
4963+
current_wi = load_agnai_wi(obj,chatopponent,myname);
49214964
}
49224965
}
49234966
render_gametext();
@@ -4993,7 +5036,16 @@ Current version: 99
49935036
let keys = data.worldInfos[w].keys;
49945037
let entry = data.worldInfos[w].entry;
49955038

4996-
temp_scenario.worldinfo.push({"key":(keys?keys:""),"content":(entry?entry:"")})
5039+
let nwi = {
5040+
"key": (keys ? keys : ""),
5041+
"keysecondary": "",
5042+
"content": (entry ? entry : ""),
5043+
"comment": "",
5044+
"folder": null,
5045+
"selective": false,
5046+
"constant": false
5047+
};
5048+
temp_scenario.worldinfo.push(nwi);
49975049
}
49985050
}
49995051
preview_temp_scenario();
@@ -5098,16 +5150,17 @@ Current version: 99
50985150
.then(blob => {
50995151
preview_temp_scenario();
51005152

5101-
if(card_is_defective)
5102-
{
5103-
readTavernPngFromBlob(blob,(obj)=>{
5104-
if(obj!=null)
5153+
readTavernPngFromBlob(blob,(obj)=>{
5154+
if(obj!=null)
5155+
{
5156+
//a lightweight tavern card loader, not fully compliant
5157+
if(obj.spec=="chara_card_v2" && obj.data!=null)
5158+
{
5159+
obj = obj.data;
5160+
}
5161+
5162+
if(card_is_defective)
51055163
{
5106-
//a lightweight tavern card loader, not fully compliant
5107-
if(obj.spec=="chara_card_v2" && obj.data!=null)
5108-
{
5109-
obj = obj.data;
5110-
}
51115164
let chatopponent = obj.name?obj.name:"Bot";
51125165
let memory = obj.description?("Persona: "+obj.description):"";
51135166
memory += obj.personality?("\nPersonality: "+obj.personality):"";
@@ -5136,11 +5189,19 @@ Current version: 99
51365189
temp_scenario.chatopponent = chatopponent;
51375190
temp_scenario.prompt = ("\n{{char}}: "+ greeting);
51385191
temp_scenario.memory = combinedmem;
5139-
preview_temp_scenario();
51405192
}
51415193

5142-
});
5143-
}
5194+
//since cai format has no wi, try to grab it from tavern format
5195+
if(obj.character_book && obj.character_book.entries && obj.character_book.entries.length>0)
5196+
{
5197+
let myname = ((localsettings.chatname && localsettings.chatname!="")?localsettings.chatname:"You");
5198+
temp_scenario.worldinfo = load_tavern_wi(obj.character_book,chatopponent,myname);
5199+
}
5200+
preview_temp_scenario();
5201+
}
5202+
5203+
});
5204+
51445205
const objectURL = URL.createObjectURL(blob);
51455206
const compressedImg = compressImage(objectURL, (compressedImageURI, aspectratio)=>{
51465207
temp_scenario.image = compressedImageURI;
@@ -5233,21 +5294,7 @@ Current version: 99
52335294
refreshPreview(true);
52345295
}
52355296
if (temp_scenario.worldinfo && temp_scenario.worldinfo.length > 0) {
5236-
current_wi = [];
5237-
for (let x = 0; x < temp_scenario.worldinfo.length; ++x) {
5238-
let key = temp_scenario.worldinfo[x].key;
5239-
let content = temp_scenario.worldinfo[x].content;
5240-
let nwi = {
5241-
"key": (key ? key : ""),
5242-
"keysecondary": "",
5243-
"content": (content ? content : ""),
5244-
"comment": "",
5245-
"folder": null,
5246-
"selective": false,
5247-
"constant": false
5248-
};
5249-
current_wi.push(nwi);
5250-
}
5297+
current_wi = temp_scenario.worldinfo;
52515298
}
52525299

52535300
localsettings.opmode = temp_scenario.opmode;
@@ -8925,6 +8972,9 @@ Current version: 99
89258972

89268973
//horde now supports stopping sequences
89278974
submit_payload.params.stop_sequence = get_stop_sequences();
8975+
8976+
//horde should support min_p in future too
8977+
submit_payload.params.min_p = localsettings.min_p;
89288978
}
89298979

89308980
last_request_str = JSON.stringify(submit_payload);
@@ -10220,7 +10270,7 @@ Current version: 99
1022010270
document.getElementById("topbtn_ai").classList.add("hidden");
1022110271
document.getElementById("topbtn_newgame").classList.remove("hidden");
1022210272
document.getElementById("topbtn_save_load").classList.remove("hidden");
10223-
document.getElementById("topbtn_settings").classList.add("hidden");
10273+
document.getElementById("topbtn_settings").classList.remove("hidden");
1022410274
document.getElementById("topbtn_scenarios").classList.add("hidden");
1022510275
document.getElementById("topbtn_quickplay").classList.add("hidden");
1022610276
} else {
@@ -10500,9 +10550,24 @@ Current version: 99
1050010550
{
1050110551
//resize chat inp
1050210552
let textarea = document.getElementById("cht_inp");
10503-
let numberOfLineBreaks = (textarea.value.match(/\n/g) || []).length;
10504-
numberOfLineBreaks = numberOfLineBreaks>4?4:numberOfLineBreaks;
10505-
textarea.rows = numberOfLineBreaks+1;
10553+
10554+
let textlines = textarea.value.split("\n");
10555+
let numberOfLineBreaks = textlines.length;
10556+
let lengthtester = document.getElementById("cht_inp_lengthtester");
10557+
for(let l=0;l<textlines.length;++l)
10558+
{
10559+
lengthtester.innerText = textlines[l];
10560+
if(textarea.offsetWidth>0)
10561+
{
10562+
numberOfLineBreaks += Math.floor(lengthtester.offsetWidth / textarea.offsetWidth );
10563+
}
10564+
}
10565+
lengthtester.innerText = "";
10566+
numberOfLineBreaks = numberOfLineBreaks>5?5:numberOfLineBreaks;
10567+
textarea.rows = numberOfLineBreaks;
10568+
10569+
// textarea.style.height = "auto";
10570+
// textarea.style.height = textarea.scrollHeight + 3 + "px";
1050610571
}
1050710572
function chat_submit_generation()
1050810573
{
@@ -11524,7 +11589,8 @@ Current version: 99
1152411589
<div class="cht_inp_hold">
1152511590
<button onclick="show_groupchat_select()" id="chat_btnmode_chat" class="chat_btnmode_chat hidden" type="button"></button>
1152611591
<div id="cht_inp_bg" class="cht_inp_bg">
11527-
<textarea class="cht_inp_bg_inner" id="cht_inp" type="text" name="chtchtinp" role="presentation" autocomplete="noppynop" spellcheck="true" rows="1" wrap="off" placeholder="Type a message" value="" oninput="update_submit_button();chat_resize_input();" onkeypress="return chat_handle_typing(event)"/></textarea>
11592+
<div class="cht_inp_bg_inner" id="cht_inp_lengthtester" style="white-space: nowrap; visibility: hidden; height: 0px; position:absolute; width: auto;"></div>
11593+
<textarea class="cht_inp_bg_inner" id="cht_inp" type="text" name="chtchtinp" role="presentation" autocomplete="noppynop" spellcheck="true" rows="1" wrap="on" placeholder="Type a message" value="" oninput="update_submit_button();chat_resize_input();" onkeypress="return chat_handle_typing(event)"/></textarea>
1152811594
</div>
1152911595
<button onclick="chat_submit_generation()" id="chat_msg_send_btn" class="chat_msg_send_btn" type="button"></button>
1153011596
<button onclick="abort_generation()" id="chat_msg_send_btn_abort" class="hidden chat_msg_send_btn_abort" type="button"></button>

Diff for: koboldcpp.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -2274,15 +2274,21 @@ def main(launch_args,start_server=True):
22742274
basepath = os.path.abspath(os.path.dirname(__file__))
22752275
with open(os.path.join(basepath, "klite.embd"), mode='rb') as f:
22762276
embedded_kailite = f.read()
2277+
# patch it with extra stuff
2278+
origStr = "Sorry, Kobold Lite requires Javascript to function."
2279+
patchedStr = "Sorry, Kobold Lite requires Javascript to function.<br>You can use <a class=\"color_blueurl\" href=\"/noscript\">KoboldCpp NoScript mode</a> instead."
2280+
embedded_kailite = embedded_kailite.decode("UTF-8","ignore")
2281+
embedded_kailite = embedded_kailite.replace(origStr, patchedStr)
2282+
embedded_kailite = embedded_kailite.encode()
22772283
print("Embedded Kobold Lite loaded.")
2278-
except:
2284+
except Exception as e:
22792285
print("Could not find Kobold Lite. Embedded Kobold Lite will not be available.")
22802286

22812287
try:
22822288
basepath = os.path.abspath(os.path.dirname(__file__))
22832289
with open(os.path.join(basepath, "kcpp_docs.embd"), mode='rb') as f:
22842290
embedded_kcpp_docs = f.read()
2285-
except:
2291+
except Exception as e:
22862292
print("Could not find Embedded KoboldCpp API docs.")
22872293

22882294
if args.port_param!=defaultport:

0 commit comments

Comments
 (0)