Skip to content

Commit a0440fd

Browse files
committed
updated lite
1 parent 2338e95 commit a0440fd

File tree

1 file changed

+170
-52
lines changed

1 file changed

+170
-52
lines changed

klite.embd

+170-52
Original file line numberDiff line numberDiff line change
@@ -4030,6 +4030,7 @@ Current version: 113
40304030
const foundStory = urlParams.get('s');
40314031
const foundScenario = urlParams.get('scenario');
40324032
const foundChub = urlParams.get('chub');
4033+
const foundPyg = urlParams.get('pyg');
40334034

40344035
if (foundStory && foundStory != "") {
40354036
let safe_to_overwrite = (gametext_arr.length == 0 && current_memory == "" && current_anote == "" && current_wi.length == 0 && redo_arr.length == 0);
@@ -4056,6 +4057,11 @@ Current version: 113
40564057
get_chubai_scenario(foundChub);
40574058
//purge url params
40584059
window.history.replaceState(null, null, window.location.pathname);
4060+
} else if (foundPyg && foundPyg != "") {
4061+
display_scenarios();
4062+
get_pygchat_scenario(foundPyg);
4063+
//purge url params
4064+
window.history.replaceState(null, null, window.location.pathname);
40594065
}
40604066
}
40614067

@@ -5360,6 +5366,68 @@ Current version: 113
53605366
},false);
53615367
}
53625368

5369+
function load_temp_scenario_from_tavernobj(obj,loadall)
5370+
{
5371+
if(obj!=null)
5372+
{
5373+
//a lightweight tavern card loader, not fully compliant
5374+
if(obj.spec=="chara_card_v2" && obj.data!=null)
5375+
{
5376+
obj = obj.data;
5377+
}
5378+
5379+
if(loadall)
5380+
{
5381+
let chatopponent = obj.name?obj.name:"Bot";
5382+
let memory = obj.description?("Persona: "+obj.description):"";
5383+
memory += obj.personality?("\nPersonality: "+obj.personality):"";
5384+
let scenario = obj.scenario?obj.scenario:"";
5385+
let examplemsg = obj.mes_example?obj.mes_example:"";
5386+
let greeting = obj.first_mes?obj.first_mes:"";
5387+
let sysprompt = obj.system_prompt?obj.system_prompt:"";
5388+
5389+
//aliases
5390+
if(examplemsg=="" && obj.mesExample!="")
5391+
{
5392+
examplemsg = obj.mesExample;
5393+
}
5394+
if(greeting=="" && obj.firstMes!="")
5395+
{
5396+
greeting = obj.firstMes;
5397+
}
5398+
5399+
if(scenario!="")
5400+
{
5401+
scenario = "\n[Scenario: "+scenario+"]";
5402+
}
5403+
if(examplemsg!="")
5404+
{
5405+
examplemsg = "\n"+examplemsg;
5406+
}
5407+
if(sysprompt!="")
5408+
{
5409+
sysprompt = sysprompt+"\n";
5410+
}
5411+
let combinedmem = sysprompt + memory + scenario + examplemsg;
5412+
temp_scenario.title = chatopponent;
5413+
let prev2 = replaceAll(obj.description,"{{char}}",chatopponent,true);
5414+
prev2 = replaceAll(prev2,"{{user}}","You",true);
5415+
temp_scenario.desc = prev2;
5416+
temp_scenario.chatopponent = chatopponent;
5417+
temp_scenario.prompt = ("\n{{char}}: "+ greeting);
5418+
temp_scenario.memory = combinedmem;
5419+
}
5420+
5421+
//since cai format has no wi, try to grab it from tavern format
5422+
if(obj.character_book && obj.character_book.entries && obj.character_book.entries.length>0)
5423+
{
5424+
let myname = ((localsettings.chatname && localsettings.chatname!="")?localsettings.chatname:"You");
5425+
temp_scenario.worldinfo = load_tavern_wi(obj.character_book,chatopponent,myname);
5426+
}
5427+
preview_temp_scenario();
5428+
}
5429+
}
5430+
53635431
function get_chubai_portrait(userinput, card_is_defective, original_no_exist)
53645432
{
53655433
//try to obtain the full portrait image
@@ -5387,55 +5455,7 @@ Current version: 113
53875455
preview_temp_scenario();
53885456

53895457
readTavernPngFromBlob(blob,(obj)=>{
5390-
if(obj!=null)
5391-
{
5392-
//a lightweight tavern card loader, not fully compliant
5393-
if(obj.spec=="chara_card_v2" && obj.data!=null)
5394-
{
5395-
obj = obj.data;
5396-
}
5397-
5398-
if(card_is_defective)
5399-
{
5400-
let chatopponent = obj.name?obj.name:"Bot";
5401-
let memory = obj.description?("Persona: "+obj.description):"";
5402-
memory += obj.personality?("\nPersonality: "+obj.personality):"";
5403-
let scenario = obj.scenario?obj.scenario:"";
5404-
let examplemsg = obj.mes_example?obj.mes_example:"";
5405-
let greeting = obj.first_mes?obj.first_mes:"";
5406-
let sysprompt = obj.system_prompt?obj.system_prompt:"";
5407-
5408-
if(scenario!="")
5409-
{
5410-
scenario = "\n[Scenario: "+scenario+"]";
5411-
}
5412-
if(examplemsg!="")
5413-
{
5414-
examplemsg = "\n"+examplemsg;
5415-
}
5416-
if(sysprompt!="")
5417-
{
5418-
sysprompt = sysprompt+"\n";
5419-
}
5420-
let combinedmem = sysprompt + memory + scenario + examplemsg;
5421-
temp_scenario.title = chatopponent;
5422-
let prev2 = replaceAll(obj.description,"{{char}}",chatopponent,true);
5423-
prev2 = replaceAll(prev2,"{{user}}","You",true);
5424-
temp_scenario.desc = prev2;
5425-
temp_scenario.chatopponent = chatopponent;
5426-
temp_scenario.prompt = ("\n{{char}}: "+ greeting);
5427-
temp_scenario.memory = combinedmem;
5428-
}
5429-
5430-
//since cai format has no wi, try to grab it from tavern format
5431-
if(obj.character_book && obj.character_book.entries && obj.character_book.entries.length>0)
5432-
{
5433-
let myname = ((localsettings.chatname && localsettings.chatname!="")?localsettings.chatname:"You");
5434-
temp_scenario.worldinfo = load_tavern_wi(obj.character_book,chatopponent,myname);
5435-
}
5436-
preview_temp_scenario();
5437-
}
5438-
5458+
load_temp_scenario_from_tavernobj(obj,card_is_defective);
54395459
});
54405460

54415461
const objectURL = URL.createObjectURL(blob);
@@ -5461,6 +5481,102 @@ Current version: 113
54615481
});
54625482
}
54635483

5484+
function get_pygchat_scenario(charstr="")
5485+
{
5486+
const loadpyg = function(userinput)
5487+
{
5488+
if(userinput=="")
5489+
{
5490+
//pass
5491+
}
5492+
else
5493+
{
5494+
if (userinput.match(/pygmalion\.chat\//i)) {
5495+
const urlParams = new URLSearchParams(userinput);
5496+
const cid = urlParams.get('id');
5497+
if(cid && cid!="")
5498+
{
5499+
userinput = cid;
5500+
}
5501+
}
5502+
userinput = userinput.endsWith('/') ? userinput.slice(0, -1) : userinput;
5503+
if(userinput!="")
5504+
{
5505+
temp_scenario = {
5506+
"title":"",
5507+
"desc": "",
5508+
"opmode":3,
5509+
"chatname": "You",
5510+
"chatopponent": "",
5511+
"gui_type":1,
5512+
"prefmodel1":chatmodels1,
5513+
"prefmodel2":chatmodels2,
5514+
"prompt":"",
5515+
"memory": "",
5516+
"authorsnote": "",
5517+
"worldinfo": [],
5518+
};
5519+
5520+
document.getElementById("scenariodesc").innerText = "Loading scenario from Pygmalion.Chat...";
5521+
fetch(cors_proxy+"?https://server.pygmalion.chat/galatea.v1.PublicCharacterService/CharacterExport", {
5522+
method: 'POST',
5523+
headers: {
5524+
'Content-Type': 'application/json',
5525+
},
5526+
body: JSON.stringify({ "character_id": userinput }),
5527+
referrerPolicy: 'no-referrer',
5528+
})
5529+
.then(x => {
5530+
if(x.ok)
5531+
{
5532+
return x.json();
5533+
}else{
5534+
console.log('Cannot fetch pyg scenario: try fallback to tavern image');
5535+
throw new Error('Cannot fetch character from pygmalion.chat');
5536+
return null;
5537+
}
5538+
})
5539+
.then(data => {
5540+
console.log(data);
5541+
if(data && data.card) //if fetch was successful
5542+
{
5543+
load_temp_scenario_from_tavernobj(data.card,true);
5544+
if(data.card.data && data.card.data.avatar)
5545+
{
5546+
const compressedImg = compressImage(data.card.data.avatar, (compressedImageURI, aspectratio)=>{
5547+
temp_scenario.image = compressedImageURI;
5548+
temp_scenario.image_aspect = aspectratio;
5549+
preview_temp_scenario();
5550+
}, true);
5551+
}
5552+
}else{
5553+
temp_scenario = null;
5554+
document.getElementById("scenariodesc").innerText = "Error: Selected scenario is invalid.";
5555+
}
5556+
5557+
}).catch((error) => {
5558+
temp_scenario = null;
5559+
document.getElementById("scenariodesc").innerText = "Error: Selected scenario is invalid.";
5560+
console.log("Error: " + error);
5561+
});
5562+
}else{
5563+
temp_scenario = null;
5564+
document.getElementById("scenariodesc").innerText = "Error: User input is invalid\n\n Please ensure you have input a valid Pygmalion.Chat UUID.";
5565+
}
5566+
}
5567+
}
5568+
5569+
if(charstr=="")
5570+
{
5571+
inputBox("Enter pygmalion.chat character UUID","Import from pygmalion.chat","","d7950ca8-c241-4725-8de1-42866e389ebf", ()=>{
5572+
let userinput = getInputBoxValue().trim();
5573+
loadpyg(userinput);
5574+
},false);
5575+
}else{
5576+
loadpyg(charstr);
5577+
}
5578+
}
5579+
54645580
function get_chubai_scenario(chubstr="")
54655581
{
54665582
const loadchub = function(userinput)
@@ -5828,7 +5944,8 @@ Current version: 113
58285944
document.getElementById("quickstartcontainer").classList.remove("hidden");
58295945

58305946
let scenarios = `<button type="button" name="" class="scenarioitem purple btn btn-primary" onclick="get_aetherroom_scenario()">Import from<br>aetherroom.club</button>`+
5831-
`<button type="button" name="" class="scenarioitem purple btn btn-primary" onclick="get_chubai_scenario()">Import from<br>chub.ai</button>`;
5947+
`<button type="button" name="" class="scenarioitem purple btn btn-primary" onclick="get_chubai_scenario()">Import from<br>chub.ai</button>` +
5948+
`<button type="button" name="" class="scenarioitem purple btn btn-primary" onclick="get_pygchat_scenario()">Import from<br>pygmalion.chat</button>`;
58325949
for(let i=0;i<scenario_db.length;++i)
58335950
{
58345951
let curr = scenario_db[i];
@@ -8592,7 +8709,7 @@ Current version: 113
85928709
compressImage(img.target.result, (newDataUri) => {
85938710
image_db[imgid].done = true;
85948711
image_db[imgid].result = newDataUri;
8595-
}, true, true, imgres,0.33,true);
8712+
}, true, true, imgres,0.35,true);
85968713

85978714
}
85988715
reader.readAsDataURL(file);
@@ -10507,7 +10624,7 @@ Current version: 113
1050710624
}
1050810625
}
1050910626

10510-
function compressImage(inputDataUri, onDone, isJpeg=true, fixedSize=true, maxSize=NO_HD_RES_PX, quality = 0.33, forceCrop=false) {
10627+
function compressImage(inputDataUri, onDone, isJpeg=true, fixedSize=true, maxSize=NO_HD_RES_PX, quality = 0.35, forceCrop=false) {
1051110628
let img = document.createElement('img');
1051210629
let wantedWidth = maxSize;
1051310630
let wantedHeight = maxSize;
@@ -10571,6 +10688,7 @@ Current version: 113
1057110688
}
1057210689
onDone(dataURI,aspectratio);
1057310690
};
10691+
img.setAttribute('crossorigin', 'anonymous');
1057410692

1057510693
// We put the Data URI in the image's src attribute
1057610694
if (typeof inputDataUri === 'string' || inputDataUri instanceof String)

0 commit comments

Comments
 (0)