@@ -3532,6 +3532,7 @@ Current version: 99
3532
3532
}
3533
3533
3534
3534
console.log("Init started");
3535
+ let loadok = false;
3535
3536
try {
3536
3537
let loadedsettingsjson = localStorage.getItem(STORAGE_PREFIX + "settings");
3537
3538
let loadedstorycompressed = localStorage.getItem(STORAGE_PREFIX + "story");
@@ -3558,12 +3559,41 @@ Current version: 99
3558
3559
//toggle persistence off to prevent it from turning on again
3559
3560
localsettings.persist_session = false;
3560
3561
}
3562
+ loadok = true;
3561
3563
} else {
3562
3564
console.log("Skipped missing local save");
3565
+ loadok = false;
3563
3566
}
3564
3567
3565
3568
} catch (e) {
3566
3569
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
+ });
3567
3597
}
3568
3598
3569
3599
const tokenstreaming = urlParams.get('streaming');
@@ -3636,6 +3666,17 @@ Current version: 99
3636
3666
window.clipboardData
3637
3667
? window.clipboardData.getData('Text')
3638
3668
: '';
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
+
3639
3680
text = escapeHtml(text);
3640
3681
text = text.replace(/\r?\n/g, '<br>');
3641
3682
document.execCommand("insertHTML", false, text);
@@ -4816,7 +4857,7 @@ Current version: 99
4816
4857
function load_agnai_wi(obj,chatopponent,myname)
4817
4858
{
4818
4859
console.log("Append Agnai WI");
4819
- current_wi = [];
4860
+ let loadedwi = [];
4820
4861
for (let key in obj.entries) {
4821
4862
var itm = obj.entries[key];
4822
4863
var karr = itm.keywords;
@@ -4829,13 +4870,14 @@ Current version: 99
4829
4870
"selective": false,
4830
4871
"constant": false
4831
4872
};
4832
- current_wi .push(nwi);
4873
+ loadedwi .push(nwi);
4833
4874
}
4875
+ return loadedwi;
4834
4876
}
4835
4877
function load_tavern_wi(obj,chatopponent,myname)
4836
4878
{
4837
4879
console.log("Append Tavern WI");
4838
- current_wi = [];
4880
+ let loadedwi = [];
4839
4881
for (let key in obj.entries) {
4840
4882
var itm = obj.entries[key];
4841
4883
var karr = itm.key;
@@ -4857,8 +4899,9 @@ Current version: 99
4857
4899
"selective": itm.selective,
4858
4900
"constant": itm.constant
4859
4901
};
4860
- current_wi .push(nwi);
4902
+ loadedwi .push(nwi);
4861
4903
}
4904
+ return loadedwi;
4862
4905
}
4863
4906
function load_tavern_obj(obj)
4864
4907
{
@@ -4894,11 +4937,11 @@ Current version: 99
4894
4937
//check if it's a world info only card, if so, do not restart game
4895
4938
if(combinedmem.trim()=="" && greeting=="" && obj.entries)
4896
4939
{
4897
- load_tavern_wi(obj,chatopponent,myname);
4940
+ current_wi = load_tavern_wi(obj,chatopponent,myname);
4898
4941
}
4899
4942
else if(agnaidatafieldsempty.trim()=="" && obj.entries && obj.kind=="memory")
4900
4943
{
4901
- load_agnai_wi(obj,chatopponent,myname);
4944
+ current_wi = load_agnai_wi(obj,chatopponent,myname);
4902
4945
}
4903
4946
else
4904
4947
{
@@ -4913,11 +4956,11 @@ Current version: 99
4913
4956
//handle character book
4914
4957
if(obj.character_book && obj.character_book.entries && obj.character_book.entries.length>0)
4915
4958
{
4916
- load_tavern_wi(obj.character_book,chatopponent,myname);
4959
+ current_wi = load_tavern_wi(obj.character_book,chatopponent,myname);
4917
4960
}
4918
4961
else if(obj.entries && obj.entries.length>0)
4919
4962
{
4920
- load_agnai_wi(obj,chatopponent,myname);
4963
+ current_wi = load_agnai_wi(obj,chatopponent,myname);
4921
4964
}
4922
4965
}
4923
4966
render_gametext();
@@ -4993,7 +5036,16 @@ Current version: 99
4993
5036
let keys = data.worldInfos[w].keys;
4994
5037
let entry = data.worldInfos[w].entry;
4995
5038
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);
4997
5049
}
4998
5050
}
4999
5051
preview_temp_scenario();
@@ -5098,16 +5150,17 @@ Current version: 99
5098
5150
.then(blob => {
5099
5151
preview_temp_scenario();
5100
5152
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)
5105
5163
{
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
- }
5111
5164
let chatopponent = obj.name?obj.name:"Bot";
5112
5165
let memory = obj.description?("Persona: "+obj.description):"";
5113
5166
memory += obj.personality?("\nPersonality: "+obj.personality):"";
@@ -5136,11 +5189,19 @@ Current version: 99
5136
5189
temp_scenario.chatopponent = chatopponent;
5137
5190
temp_scenario.prompt = ("\n{{char}}: "+ greeting);
5138
5191
temp_scenario.memory = combinedmem;
5139
- preview_temp_scenario();
5140
5192
}
5141
5193
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
+
5144
5205
const objectURL = URL.createObjectURL(blob);
5145
5206
const compressedImg = compressImage(objectURL, (compressedImageURI, aspectratio)=>{
5146
5207
temp_scenario.image = compressedImageURI;
@@ -5233,21 +5294,7 @@ Current version: 99
5233
5294
refreshPreview(true);
5234
5295
}
5235
5296
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;
5251
5298
}
5252
5299
5253
5300
localsettings.opmode = temp_scenario.opmode;
@@ -8925,6 +8972,9 @@ Current version: 99
8925
8972
8926
8973
//horde now supports stopping sequences
8927
8974
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;
8928
8978
}
8929
8979
8930
8980
last_request_str = JSON.stringify(submit_payload);
@@ -10220,7 +10270,7 @@ Current version: 99
10220
10270
document.getElementById("topbtn_ai").classList.add("hidden");
10221
10271
document.getElementById("topbtn_newgame").classList.remove("hidden");
10222
10272
document.getElementById("topbtn_save_load").classList.remove("hidden");
10223
- document.getElementById("topbtn_settings").classList.add ("hidden");
10273
+ document.getElementById("topbtn_settings").classList.remove ("hidden");
10224
10274
document.getElementById("topbtn_scenarios").classList.add("hidden");
10225
10275
document.getElementById("topbtn_quickplay").classList.add("hidden");
10226
10276
} else {
@@ -10500,9 +10550,24 @@ Current version: 99
10500
10550
{
10501
10551
//resize chat inp
10502
10552
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";
10506
10571
}
10507
10572
function chat_submit_generation()
10508
10573
{
@@ -11524,7 +11589,8 @@ Current version: 99
11524
11589
<div class="cht_inp_hold">
11525
11590
<button onclick="show_groupchat_select()" id="chat_btnmode_chat" class="chat_btnmode_chat hidden" type="button"></button>
11526
11591
<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>
11528
11594
</div>
11529
11595
<button onclick="chat_submit_generation()" id="chat_msg_send_btn" class="chat_msg_send_btn" type="button"></button>
11530
11596
<button onclick="abort_generation()" id="chat_msg_send_btn_abort" class="hidden chat_msg_send_btn_abort" type="button"></button>
0 commit comments