Skip to content

Commit

Permalink
updated lite
Browse files Browse the repository at this point in the history
  • Loading branch information
LostRuins committed Feb 24, 2024
1 parent 6d6d79f commit 1bcbd2e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 18 deletions.
106 changes: 90 additions & 16 deletions klite.embd
Original file line number Diff line number Diff line change
Expand Up @@ -4860,12 +4860,16 @@ Current version: 114
try {
let new_loaded_storyobj = JSON.parse(text);
//we don't want to fiddle with the file as its very complex. only handle the parts we are interested in, and just leave the rest untouched.
if (new_loaded_storyobj.prompt == null) {
if (new_loaded_storyobj.prompt != null && !new_loaded_storyobj.scenarioVersion) {
//quick sanity check. if prompt does not exist, this is not a KAI save.

kai_json_load(new_loaded_storyobj,false);
if (selectedFilename && selectedFilename != "") {
last_known_filename = selectedFilename;
}
} else {
//check for tavernai fields
if (new_loaded_storyobj.name != null || new_loaded_storyobj.description != null ||
new_loaded_storyobj.personality != null || new_loaded_storyobj.spec=="chara_card_v2") {
if (!new_loaded_storyobj.scenarioVersion && (new_loaded_storyobj.name != null || new_loaded_storyobj.description != null ||
new_loaded_storyobj.personality != null || new_loaded_storyobj.spec=="chara_card_v2")) {
load_tavern_obj(new_loaded_storyobj);
}
else if (new_loaded_storyobj.char_name != null || new_loaded_storyobj.char_persona != null) {
Expand All @@ -4876,14 +4880,17 @@ Current version: 114
{
kai_json_load(new_loaded_storyobj,false);
}
else if(new_loaded_storyobj.scenarioVersion>1 && new_loaded_storyobj.scenarioVersion<10)
{
nai_json_load(new_loaded_storyobj);
}
else if(new_loaded_storyobj.lorebookVersion>1 && new_loaded_storyobj.lorebookVersion<10)
{
current_wi = load_nai_wi(new_loaded_storyobj);
}
else {
msgbox("Could not load selected json file. Does not appear to be a KoboldAI story or compatible format.");
}
} else {
kai_json_load(new_loaded_storyobj,false);
if (selectedFilename && selectedFilename != "") {
last_known_filename = selectedFilename;
}
}
} catch (e) {
console.log(e)
Expand Down Expand Up @@ -5282,6 +5289,7 @@ Current version: 114
}
function load_ooba_obj(obj)
{
console.log("Loading ooba obj");
let chatopponent = obj.char_name?obj.char_name:defaultchatopponent;
let myname = ((localsettings.chatname && localsettings.chatname!="")?localsettings.chatname:"You");
let memory = obj.char_persona?("Persona: "+obj.char_persona):"";
Expand All @@ -5306,6 +5314,53 @@ Current version: 114
localsettings.gui_type_chat = 2;
render_gametext(true);
}
function nai_json_load(obj)
{
console.log("Loading nai obj");
restart_new_game(false);
if(obj.prompt!="")
{
gametext_arr.push(obj.prompt);
}
current_memory = "";
if(obj.context && obj.context.length>0)
{
for(let i=0;i<obj.context.length;++i)
{
current_memory += obj.context[i].text + "\n";
}
}
if(obj.lorebook)
{
current_wi = load_nai_wi(obj.lorebook);
}
render_gametext(true);
}
function load_nai_wi(obj)
{
console.log("Loading nai wi");
let loadedwi = [];
for (let i=0;i<obj.entries.length;++i) {
var itm = obj.entries[i];
var key = "";
if(itm.keys && itm.keys.length>0)
{
key = itm.keys[0];
}

let nwi = {
"key": key,
"keysecondary": "",
"content": itm.text,
"comment": "",
"folder": null,
"selective": false,
"constant": false
};
loadedwi.push(nwi);
}
return loadedwi;
}

function get_aetherroom_scenario()
{
Expand Down Expand Up @@ -7998,7 +8053,7 @@ Current version: 114
localsettings.max_length = cleannum(localsettings.max_length, 1, (localsettings.max_context_length-1));
localsettings.temperature = cleannum(localsettings.temperature, 0.01, 5);
localsettings.rep_pen = cleannum(localsettings.rep_pen, 0.1, 5);
localsettings.rep_pen_range = cleannum(localsettings.rep_pen_range, 0, 8192);
localsettings.rep_pen_range = cleannum(localsettings.rep_pen_range, 0, localsettings.max_context_length);
localsettings.rep_pen_slope = cleannum(localsettings.rep_pen_slope, 0, 20);
localsettings.top_p = cleannum(localsettings.top_p, 0.002, 1);
localsettings.min_p = cleannum(localsettings.min_p, 0.0, 1);
Expand Down Expand Up @@ -8419,7 +8474,7 @@ Current version: 114

function reset_all_settings()
{
msgboxYesNo("Reset ALL settings to their defaults? This will also reset your aesthetic UI and your current story! Your saved endpoints and API keys will be unaffected.","Confirm Reset All Settings",()=>{
msgboxYesNo("Reset ALL settings to their defaults? This will also reset your aesthetic UI and your current story!","Confirm Reset All Settings",()=>{
localsettings = JSON.parse(JSON.stringify(defaultsettings));
let ns = new AestheticInstructUISettings();
aestheticInstructUISettings = deepCopyAestheticSettings(ns);
Expand Down Expand Up @@ -8783,6 +8838,18 @@ Current version: 114
}
}

function test_tts()
{
inputBox("Enter phrase to speak.","Test TTS","","Input text to speak", ()=>{
let userinput = getInputBoxValue();
userinput = userinput.trim();
let ssval = document.getElementById("ttsselect").value;
if (userinput != null && userinput!="" && ssval > 0) {
tts_speak(userinput,ssval);
}
},false);
}

function toggle_tts_mode()
{
if(document.getElementById("ttsselect").value==XTTS_ID)
Expand Down Expand Up @@ -8813,12 +8880,17 @@ Current version: 114
}
},false);
}
function tts_speak(text)
function tts_speak(text, speech_synth_override=null)
{
if(!text || text=="" || text.trim()=="")
{
return;
}
let ssval = localsettings.speech_synth;
if(speech_synth_override!=null)
{
ssval = speech_synth_override;
}
if(localsettings.narrate_only_dialog)
{
// Remove text within asterisks and the asterisks, then trim
Expand All @@ -8841,7 +8913,7 @@ Current version: 114
}
}

if(localsettings.speech_synth==XTTS_ID) //xtts api server
if(ssval==XTTS_ID) //xtts api server
{
if(xtts_is_connected)
{
Expand Down Expand Up @@ -8877,7 +8949,7 @@ Current version: 114
{
if ('speechSynthesis' in window) {
let utterance = new window.SpeechSynthesisUtterance(text);
utterance.voice = window.speechSynthesis.getVoices()[localsettings.speech_synth - 1];
utterance.voice = window.speechSynthesis.getVoices()[ssval - 1];
window.speechSynthesis.speak(utterance);
}
}
Expand Down Expand Up @@ -9794,7 +9866,8 @@ Current version: 114
{
if(localsettings.opmode==1)
{
submit_payload.prompt = submit_payload.prompt + " \n ASSISTANT: Here is a continuation of the story: \nASSISTANT:";
submit_payload.prompt = submit_payload.prompt + " \nASSISTANT: Here is a direct partial continuation of the story without repeating it: \nASSISTANT:";
submit_payload.params.max_length += 100; //add length
}

urlbase = default_gemini_base;
Expand Down Expand Up @@ -13738,8 +13811,9 @@ Current version: 114
<div class="settingitem">
<div class="settinglabel">
<div class="justifyleft settingsmall">TTS <span class="helpicon">?<span class="helptext">Enable Text-To-Speech to have your story automatically read to you.</span></span></div>
<select class="form-control" id="ttsselect" style="height:20px;padding:0;margin:0px 0 0;" onchange="toggle_tts_mode()">
<select class="form-control" id="ttsselect" style="font-size:12px;height:20px;padding:0;margin:0px 0 0;width:calc(100% - 32px);" onchange="toggle_tts_mode()">
</select>
<button id="test_tts" type="button" class="bg_green btn btn-primary" style="height:20px; width:30px; padding:2px 3px;font-size:11px;" onclick="test_tts()">Test</button>
<div id="xtts_container" class="settinglabel hidden">
<table width="100%"><tr>
<td><button id="xtts_url" type="button" class="btn btn-primary" style="width:100%; padding:2px 3px;margin-top:2px;font-size:11px;" onclick="set_xtts_url()">Set URL</button></td>
Expand Down
2 changes: 0 additions & 2 deletions koboldcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,6 @@ def run_blocking(): #api format 1=basic,2=kai,3=oai,4=oai-chat
genparams["max_length"] = genparams.get('max_tokens', 100)
presence_penalty = genparams.get('presence_penalty', genparams.get('frequency_penalty', 0.0))
genparams["presence_penalty"] = presence_penalty
if presence_penalty > 0:
genparams["rep_pen"] = 1.0 #disable rep pen if presence pen is specified for OAI
# openai allows either a string or a list as a stop sequence
if isinstance(genparams.get('stop',[]), list):
genparams["stop_sequence"] = genparams.get('stop', [])
Expand Down

0 comments on commit 1bcbd2e

Please sign in to comment.