Skip to content

Commit

Permalink
fixed chub ai imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Concedo authored and Concedo committed Nov 30, 2023
1 parent 35451fe commit 4ab9134
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
62 changes: 61 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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: 98
Current version: 99
-Concedo
-->

Expand Down Expand Up @@ -2523,6 +2523,21 @@
}
}

function readTavernPngFromBlob(blob, onDone)
{
var fileReader = new FileReader();
fileReader.onload = function(event) {
var data = event.target.result;
var arr = new Uint8Array(data);
var result = convertTavernPng(arr);
if(onDone)
{
onDone(result);
}
};
fileReader.readAsArrayBuffer(blob);
}

//import tavern png data. adapted from png-chunks-extract under MIT license
//accepts png input data, and returns the extracted JSON
function convertTavernPng(data)
Expand Down Expand Up @@ -5052,6 +5067,7 @@
"authorsnote": "",
"worldinfo": [],
};
let card_is_defective = (data.name==""&&previewtxt==""&&greeting==""&&cdesc==""&&cdef=="");

//try to obtain the full portrait image
fetch("https://api.chub.ai/api/characters/download", {
Expand All @@ -5076,6 +5092,50 @@
})
.then(blob => {
preview_temp_scenario();

if(card_is_defective)
{
readTavernPngFromBlob(blob,(obj)=>{
if(obj!=null)
{
//a lightweight tavern card loader, not fully compliant
if(obj.spec=="chara_card_v2" && obj.data!=null)
{
obj = obj.data;
}
let chatopponent = obj.name?obj.name:"Bot";
let memory = obj.description?("Persona: "+obj.description):"";
memory += obj.personality?("\nPersonality: "+obj.personality):"";
let scenario = obj.scenario?obj.scenario:"";
let examplemsg = obj.mes_example?obj.mes_example:"";
let greeting = obj.first_mes?obj.first_mes:"";
let sysprompt = obj.system_prompt?obj.system_prompt:"";

if(scenario!="")
{
scenario = "\n[Scenario: "+scenario+"]";
}
if(examplemsg!="")
{
examplemsg = "\n"+examplemsg;
}
if(sysprompt!="")
{
sysprompt = sysprompt+"\n";
}
let combinedmem = sysprompt + memory + scenario + examplemsg;
temp_scenario.title = chatopponent;
let prev2 = replaceAll(obj.description,"{{char}}",chatopponent,true);
prev2 = replaceAll(prev2,"{{user}}","You",true);
temp_scenario.desc = prev2;
temp_scenario.chatopponent = chatopponent;
temp_scenario.prompt = ("\n{{char}}: "+ greeting);
temp_scenario.memory = combinedmem;
preview_temp_scenario();
}

});
}
const objectURL = URL.createObjectURL(blob);
const compressedImg = compressImage(objectURL, (compressedImageURI, aspectratio)=>{
temp_scenario.image = compressedImageURI;
Expand Down
16 changes: 13 additions & 3 deletions koboldcpp_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,19 @@
"content": {
"application/json": {
"example": {
"prompt": "Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze.",
"temperature": 0.5,
"top_p": 0.9
"max_context_length": 2048,
"max_length": 100,
"prompt": "Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze.",
"quiet": false,
"rep_pen": 1.1,
"rep_pen_range": 256,
"rep_pen_slope": 1,
"temperature": 0.5,
"tfs": 1.0,
"top_a": 0,
"top_k": 100,
"top_p": 0.9,
"typical": 1.0
},
"schema": {
"$ref": "#/components/schemas/GenerationInput"
Expand Down

0 comments on commit 4ab9134

Please sign in to comment.