diff --git a/public/index.html b/public/index.html index cc71b1bde..07a29a031 100644 --- a/public/index.html +++ b/public/index.html @@ -128,8 +128,8 @@ var preset_settings = 'gui'; var user_avatar = 'you.png'; var temp = 0.5; - var amount_gen = 80; - var max_context = 2048;//2048; + var amount_gen = 80; //default max length of AI generated responses + var max_context = 2048; var rep_pen = 1; var rep_pen_size = 100; @@ -212,8 +212,8 @@ function QuickRefresh(){ clearChat(); //characters.length = 0 //if this could be enabled it would allow the GetCharacters function to detect files added or removed from the char dir on each panel load - console.log('quickRefresh() -- active_character -- '+active_character); - console.log('quickRefresh() -- this_chid -- '+this_chid); + //console.log('quickRefresh() -- active_character -- '+active_character); + //console.log('quickRefresh() -- this_chid -- '+this_chid); getSettings("def"); getCharacters(); getUserAvatars(); @@ -225,7 +225,25 @@ document.getElementById('nav-toggle').click(); }; } - + + //RossAscends: a utility function for counting characters, even works for unsaved characters. + function CountCharTokens(){ + $('#result_info').html(''); + if (selected_button == 'create'){ + var count_tokens = encode(JSON.stringify(create_save_description+create_save_personality+create_save_scenario+create_save_mes_example)).length; + console.log('This unsaved character has '+count_tokens+' tokens in the defs.'); + }else{ + var count_tokens = encode(JSON.stringify(characters[this_chid].description+characters[this_chid].personality+characters[this_chid].scenario+characters[this_chid].mes_example)).length; + console.log(characters[this_chid].name+' has '+count_tokens+' tokens in the defs.'); + } + + if(count_tokens < 1024){ + $('#result_info').html(count_tokens+" Tokens"); + }else{ + $('#result_info').html(""+count_tokens+" Tokens(TOO MANY TOKENS)"); + } + } + $('#characloud_url').click(function(){ window.open('https://boosty.to/tavernai', '_blank'); }); @@ -350,7 +368,7 @@ //console.log('printCharacters() entered'); $("#rm_print_characters_block").empty(); - console.log('printCharacters() -- sees '+characters.length+' characters.'); + //console.log('printCharacters() -- sees '+characters.length+' characters.'); characters.forEach(function(item, i, arr) { var this_avatar = default_avatar; @@ -359,7 +377,7 @@ } //RossAscends: changed 'prepend' to 'append' to make alphabetical sorting display correctly. $("#rm_print_characters_block").append('
'+item.name+'
'); - console.log('printcharacters() -- printing -- ChID '+i+' ('+item.name+')'); + //console.log('printcharacters() -- printing -- ChID '+i+' ('+item.name+')'); }); } @@ -889,6 +907,8 @@ } function runGenerate(cycleGenerationPromt = ''){ + + generatedPromtCache+=cycleGenerationPromt; if(generatedPromtCache.length == 0){ chatString = ""; @@ -945,7 +965,8 @@ //Send story string var mesSendString = ''; var mesExmString = ''; - function setPromtString(){ + + function setPromtString(){ mesSendString = ''; mesExmString = ''; for(let j = 0; j < count_exm_add; j++){ @@ -955,17 +976,22 @@ mesSendString+=mesSend[j]; } } + function checkPromtSize(){ setPromtString(); let thisPromtContextSize = encode(JSON.stringify(storyString+mesExmString+mesSendString+anchorTop+anchorBottom+charPersonality+generatedPromtCache)).length+120; - if(thisPromtContextSize > this_max_context){ - if(count_exm_add > 0){ + + if(thisPromtContextSize > this_max_context){ //if the prepared prompt is larger than the max context size... + + if(count_exm_add > 0){ // ..and we have example mesages.. + //console.log('Context size: '+thisPromtContextSize+' -- too big, removing example message'); //mesExamplesArray.length = mesExamplesArray.length-1; - count_exm_add--; - checkPromtSize(); - }else if(mesSend.length > 0){ - mesSend.shift(); - checkPromtSize(); + count_exm_add--; // remove the example messages... + checkPromtSize(); // and try agin... + }else if(mesSend.length > 0){ // if the chat history is longer than 0 + //console.log('Context size: '+thisPromtContextSize+' -- too big, removing oldest chat message'); + mesSend.shift(); // remove the first (oldest) chat entry.. + checkPromtSize(); // and check size again.. }else{ //end } @@ -975,6 +1001,7 @@ if(generatedPromtCache.length > 0){ + //console.log('Generated Prompt Cache length: '+generatedPromtCache.length); checkPromtSize(); }else{ setPromtString(); @@ -991,26 +1018,35 @@ var generate_data; if(main_api == 'kobold'){ var generate_data = {prompt: finalPromt, gui_settings: true,max_length: amount_gen,temperature: temp, max_context_length: max_context}; - if(preset_settings != 'gui'){ + if(preset_settings != 'gui'){ //if we aren't using the kobold GUI settings... var this_settings = koboldai_settings[koboldai_setting_names[preset_settings]]; - var this_amount_gen = parseInt(amount_gen); - if(is_pygmalion){ - if(tokens_already_generated === 0){ - if(parseInt(amount_gen) >= 50){ - this_amount_gen = 50; + var this_amount_gen = parseInt(amount_gen); // how many tokens the AI will be requested to generate + + if(is_pygmalion){ // if we are using a pygmalion model... + if(tokens_already_generated === 0){ // if nothing has been generated yet.. + if(parseInt(amount_gen) >= 50){ // if the max gen setting is > 50...( + this_amount_gen = 50; // then only try to make 50 this cycle.. }else{ - this_amount_gen = parseInt(amount_gen); - } - - }else{ - if(parseInt(amount_gen) - tokens_already_generated < tokens_cycle_count){ - this_amount_gen = parseInt(amount_gen) - tokens_already_generated; + this_amount_gen = parseInt(amount_gen); // otherwise, make as much as the max amount request. + } + + //console.log('Max Gen Amount: '+parseInt(amount_gen)); + + }else{ // if we already recieved some generated text... + if(parseInt(amount_gen) - tokens_already_generated < tokens_cycle_count){ // if the remaining tokens to be made is less than next potential cycle count + this_amount_gen = parseInt(amount_gen) - tokens_already_generated; // subtract already generated amount from the desired max gen amount + //console.log('Remaining tokens to be requested: '+this_amount_gen); }else{ - this_amount_gen = tokens_cycle_count; + this_amount_gen = tokens_cycle_count; // otherwise make the standard cycle amont (frist 50, and 30 after that) } } - } + //console.log('Upcoming token request amt: '+this_amount_gen); + + }else{ + //console.log('non-pyg model or GUI Settings are being used -- skipping request split'); + } + generate_data = {prompt: finalPromt, gui_settings: false, sampler_order: this_settings.sampler_order, @@ -1076,10 +1112,13 @@ dataType: "json", contentType: "application/json", success: function(data){ - tokens_already_generated += this_amount_gen; + tokens_already_generated += this_amount_gen; // add new gen amt to any prev gen counter.. + + + //console.log('Tokens requested in total: '+tokens_already_generated); //$("#send_textarea").focus(); //$("#send_textarea").removeAttr('disabled'); - is_send_press = false; + is_send_press = false; if(data.error != true){ //const getData = await response.json(); if(main_api == 'kobold'){ @@ -1089,16 +1128,22 @@ var getMessage = data.output; } - //Pygmalion run again + //Pygmalion run again // to make it continue generating so long as it's under max_amount and hasn't signaled + // an end to the character's response via typing "You:" or adding "" if(is_pygmalion){ if_typing_text = false; message_already_generated +=getMessage; - if(message_already_generated.indexOf('You:') === -1 && message_already_generated.indexOf('<|endoftext|>') === -1 && tokens_already_generated < parseInt(amount_gen) && getMessage.length > 0){ - runGenerate(getMessage); + //console.log('AI Response so far: '+message_already_generated); + if( message_already_generated.indexOf('You:') === -1 && //if there is no 'You:' in the response msg + message_already_generated.indexOf('<|endoftext|>') === -1 && //if there is no stamp in the response msg + tokens_already_generated < parseInt(amount_gen) && //if the gen'd msg is less than the max response length.. + getMessage.length > 0){ //if we actually have gen'd text at all... + runGenerate(getMessage); //generate again with the 'GetMessage' argument.. return; } getMessage = message_already_generated; + } //Formating getMessage = $.trim(getMessage); @@ -1135,10 +1180,10 @@ addOneMessage(chat[chat.length-1]); $( "#send_but" ).css("display", "inline"); $( "#loading_mes" ).css("display", "none"); - //console.log('/savechat called by /Generate'); + //let final_message_length = encode(JSON.stringify(getMessage)).length; + //console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)'); saveChat(); }else{ - //console.log('run force_name2 protocol'); Generate('force_name2'); } }else{ @@ -1223,9 +1268,7 @@ chat_create_date = humanizedISO8601DateTime(); } //console.log(chat); - //console.log('getChatResults called by /getchat'); getChatResult(); - //console.log('savechat called by /getchat'); saveChat(); }, error: function (jqXHR, exception) { @@ -1340,6 +1383,7 @@ }); function select_rm_create(){ menu_type = 'create'; + //console.log('select_rm_Create() -- selected button: '+selected_button); if(selected_button == 'create'){ if(create_save_avatar != ''){ @@ -1347,6 +1391,7 @@ read_avatar_load($("#add_avatar_button").get(0)); } } + $( "#rm_characters_block" ).css("display", "none"); $( "#rm_api_block" ).css("display", "none"); $( "#rm_ch_create_block" ).css("display", "block"); @@ -1359,6 +1404,7 @@ complete: function() { } }); $( "#rm_info_block" ).css("display", "none"); + $( "#delete_button_div" ).css("display", "none"); $( "#delete_button" ).css("display", "none"); $( "#export_button" ).css("display", "none"); @@ -1389,6 +1435,7 @@ $("#name_div").css("display", "block"); $("#form_create").attr("actiontype", "createcharacter"); + CountCharTokens(); } function select_rm_characters(){ QuickRefresh(); @@ -1484,15 +1531,9 @@ active_character = this_chid; clearChat(); chat.length = 0; - getChat(); - var count_tokens = encode(JSON.stringify(characters[this_chid].description+characters[this_chid].personality+characters[this_chid].scenario+characters[this_chid].mes_example)).length; - //RossAscends: added token counter to load when a character is selected, instead of waiting for an edit. - if(count_tokens < 1024){ - $('#result_info').html(count_tokens+" Tokens"); - }else{ - $('#result_info').html(""+count_tokens+" Tokens(TOO MANY TOKENS)"); - } - console.log('Clicked on '+characters[this_chid].name+' Active_Character set to: '+active_character+' (ChID:'+this_chid+')'); + getChat(); + + //console.log('Clicked on '+characters[this_chid].name+' Active_Character set to: '+active_character+' (ChID:'+this_chid+')'); } }else{ //if clicked on character that was already selected selected_button = 'character_edit'; @@ -1888,13 +1929,8 @@ $('#create_button').attr('value','Save'); //console.log('/editcharacters -- this_chid -- '+this_chid); if(this_chid != undefined && this_chid != 'invalid-safety-id'){ //added check to avoid trying to load tokens in case of character deletion - var count_tokens = encode(JSON.stringify(characters[this_chid].description+characters[this_chid].personality+characters[this_chid].scenario+characters[this_chid].mes_example)).length; + CountCharTokens(); } - if(count_tokens < 1024){ - $('#result_info').html(count_tokens+" Tokens"); - }else{ - $('#result_info').html(""+count_tokens+" Tokens(TOO MANY TOKENS)"); - } }, error: function (jqXHR, exception) { $('#create_button').removeAttr("disabled"); @@ -1921,17 +1957,20 @@ }); $('#description_textarea').on('keyup paste cut', function(){//change keyup paste cut + if(menu_type == 'create'){ create_save_description = $('#description_textarea').val(); + CountCharTokens(); }else{ timerSaveEdit = setTimeout(() => {$("#create_button").click();},durationSaveEdit); } - + }); $('#personality_textarea').on('keyup paste cut', function(){ if(menu_type == 'create'){ create_save_personality = $('#personality_textarea').val(); + CountCharTokens(); }else{ timerSaveEdit = setTimeout(() => {$("#create_button").click();},durationSaveEdit); } @@ -1940,6 +1979,7 @@ if(menu_type == 'create'){ create_save_scenario = $('#scenario_pole').val(); + CountCharTokens(); }else{ timerSaveEdit = setTimeout(() => {$("#create_button").click();},durationSaveEdit); } @@ -1948,6 +1988,7 @@ if(menu_type == 'create'){ create_save_mes_example = $('#mes_example_textarea').val(); + CountCharTokens(); }else{ timerSaveEdit = setTimeout(() => {$("#create_button").click();},durationSaveEdit); } @@ -1956,6 +1997,7 @@ if(menu_type == 'create'){ create_save_first_message = $('#firstmessage_textarea').val(); + CountCharTokens(); }else{ timerSaveEdit = setTimeout(() => {$("#create_button").click();},durationSaveEdit); } @@ -2338,7 +2380,9 @@ novelai_settings[i] = JSON.parse(item); }); var arr_holder = {}; - $("#settings_perset_novel").empty(); + + $("#settings_perset_novel").empty; + novelai_setting_names.forEach(function(item, i, arr) { arr_holder[item] = i; $('#settings_perset_novel').append(''); @@ -2357,7 +2401,10 @@ koboldai_settings[i] = JSON.parse(item); }); var arr_holder = {}; - $("#settings_perset").empty(); //RossAscends: uncommented this to prevent settings selector from doubling preset list on QuickRefresh + + $("#settings_perset").empty(); //RossAscends: uncommented this to prevent settings selector from doubling preset list on QuickRefresh + $("#settings_perset").append(''); //adding in the GUI settings, since it is not loaded dynamically + koboldai_setting_names.forEach(function(item, i, arr) { arr_holder[item] = i; $('#settings_perset').append(''); @@ -3046,15 +3093,18 @@
-

Create character

+

- Advanced Defininitions
+ +
+

Personality summary

A brief description of the personality ?
- +

Scenario

Circumstances and context of the dialogue ?
@@ -3118,7 +3168,10 @@
-
+
+
+
+
@@ -3147,48 +3200,52 @@