diff --git a/public/NovelAI Settings/Classic-Euterpe.settings b/public/NovelAI Settings/Classic-Euterpe.settings new file mode 100644 index 000000000..dcfc70285 --- /dev/null +++ b/public/NovelAI Settings/Classic-Euterpe.settings @@ -0,0 +1,14 @@ +{ + "order": [ + 3, + 0 + ], + "temperature": 1.11, + "max_length": 90, + "min_length": 1, + "tail_free_sampling": 0.68, + "repetition_penalty": 1.11, + "repetition_penalty_range": 320, + "repetition_penalty_frequency": 0, + "repetition_penalty_presence": 0 +} \ No newline at end of file diff --git a/public/NovelAI Settings/Classic-Krake.settings b/public/NovelAI Settings/Classic-Krake.settings new file mode 100644 index 000000000..8d9025b40 --- /dev/null +++ b/public/NovelAI Settings/Classic-Krake.settings @@ -0,0 +1,14 @@ +{ + "order": [ + 3, + 0 + ], + "temperature": 1.7, + "max_length": 90, + "min_length": 1, + "tail_free_sampling": 0.6602, + "repetition_penalty": 1.0565, + "repetition_penalty_range": 340, + "repetition_penalty_frequency": 0, + "repetition_penalty_presence": 0 +} \ No newline at end of file diff --git a/public/backgrounds/flasks.png b/public/backgrounds/flasks.png new file mode 100644 index 000000000..eba94a3dc Binary files /dev/null and b/public/backgrounds/flasks.png differ diff --git a/public/backgrounds/kingdom.png b/public/backgrounds/kingdom.png new file mode 100644 index 000000000..70515e214 Binary files /dev/null and b/public/backgrounds/kingdom.png differ diff --git a/public/backgrounds/market1.png b/public/backgrounds/market.png similarity index 100% rename from public/backgrounds/market1.png rename to public/backgrounds/market.png diff --git a/public/backgrounds/noble1.png b/public/backgrounds/noble1.png new file mode 100644 index 000000000..72cba2673 Binary files /dev/null and b/public/backgrounds/noble1.png differ diff --git a/public/backgrounds/noble2.png b/public/backgrounds/noble2.png new file mode 100644 index 000000000..45e606285 Binary files /dev/null and b/public/backgrounds/noble2.png differ diff --git a/public/backgrounds/ruins.png b/public/backgrounds/ruins.png new file mode 100644 index 000000000..3d469a1b7 Binary files /dev/null and b/public/backgrounds/ruins.png differ diff --git a/public/backgrounds/smokycity.png b/public/backgrounds/smokycity.png new file mode 100644 index 000000000..64913c304 Binary files /dev/null and b/public/backgrounds/smokycity.png differ diff --git a/public/backgrounds/warmtown.png b/public/backgrounds/warmtown.png new file mode 100644 index 000000000..8c7d88e61 Binary files /dev/null and b/public/backgrounds/warmtown.png differ diff --git a/public/backgrounds/whitesnow.png b/public/backgrounds/whitesnow.png new file mode 100644 index 000000000..9c9fe8d62 Binary files /dev/null and b/public/backgrounds/whitesnow.png differ diff --git a/public/img/cancel.png b/public/img/cancel.png new file mode 100644 index 000000000..26b29623c Binary files /dev/null and b/public/img/cancel.png differ diff --git a/public/img/done.png b/public/img/done.png new file mode 100644 index 000000000..e119b4aa7 Binary files /dev/null and b/public/img/done.png differ diff --git a/public/img/kobold.png b/public/img/kobold.png new file mode 100644 index 000000000..914871155 Binary files /dev/null and b/public/img/kobold.png differ diff --git a/public/img/love.png b/public/img/love.png new file mode 100644 index 000000000..729456657 Binary files /dev/null and b/public/img/love.png differ diff --git a/public/img/novelai.png b/public/img/novelai.png new file mode 100644 index 000000000..2eb1b636a Binary files /dev/null and b/public/img/novelai.png differ diff --git a/public/img/scroll.png b/public/img/scroll.png new file mode 100644 index 000000000..22e3513e8 Binary files /dev/null and b/public/img/scroll.png differ diff --git a/public/index.html b/public/index.html index 5d21cf9e6..28f427d36 100644 --- a/public/index.html +++ b/public/index.html @@ -13,13 +13,13 @@ //2) Count tokens print fix //3) Make wildcards for characters //4) Fix same callback in server.js create/edit - //5) Edit messages + //6) Reload setting files when they was rewrite //7) Show an indicator that shows the message in context or not //8) Сombine multiple messages into one if the text continues //9) Access for many chats //10) Design presets - //11) Fix sended propt with json markup + //11) Fix sending propt with json additional symbols (kinda \\ and etc) // //import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js"; //let text = "hello world"; @@ -29,9 +29,10 @@ import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js"; $(document).ready(function(){ var bg_menu_toggle = false; - var name1 = "You"; + var default_user_name = "You"; + var name1 = default_user_name; var name2 = "Chloe"; - var chat = ['\nChloe: *You went inside. The air smelled of fried meat, tobacco and a hint of wine. A dim light was cast by candles, and a fire crackled in the fireplace. It seems to be a very pleasant place. Behind the wooden bar is an elf waitress, she is smiling. Her ears are very pointy, and there is a twinkle in her eye. She wears glasses and a white aporn. As soon as she noticed you, she immediately came right up close to you.*\n\n Hello there! How is your evening going?\n\n@@@TavernAI v1.0.0@@@
Give a Tip




']; + var chat = ['\nChloe: *You went inside. The air smelled of fried meat, tobacco and a hint of wine. A dim light was cast by candles, and a fire crackled in the fireplace. It seems to be a very pleasant place. Behind the wooden bar is an elf waitress, she is smiling. Her ears are very pointy, and there is a twinkle in her eye. She wears glasses and a white aporn. As soon as she noticed you, she immediately came right up close to you.*\n\n Hello there! How is your evening going?\n\n@@@TavernAI v1.1.0@@@
Give a Tip




']; var default_ch_mes = "Hello"; var count_view_mes = 0; var mesStr = ''; @@ -61,14 +62,21 @@ var api_server = ""; var interval_timer = setInterval(getStatus, 2000); + var interval_timer_novel = setInterval(getStatusNovel, 3000); var is_get_status = false; + var is_get_status_novel = false; var is_api_button_press = false; + var is_api_button_press_novel = false; var is_send_press = false;//Send generation var add_mes_without_animation = false; var this_del_mes = 0; + var this_edit_mes_text = ''; + var this_edit_mes_chname = ''; + var this_edit_mes_id; + const delay = ms => new Promise(res => setTimeout(res, ms)); //settings var settings; @@ -79,14 +87,33 @@ var temp = 0.5; var amount_gen = 80; var max_context = 2048;//2048; - - var postAnchor = ''; + var rep_pen = 1; + var rep_pen_size = 100; + + var anchor_order = 0; + var style_anchor = true; + var character_anchor = true; + + var main_api = 'kobold'; + //novel settings + var temp_novel = 0.5; + var rep_pen_novel = 1; + var rep_pen_size_novel = 100; + + var api_key_novel = ""; + var novel_tier; + var model_novel = "euterpe-v2"; + var novelai_settings; + var novelai_setting_names; + var preset_settings_novel = 'Classic-Krake'; + //css var bg1_toggle = true; var css_mes_bg = $('
').css('background'); var css_send_form_display = $('
').css('display'); ///////////// - getSettings(); + getSettings("def"); + //var interval_getSettings = setInterval(getSettings, 1000); getCharacters(); printMessages(); @@ -101,13 +128,18 @@ $("#online_status_text").html("No connection..."); $("#online_status_indicator2").css("background-color", "red"); $("#online_status_text2").html("No connection..."); + $("#online_status_indicator3").css("background-color", "red"); + $("#online_status_text3").html("No connection..."); is_get_status = false; + is_get_status_novel = false; }else{ $("#online_status_indicator").css("background-color", "black"); $("#online_status").css("opacity", 0.0); $("#online_status_text").html(""); $("#online_status_indicator2").css("background-color", "green"); $("#online_status_text2").html(online_status); + $("#online_status_indicator3").css("background-color", "green"); + $("#online_status_text3").html(online_status); } } @@ -133,7 +165,10 @@ //processData: false, success: function(data){ online_status = data.result; - + if(online_status == undefined){ + online_status = 'no_connection'; + } + //console.log(online_status); resultCheckStatus(); }, @@ -145,8 +180,13 @@ resultCheckStatus(); } }); + }else{ + if(is_get_status_novel != true){ + online_status = 'no_connection'; + } } } + function resultCheckStatus(){ is_api_button_press = false; checkOnlineStatus(); @@ -199,6 +239,7 @@ } } async function getBackgrounds() { + const response = await fetch("/getbackgrounds", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -291,6 +332,13 @@ count_view_mes = 0; $('#chat').html(''); } + function messageFormating(mes, ch_name){ + mes = mes.replace(/\*\*(.+?)\*\*/g, '$1').replace(/\*(.+?)\*/g, '$1').replace(/\n/g, '
'); + if(ch_name !== name1){ + mes = mes.replaceAll(name2+":", ""); + } + return mes; + } function addOneMessage(message){ message = message.replace(/^\s+/g, ''); //console.log(message.indexOf(name1+":")); @@ -320,11 +368,13 @@ } //Formating - messageText = messageText.replace(/\*\*(.+?)\*\*/g, '$1').replace(/\*(.+?)\*/g, '$1').replace(/\n/g, '
'); - if(characterName != name1){ - messageText = messageText.replaceAll(name2+":", ""); - } - $("#chat").append( "
"+characterName+"
"+messageText+"
" ); + //messageText = messageText.replace(/\*\*(.+?)\*\*/g, '$1').replace(/\*(.+?)\*/g, '$1').replace(/\n/g, '
'); + //if(characterName != name1){ + //messageText = messageText.replaceAll(name2+":", ""); + //} + messageText = messageFormating(messageText, characterName); + + $("#chat").append( "
"+characterName+"
"+messageText+"
" ); count_view_mes++; if(!add_mes_without_animation){ $('#chat').children().last().css("opacity",1.0); @@ -383,9 +433,30 @@ var userSendString = ""; - postAnchor = "talks a lot with descriptions";//'Talk a lot with description what is going on around';// in asterisks + var postAnchorChar = "talks a lot with descriptions";//'Talk a lot with description what is going on around';// in asterisks + var postAnchorStyle = "[Writing style: very long messages]";//"[Genre: roleplay chat][Tone: very long messages with descriptions]"; + var anchorTop = ''; + var anchorBottom = ''; + var topAnchorDepth = 8; + + if(character_anchor){ + if(anchor_order === 0){ + anchorTop = "["+name2+" "+postAnchorChar+"]"; + }else{ + anchorBottom = "["+name2+" "+postAnchorChar+"]"; + } + } + if(style_anchor){ + if(anchor_order === 1){ + anchorTop = postAnchorStyle; + }else{ + anchorBottom = postAnchorStyle; + } + } + + //********************************* - //KoboldAI PRE FORMATING STRING + //PRE FORMATING STRING //********************************* userSendString = name1+": "+textareaText+"\n"; @@ -401,18 +472,14 @@ charPersonality = "["+name2+" is "+charPersonality+"]";//"["+name2+"'s personality: "+charPersonality+"]"; } - if($.trim(postAnchor.length) > 0){ - postAnchor = "["+name2+" "+postAnchor+"]"; - } - var anchorAndPersonality = charPersonality+postAnchor; storyString = $.trim(characters[this_chid].description); if($.trim(storyString.length) > 0){ if(storyString.slice(-1) !== ']' || storyString.substr(0,1) !== '['){ storyString = '['+storyString+']'; } } - if(count_view_mes < 5){ - storyString+=anchorAndPersonality; + if(count_view_mes < topAnchorDepth){ + storyString+=charPersonality; } if(count_view_mes < 10){ storyString+='\nThen the dialogue between '+name1+' and '+name2+' begins.\n'; @@ -424,9 +491,19 @@ j++; } //chat2 = chat2.reverse(); + var this_max_context = 1487; + if(main_api == 'kobold') this_max_context = max_context; + if(main_api == 'novel'){ + if(novel_tier === 1){ + this_max_context = 1024; + }else{ + this_max_context = 2048; + } + } + var i = 0; for (const item of chat2) {//console.log(encode("dsfs").length); - if(encode(JSON.stringify(characters[this_chid].description+chatString+postAnchor+characters[this_chid].personality)).length+120 < max_context){ //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide) + if(encode(JSON.stringify(characters[this_chid].description+chatString+anchorTop+anchorBottom+characters[this_chid].personality)).length+120 < this_max_context){ //(The number of tokens in the entire promt) need fix, it must count correctly (added +120, so that the description of the character does not hide) chatString = item+chatString; arrMes[arrMes.length] = item; @@ -452,16 +529,17 @@ chatString = chatString.substr(0,chatString.length-1); } } - if(i == arrMes.length-4 && count_view_mes>=5 && !is_add_personality){ + if(i === arrMes.length-topAnchorDepth && count_view_mes>=topAnchorDepth && !is_add_personality){ is_add_personality = true; //chatString = chatString.substr(0,chatString.length-1); //anchorAndPersonality = "[Genre: roleplay chat][Tone: very long messages with descriptions]"; - chatString+=anchorAndPersonality+'\n'; + chatString+=charPersonality+anchorTop+'\n'; } if(i >= arrMes.length-1 && count_view_mes>=4 && $.trim(item).substr(0, (name1+":").length) == name1+":"){//For add anchor in end chatString = chatString.substr(0,chatString.length-1); - chatString+="[Writing style: very long messages]"; + //chatString+=postAnchor+"\n";//"[Writing style: very long messages]\n"; + chatString+=anchorBottom+"\n"; } }); @@ -475,38 +553,70 @@ } //console.log(JSON.stringify(storyString)); //Send story string - var generate_data = {prompt: storyString, gui_settings: true,max_length: amount_gen,temperature: temp, max_context_length: max_context}; - if(preset_settings != 'gui'){ + var generate_data; + if(main_api == 'kobold'){ + var generate_data = {prompt: storyString, gui_settings: true,max_length: amount_gen,temperature: temp, max_context_length: max_context}; + if(preset_settings != 'gui'){ - var this_settings = koboldai_settings[koboldai_setting_names[preset_settings]]; + var this_settings = koboldai_settings[koboldai_setting_names[preset_settings]]; - generate_data = {prompt: storyString, - gui_settings: false, - sampler_order: this_settings.sampler_order, - max_context_length: max_context,//this_settings.max_length, - max_length: amount_gen, - rep_pen: this_settings.rep_pen, - rep_pen_range: this_settings.rep_pen_range, - rep_pen_slope: this_settings.rep_pen_slope, - temperature: temp, - tfs: this_settings.tfs, - top_a: this_settings.top_a, - top_k: this_settings.top_k, - top_p: this_settings.top_p, - typical: this_settings.typical, - s1:this_settings.sampler_order[0], - s2:this_settings.sampler_order[1], - s3:this_settings.sampler_order[2], - s4:this_settings.sampler_order[3], - s5:this_settings.sampler_order[4], - s6:this_settings.sampler_order[5], - s7:this_settings.sampler_order[6] - }; + generate_data = {prompt: storyString, + gui_settings: false, + sampler_order: this_settings.sampler_order, + max_context_length: parseInt(max_context),//this_settings.max_length, + max_length: parseInt(amount_gen), + rep_pen: parseFloat(rep_pen), + rep_pen_range: parseInt(rep_pen_size), + rep_pen_slope: this_settings.rep_pen_slope, + temperature: parseFloat(temp), + tfs: this_settings.tfs, + top_a: this_settings.top_a, + top_k: this_settings.top_k, + top_p: this_settings.top_p, + typical: this_settings.typical, + s1:this_settings.sampler_order[0], + s2:this_settings.sampler_order[1], + s3:this_settings.sampler_order[2], + s4:this_settings.sampler_order[3], + s5:this_settings.sampler_order[4], + s6:this_settings.sampler_order[5], + s7:this_settings.sampler_order[6] + }; + } + } + if(main_api == 'novel'){ + var this_settings = novelai_settings[novelai_setting_names[preset_settings_novel]]; + generate_data = {"input": storyString, + "model": model_novel, + "use_string": true, + "temperature": parseFloat(temp_novel), + "max_length": this_settings.max_length, + "min_length": this_settings.min_length, + "tail_free_sampling": this_settings.tail_free_sampling, + "repetition_penalty": parseFloat(rep_pen_novel), + "repetition_penalty_range": parseInt(rep_pen_size_novel), + "repetition_penalty_frequency": this_settings.repetition_penalty_frequency, + "repetition_penalty_presence": this_settings.repetition_penalty_presence, + //"stop_sequences": {{187}}, + //bad_words_ids = {{50256}, {0}, {1}}; + //generate_until_sentence = true; + "use_cache": false, + //use_string = true; + "return_full_text": false, + "prefix": "vanilla", + "order": this_settings.order + }; + } + var generate_url = ''; + if(main_api == 'kobold'){ + generate_url = '/generate'; + } + if(main_api == 'novel'){ + generate_url = '/generate_novelai'; } - jQuery.ajax({ type: 'POST', // - url: '/generate', // + url: generate_url, // data: JSON.stringify(generate_data), beforeSend: function(){ //$('#create_button').attr('value','Creating...'); @@ -521,8 +631,12 @@ is_send_press = false; if(data.error != true){ //const getData = await response.json(); - var getMessage = data.results[0].text; - + if(main_api == 'kobold'){ + var getMessage = data.results[0].text; + } + if(main_api == 'novel'){ + var getMessage = data.output; + } //Formating getMessage = $.trim(getMessage); if(getMessage.indexOf(name1+":") != -1){ @@ -569,10 +683,15 @@ } async function saveChat() { + if(chat[0].indexOf('') === -1){ + var save_chat = [''+name1, ...chat]; + }else{ + var save_chat = chat; + } jQuery.ajax({ type: 'POST', url: '/savechat', - data: JSON.stringify({ch_name: characters[this_chid].name, file_name: characters[this_chid].chat, chat: chat}), + data: JSON.stringify({ch_name: characters[this_chid].name, file_name: characters[this_chid].chat, chat: save_chat}), beforeSend: function(){ //$('#create_button').attr('value','Creating...'); }, @@ -620,6 +739,33 @@ function getChatResult(){ name2 = characters[this_chid].name; if(chat.length > 1){ + if(chat[0].indexOf('') !== -1){ + var this_chat_user_name = chat[0].substr(''.length, chat[0].length); + if(this_chat_user_name !== name1){ + var arr_char = []; + chat.forEach(function(item, i) { + if(i !== 0){ + //var str = item.replace(new RegExp(this_chat_user_name+':', "g"), name1+':'); + if(chat[i].indexOf(name2+":") !== 0){ + var str = item.replace(this_chat_user_name+':', name1+':'); + arr_char.push(str); + }else{ + arr_char.push(item); + } + } + }); + chat = []; + chat = arr_char; + }else{ + chat.shift(); + } + //chat.shift(); + }else{ //if(default_user_name !== name1){ + chat.forEach(function(item, i) { + var str = item.replace(new RegExp(default_user_name+':', "g"), name1+':'); + chat[i] = str; + }); + } }else{ @@ -803,6 +949,7 @@ $(document).on('click', '.character_select', function(){ if(this_chid !== $(this).attr("chid")){ if(!is_send_press){ + this_edit_mes_id = undefined; selected_button = 'character_edit'; this_chid = $(this).attr("chid"); clearChat(); @@ -816,6 +963,9 @@ } }); + $(document).on('input', '.edit_textarea', function(){ + $(this).height(0).height(this.scrollHeight); + }); $(document).on('click', '.del_checkbox', function(){ $('.del_checkbox').each(function(){ $(this).prop( "checked", false ); @@ -1209,6 +1359,7 @@ //getStatus(); } }); + $( "body" ).click(function() { if($("#options").css('opacity') == 1.0){ $('#options').transition({ @@ -1302,23 +1453,82 @@ preset_settings = $('#settings_perset').find(":selected").text(); temp = koboldai_settings[koboldai_setting_names[preset_settings]].temp; amount_gen = koboldai_settings[koboldai_setting_names[preset_settings]].genamt; + rep_pen = koboldai_settings[koboldai_setting_names[preset_settings]].rep_pen; + rep_pen_size = koboldai_settings[koboldai_setting_names[preset_settings]].rep_pen_range; $('#temp').val(temp); - $('#amount_gen').val(amount_gen); $('#temp_counter').html(temp); + + $('#amount_gen').val(amount_gen); $('#amount_gen_counter').html(amount_gen); + $('#rep_pen').val(rep_pen); + $('#rep_pen_counter').html(rep_pen); + + $('#rep_pen_size').val(rep_pen_size); + $('#rep_pen_size_counter').html(rep_pen_size+" Tokens"); + $("#range_block").children().prop("disabled", false); $("#range_block").css('opacity',1.0); + $("#amount_gen_block").children().prop("disabled", false); + $("#amount_gen_block").css('opacity',1.0); }else{ //$('.button').disableSelection(); preset_settings = 'gui'; $("#range_block").children().prop("disabled", true); $("#range_block").css('opacity',0.5); + $("#amount_gen_block").children().prop("disabled", true); + $("#amount_gen_block").css('opacity',0.45); } saveSettings(); }); - + $( "#settings_perset_novel" ).change(function() { + + preset_settings_novel = $('#settings_perset_novel').find(":selected").text(); + temp_novel = novelai_settings[novelai_setting_names[preset_settings_novel]].temperature; + //amount_gen = koboldai_settings[koboldai_setting_names[preset_settings]].genamt; + rep_pen_novel = novelai_settings[novelai_setting_names[preset_settings_novel]].repetition_penalty; + rep_pen_size_novel = novelai_settings[novelai_setting_names[preset_settings_novel]].repetition_penalty_range; + $('#temp_novel').val(temp_novel); + $('#temp_counter_novel').html(temp_novel); + + //$('#amount_gen').val(amount_gen); + //$('#amount_gen_counter').html(amount_gen); + + $('#rep_pen_novel').val(rep_pen_novel); + $('#rep_pen_counter_novel').html(rep_pen_novel); + + $('#rep_pen_size_novel').val(rep_pen_size_novel); + $('#rep_pen_size_counter_novel').html(rep_pen_size_novel+" Tokens"); + + //$("#range_block").children().prop("disabled", false); + //$("#range_block").css('opacity',1.0); + saveSettings(); + }); + $( "#main_api" ).change(function() { + is_get_status = false; + is_get_status_novel = false; + online_status = 'no_connection'; + checkOnlineStatus(); + changeMainAPI(); + saveSettings(); + }); + function changeMainAPI(){ + if($('#main_api').find(":selected").val() == 'kobold'){ + $('#kobold_api').css("display", "block"); + $('#novel_api').css("display", "none"); + main_api = 'kobold'; + $('#max_context_block').css('display', 'block'); + $('#amount_gen_block').css('display', 'block'); + } + if($('#main_api').find(":selected").val() == 'novel'){ + $('#kobold_api').css("display", "none"); + $('#novel_api').css("display", "block"); + main_api = 'novel'; + $('#max_context_block').css('display', 'none'); + $('#amount_gen_block').css('display', 'none'); + } + } async function getUserAvatars(){ const response = await fetch("/getuseravatars", { method: "POST", @@ -1342,9 +1552,15 @@ } } + + $(document).on('input', '#temp', function() { temp = $(this).val(); - $('#temp_counter').html( $(this).val() ); + if(isInt(temp)){ + $('#temp_counter').html( $(this).val()+".00" ); + }else{ + $('#temp_counter').html( $(this).val() ); + } var tempTimer = setTimeout(saveSettings, 500); }); $(document).on('input', '#amount_gen', function() { @@ -1352,10 +1568,62 @@ $('#amount_gen_counter').html( $(this).val() ); var amountTimer = setTimeout(saveSettings, 500); }); + $(document).on('input', '#max_context', function() { + max_context = parseInt($(this).val()); + $('#max_context_counter').html( $(this).val() +' Tokens'); + var max_contextTimer = setTimeout(saveSettings, 500); + }); + $('#style_anchor').change(function() { + style_anchor = !!$('#style_anchor').prop('checked'); + saveSettings(); + }); + $('#character_anchor').change(function() { + character_anchor = !!$('#character_anchor').prop('checked'); + saveSettings(); + }); + $(document).on('input', '#rep_pen', function() { + rep_pen = $(this).val(); + if(isInt(rep_pen)){ + $('#rep_pen_counter').html( $(this).val()+".00" ); + }else{ + $('#rep_pen_counter').html( $(this).val() ); + } + var repPenTimer = setTimeout(saveSettings, 500); + }); + $(document).on('input', '#rep_pen_size', function() { + rep_pen_size = $(this).val(); + $('#rep_pen_size_counter').html( $(this).val()+" Tokens"); + var repPenSizeTimer = setTimeout(saveSettings, 500); + }); + + //Novel + $(document).on('input', '#temp_novel', function() { + temp_novel = $(this).val(); + if(isInt(temp_novel)){ + $('#temp_counter_novel').html( $(this).val()+".00" ); + }else{ + $('#temp_counter_novel').html( $(this).val() ); + } + var tempTimer_novel = setTimeout(saveSettings, 500); + }); + $(document).on('input', '#rep_pen_novel', function() { + rep_pen_novel = $(this).val(); + if(isInt(rep_pen_novel)){ + $('#rep_pen_counter_novel').html( $(this).val()+".00" ); + }else{ + $('#rep_pen_counter_novel').html( $(this).val() ); + } + var repPenTimer_novel = setTimeout(saveSettings, 500); + }); + $(document).on('input', '#rep_pen_size_novel', function() { + rep_pen_size_novel = $(this).val(); + $('#rep_pen_size_counter_novel').html( $(this).val()+" Tokens"); + var repPenSizeTimer_novel = setTimeout(saveSettings, 500); + }); //***************SETTINGS****************// /////////////////////////////////////////// - async function getSettings(){ + async function getSettings(type){//timer jQuery.ajax({ @@ -1373,12 +1641,53 @@ success: function(data){ if(data.result != 'file not find'){ settings = JSON.parse(data.settings); + if(settings.myname !== undefined){ + if(settings.myname !== ''){ + name1 = settings.myname; + $('#your_name').val(name1); + } + } + + + //Novel + if(settings.main_api != undefined){ + main_api = settings.main_api; + $("#main_api option[value="+main_api+"]").attr('selected', 'true'); + changeMainAPI(); + } + if(settings.api_key_novel != undefined){ + api_key_novel = settings.api_key_novel; + $("#api_key_novel").val(api_key_novel); + } + model_novel = settings.model_novel; + $("#model_novel_select option[value="+model_novel+"]").attr('selected', 'true'); + + novelai_setting_names = data.novelai_setting_names; + novelai_settings = data.novelai_settings; + novelai_settings.forEach(function(item, i, arr) { + + novelai_settings[i] = JSON.parse(item); + }); + var arr_holder = {}; + $("#settings_perset_novel").empty(); + novelai_setting_names.forEach(function(item, i, arr) { + arr_holder[item] = i; + $('#settings_perset_novel').append(''); + + }); + novelai_setting_names = {}; + novelai_setting_names = arr_holder; + + preset_settings_novel = settings.preset_settings_novel; + $("#settings_perset_novel option[value="+novelai_setting_names[preset_settings_novel]+"]").attr('selected', 'true'); + //Kobold koboldai_setting_names = data.koboldai_setting_names; koboldai_settings = data.koboldai_settings; koboldai_settings.forEach(function(item, i, arr) { koboldai_settings[i] = JSON.parse(item); }); var arr_holder = {}; + //$("#settings_perset").empty(); koboldai_setting_names.forEach(function(item, i, arr) { arr_holder[item] = i; $('#settings_perset').append(''); @@ -1391,15 +1700,64 @@ temp = settings.temp; amount_gen = settings.amount_gen; + if(settings.max_context !== undefined) max_context = parseInt(settings.max_context); + if(settings.anchor_order !== undefined) anchor_order = parseInt(settings.anchor_order); + if(settings.style_anchor !== undefined) style_anchor = !!settings.style_anchor; + if(settings.character_anchor !== undefined) character_anchor = !!settings.character_anchor; + rep_pen = settings.rep_pen; + rep_pen_size = settings.rep_pen_size; + + + var addZeros = ""; + if(isInt(temp)) addZeros = ".00"; $('#temp').val(temp); + $('#temp_counter').html(temp+addZeros); + + $('#style_anchor').prop('checked', style_anchor); + $('#character_anchor').prop('checked', character_anchor); + $("#anchor_order option[value="+anchor_order+"]").attr('selected', 'true'); + + $('#max_context').val(max_context); + $('#max_context_counter').html(max_context+' Tokens'); + $('#amount_gen').val(amount_gen); - $('#temp_counter').html(temp); - $('#amount_gen_counter').html(amount_gen); + $('#amount_gen_counter').html(amount_gen+' Tokens'); + + addZeros = ""; + if(isInt(rep_pen)) addZeros = ".00"; + $('#rep_pen').val(rep_pen); + $('#rep_pen_counter').html(rep_pen+addZeros); + + $('#rep_pen_size').val(rep_pen_size); + $('#rep_pen_size_counter').html(rep_pen_size+" Tokens"); + + //Novel + + temp_novel = settings.temp_novel; + rep_pen_novel = settings.rep_pen_novel; + rep_pen_size_novel = settings.rep_pen_size_novel; + + addZeros = ""; + if(isInt(temp_novel)) addZeros = ".00"; + $('#temp_novel').val(temp_novel); + $('#temp_counter_novel').html(temp_novel+addZeros); + + addZeros = ""; + if(isInt(rep_pen_novel)) addZeros = ".00"; + $('#rep_pen_novel').val(rep_pen_novel); + $('#rep_pen_counter_novel').html(rep_pen_novel+addZeros); + + $('#rep_pen_size_novel').val(rep_pen_size_novel); + $('#rep_pen_size_counter_novel').html(rep_pen_size_novel+" Tokens"); + + ////////////////////// if(preset_settings == 'gui'){ $("#settings_perset option[value=gui]").attr('selected', 'true'); $("#range_block").children().prop("disabled", true); $("#range_block").css('opacity',0.5); - + + $("#amount_gen_block").children().prop("disabled", true); + $("#amount_gen_block").css('opacity',0.45); }else{ if(typeof koboldai_setting_names[preset_settings] !== 'undefined') { @@ -1407,11 +1765,16 @@ }else{ $("#range_block").children().prop("disabled", true); $("#range_block").css('opacity',0.5); + $("#amount_gen_block").children().prop("disabled", true); + $("#amount_gen_block").css('opacity',0.45); + preset_settings = 'gui'; $("#settings_perset option[value=gui]").attr('selected', 'true'); } } + + //User user_avatar = settings.user_avatar; $('.mes').each(function(){ if($(this).attr('ch_name') == name1){ @@ -1433,17 +1796,31 @@ } - async function saveSettings(){ + async function saveSettings(type){ jQuery.ajax({ type: 'POST', url: '/savesettings', data: JSON.stringify({ + myname: name1,                      api_server: api_server, preset_settings: preset_settings, + preset_settings_novel: preset_settings_novel, user_avatar: user_avatar, temp: temp, - amount_gen: amount_gen + amount_gen: amount_gen, + max_context: max_context, + anchor_order: anchor_order, + style_anchor: style_anchor, + character_anchor: character_anchor, + main_api: main_api, + api_key_novel: api_key_novel, + rep_pen: rep_pen, + rep_pen_size: rep_pen_size, + model_novel: model_novel, + temp_novel: temp_novel, + rep_pen_novel: rep_pen_novel, + rep_pen_size_novel: rep_pen_size_novel                  }), beforeSend: function(){ @@ -1455,7 +1832,9 @@ //processData: false, success: function(data){ //online_status = data.result; - + if(type === 'change_name'){ + location.reload(); + } }, error: function (jqXHR, exception) { @@ -1488,8 +1867,195 @@ } }); }); + function isInt(value) { + return !isNaN(value) && + parseInt(Number(value)) == value && + !isNaN(parseInt(value, 10)); + } + //******************** + //***Message Editor*** + $(document).on('click', '.mes_edit', function(){ + if(this_chid !== undefined){ + if(this_edit_mes_id !== undefined){ + let mes_edited = $('#chat').children().filter('[mesid="'+this_edit_mes_id+'"]').children('.mes_block').children('.ch_name').children('.mes_edit_done'); + messageEditDone(mes_edited); + } + $(this).parent().parent().children('.mes_text').empty(); + $(this).css('display','none'); + $(this).parent().children('.mes_edit_done').css('display','inline-block'); + $(this).parent().children('.mes_edit_done').css('opacity',0.0); + $(this).parent().children('.mes_edit_cancel').css('display','inline-block'); + $(this).parent().children('.mes_edit_cancel').css('opacity',0.0); + $(this).parent().children('.mes_edit_done').transition({ + opacity: 1.0, + duration: 600, + easing: "", + complete: function() { } + }); + $(this).parent().children('.mes_edit_cancel').transition({ + opacity: 1.0, + duration: 600, + easing: "", + complete: function() { } + }); + var edit_mes_id = $(this).parent().parent().parent().attr('mesid'); + this_edit_mes_id = edit_mes_id; + + var text = chat[edit_mes_id]; + if(text.indexOf(name1+":") == 0){ + text = text.substr((name1+":").length); + this_edit_mes_chname = name1; + }else{ + this_edit_mes_chname = name2; + if(text.indexOf(name2+":") == 0){ + text = text.substr((name2+":").length); + } + } + text = text.trim(); + $(this).parent().parent().children('.mes_text').append(''); + let edit_textarea = $(this).parent().parent().children('.mes_text').children('.edit_textarea'); + edit_textarea.css('opacity',0.0); + edit_textarea.transition({ + opacity: 1.0, + duration: 0, + easing: "", + complete: function() { } + }); + edit_textarea.height(0); + edit_textarea.height(edit_textarea[0].scrollHeight); + edit_textarea.focus(); + edit_textarea[0].setSelectionRange(edit_textarea.val().length, edit_textarea.val().length); + } + }); + $(document).on('click', '.mes_edit_cancel', function(){ + //var text = $(this).parent().parent().children('.mes_text').children('.edit_textarea').val(); + var text = chat[this_edit_mes_id]; + if(text.indexOf(name1+":") == 0){ + text = text.substr((name1+":").length); + }else{ + if(text.indexOf(name2+":") == 0){ + text = text.substr((name2+":").length); + } + } + $(this).parent().parent().children('.mes_text').empty(); + $(this).css('display','none'); + $(this).parent().children('.mes_edit_done').css('display','none'); + $(this).parent().children('.mes_edit').css('display','inline-block'); + $(this).parent().parent().children('.mes_text').append(messageFormating(text,this_edit_mes_chname)); + this_edit_mes_id = undefined; + }); + $(document).on('click', '.mes_edit_done', function(){ + messageEditDone($(this)); + }); + function messageEditDone(div){ + + var text = div.parent().parent().children('.mes_text').children('.edit_textarea').val(); + //var text = chat[this_edit_mes_id]; + text = text.trim(); + chat[this_edit_mes_id] = this_edit_mes_chname+": "+text+"\n"; + div.parent().parent().children('.mes_text').empty(); + div.css('display','none'); + div.parent().children('.mes_edit_cancel').css('display','none'); + div.parent().children('.mes_edit').css('display','inline-block'); + div.parent().parent().children('.mes_text').append(messageFormating(text,this_edit_mes_chname)); + this_edit_mes_id = undefined; + saveChat(); + } + + $("#your_name_button").click(function() { + if(!is_send_press){ + name1 = $("#your_name").val(); + if(name1 === undefined || name1 == '') name1 = default_user_name; + console.log(name1); + saveSettings('change_name'); + + } + }); + //************************************************************ + //************************Novel.AI**************************** + //************************************************************ + async function getStatusNovel(){ + if(is_get_status_novel){ + + var data = {key:api_key_novel}; + + jQuery.ajax({ + type: 'POST', // + url: '/getstatus_novelai', // + data: JSON.stringify(data), + beforeSend: function(){ + //$('#create_button').attr('value','Creating...'); + }, + cache: false, + dataType: "json", + contentType: "application/json", + success: function(data){ + + + if(data.error != true){ + //var settings2 = JSON.parse(data); + //const getData = await response.json(); + novel_tier = data.tier; + if(novel_tier == undefined){ + online_status = 'no_connection'; + } + if(novel_tier === 0){ + online_status = "Paper"; + } + if(novel_tier === 1){ + online_status = "Tablet"; + } + if(novel_tier === 2){ + online_status = "Scroll"; + } + if(novel_tier === 3){ + online_status = "Opus"; + } + } + resultCheckStatusNovel(); + }, + error: function (jqXHR, exception) { + online_status = 'no_connection'; + console.log(exception); + console.log(jqXHR); + resultCheckStatusNovel(); + } + }); + }else{ + if(is_get_status != true){ + online_status = 'no_connection'; + } + } + } + $( "#api_button_novel" ).click(function() { + if($('#api_key_novel').val() != ''){ + $("#api_loading_novel").css("display", 'inline-block'); + $("#api_button_novel").css("display", 'none'); + api_key_novel = $('#api_key_novel').val(); + api_key_novel = $.trim(api_key_novel); + //console.log("1: "+api_server); + saveSettings(); + is_get_status_novel = true; + is_api_button_press_novel = true; + } + }); + function resultCheckStatusNovel(){ + is_api_button_press_novel = false; + checkOnlineStatus(); + $("#api_loading_novel").css("display", 'none'); + $("#api_button_novel").css("display", 'inline-block'); + } + $( "#model_novel_select" ).change(function() { + model_novel = $('#model_novel_select').find(":selected").val(); + saveSettings(); + }); + $( "#anchor_order" ).change(function() { + anchor_order = parseInt($('#anchor_order').find(":selected").val()); + saveSettings(); + }); }); +      Tavern.AI @@ -1511,11 +2077,16 @@
+ + +
TavernAI is being developed with love and care on a voluntary basis. If you like the project and want to support it, your donation would make a huge impact! Thank you!
-

Ethereum, USDT

- - 0x975E5C91042ce8168B3d37b17F99949c5eFB3Dfe +

Ethereum or USDT

+ + +
0x975E5C91042ce8168B3d37b17F99949c5eFB3Dfe
+
@@ -1534,7 +2105,6 @@
-

API

- -
-

API url

Example: http://127.0.0.1:5000/api
- - - -
-
-
No connection...
-
-

Preset settings

Selecting settings (?)
- + + -
-

Temperature

select
- -

Amount generation

select
- +
+
+
+ +

API url

Example: http://127.0.0.1:5000/api
+ + + +
+
+
No connection...
+
+

Preset settings

Selecting settings (?)
+ +
+

Temperature

select
+ + +

Repetition Penalty

select
+ +

Repetition Penalty Range

select
+ +
-
+ +
+

Your Avatar

+
+

Name

+ + +
+
+
+

Pro Settings

+
+

Amount generation

select
+ +
+
+

Context Size

select
+ +
+

Anchors Order

Selecting Anchors Order (?)
+ +
+

Character Anchor

+

Style Anchor

+ +
+
diff --git a/public/notes/1.png b/public/notes/1.png new file mode 100644 index 000000000..2a7700325 Binary files /dev/null and b/public/notes/1.png differ diff --git a/public/notes/2.png b/public/notes/2.png new file mode 100644 index 000000000..169cba49e Binary files /dev/null and b/public/notes/2.png differ diff --git a/public/notes/4.html b/public/notes/4.html index abdee7b65..2e2d4c8b8 100644 --- a/public/notes/4.html +++ b/public/notes/4.html @@ -1,6 +1,6 @@ - Preset settings + KoboldAI Settings @@ -8,16 +8,21 @@
-

Preset settings

+

KoboldAI Settings

Standard KoboldAI settings files are used here. To add your own settings, simply add the file .settings in TavernAI\public\KoboldAI Settings -

Important: Temporarily, at the moment, the context will always be 2048 tokens, regardless of any settings.

Temperature

Value from 0.1 to 2.0. Lower value - the answers are more logical, but less creative. Higher value - the answers are more creative, but less logical.

+

Repetition penalty

+

Repetition penalty is responsible for the penalty of repeated words. If the character is fixated on something or repeats the same phrase, then increasing this parameter will fix it. It is not recommended to increase this parameter too much for the chat format, as it may break this format. The standard value for chat is approximately 1.0 - 1.05

+

Repetition penalty range

+

The range of influence of Repetition penalty in tokens.


+

Pro settings

Amount generation

The maximum amount of tokens that a AI will generate to respond. One word is approximately 3-4 tokens. The larger the parameter value, the longer the generation time takes.

-

User Avatar

-

Images can be added in TavernAI\public\User Avatars

+

Context size

+

How much will the AI remember. Context size also affects the speed of generation.

+Important: The settings of Context size in TavernAI GUI override any other settings for KoboldAI(from KoboldAI GUI and from preset files)

diff --git a/public/notes/6.html b/public/notes/6.html new file mode 100644 index 000000000..cb51b76c8 --- /dev/null +++ b/public/notes/6.html @@ -0,0 +1,28 @@ + + + NovelAI api key + + + + + +
+
+

Finding your NAI API key

+

To get a NovelAI API key, follow these instructions:

+ + 1. Login to NovelAI through the website.

+ + 2. Create a new story, or open an existing story.

+ + 3. Open the Network Tools on your web browser. (For Chrome or Firefox, you do this by pressing Ctrl+Shift+I, then switching to the Network tab.)

+ + 4. Generate something. You should see two requests to api.novelai.net/ai/generate-stream, which might look something like this:

+

+ 5. Select the second request, then in the Headers tab of the inspection panel, scroll down to the very bottom. Look for a header called Authorization:

+

+ The long string (after "Bearer", not including it) is your API key. +
+
+ + diff --git a/public/notes/7.html b/public/notes/7.html new file mode 100644 index 000000000..b332ad51d --- /dev/null +++ b/public/notes/7.html @@ -0,0 +1,23 @@ + + + NovelAI settings + + + + + +
+
+

NovelAI settings

+

The files with the settings are here (TavernAI\public\NovelAI Settings) You also can add own settings files. +

+

Temperature

+

Value from 0.1 to 2.0. Lower value - the answers are more logical, but less creative. Higher value - the answers are more creative, but less logical.

+

Repetition penalty

+

Repetition penalty is responsible for the penalty of repeated words. If the character is fixated on something or repeats the same phrase, then increasing this parameter will fix it. It is not recommended to increase this parameter too much for the chat format, as it may break this format. The standard value for chat is approximately 1.0 - 1.05

+

Repetition penalty range

+

The range of influence of Repetition penalty in tokens.

+
+
+ + diff --git a/public/notes/8.html b/public/notes/8.html new file mode 100644 index 000000000..3cd4a4019 --- /dev/null +++ b/public/notes/8.html @@ -0,0 +1,16 @@ + + + NovelAI Models + + + + + +
+
+

NovelAI Models

+

If your subscribe tier is Paper, Tablet or Scroll use only Euterpe model otherwise you can not get an answer from NovelAI api.

+
+
+ + diff --git a/public/notes/9.html b/public/notes/9.html new file mode 100644 index 000000000..22ba82512 --- /dev/null +++ b/public/notes/9.html @@ -0,0 +1,20 @@ + + + Anchors + + + + + +
+
+

Anchors

+

Anchors are used to increase the length of messages. There are two types of anchors: Character Anchor and Style Anchor

+

Character Anchor - affects the character played by the AI by motivating him to write longer messages. Looks like [Alexa talks a lot with descriptions]

+

Style Anchor - affects all AI model, motivating AI to write longer messages. Looks like [Writing style: very long messages]

+

The order of anchors sets the location of anchors in the promt, the first anchor in the order is much higher and has less influence than the one that follows it.

+

To disable anchors, you just need to remove the checkboxes.

+
+
+ + diff --git a/public/settings.json b/public/settings.json index 97eb3613f..a485afdd5 100644 --- a/public/settings.json +++ b/public/settings.json @@ -1 +1 @@ -{"api_server":"http://localhost:5000/api","preset_settings":"Lancer-OPT-2.7B-Erebus","user_avatar":"you1.png","temp":0.8,"amount_gen":90} \ No newline at end of file +{"myname":"You","api_server":"","preset_settings":"gui","preset_settings_novel":"Classic-Euterpe","user_avatar":"legat.png","temp":0.8,"amount_gen":90,"max_context":2048,"anchor_order":0,"style_anchor":true,"character_anchor":true,"main_api":"kobold","api_key_novel":"","rep_pen":1.02,"rep_pen_size":256,"model_novel":"euterpe-v2","temp_novel":1.11,"rep_pen_novel":1.11,"rep_pen_size_novel":320} \ No newline at end of file diff --git a/public/style.css b/public/style.css index c13356897..b91c2f9ca 100644 --- a/public/style.css +++ b/public/style.css @@ -308,7 +308,7 @@ textarea{ } #personality_textarea{ width: 92%; - height: 100px; + height: 65px; margin-top: 0px; } #character_name_pole{ @@ -424,11 +424,21 @@ input[type=submit] { cursor: pointer; color:#ffffffaa; } +#api_button_novel{ + cursor: pointer; + color:#ffffffaa; +} #api_loading{ width: 25px; height: 25px; display: none; +} +#api_loading_novel{ + width: 25px; + height: 25px; + display: none; + } #rm_characters_block{ display: block; @@ -821,6 +831,23 @@ input[type=submit] { margin-left: 4px; display: inline-block; } +#online_status3{ + opacity: 0.5; + margin-top: 2px; + margin-left: 10px; + margin-bottom: 30px; +} +#online_status_indicator3{ + border-radius: 7px; + width: 14px; + height: 14px; + background-color: red; + display: inline-block; +} +#online_status_text3{ + margin-left: 4px; + display: inline-block; +} .del_checkbox{ display: none; opacity: 0.5; @@ -862,6 +889,15 @@ select { box-shadow: 0 0 2px rgba(200,200,200,0.5); background-color:#13152c; } + +.option_select_right_menu{ + width:284px; + margin-left: 10px; + margin-bottom: 35px; + color: #ffffff9d; + box-shadow: 0 0 2px rgba(200,200,200,0.5); + background-color:#13152c; +} #user_avatar_block{ margin-left: 6px; display: grid; @@ -891,6 +927,21 @@ select { #amount_gen_counter{ margin-bottom: 0px; } +#max_context{ + margin-left: 10px; + margin-bottom: 20px; +} +#max_context_counter{ + margin-bottom: 0px; +} +#range_block input{ + margin-left: 10px; + margin-bottom: 20px; +} +#range_block_novel input{ + margin-left: 10px; + margin-bottom: 20px; +} input[type="range"] { -webkit-appearance: none; margin-right: 15px; @@ -922,7 +973,7 @@ input[type="range"] { #tips_popup{ width:500px; - height: 430px; + height: 600px; position: absolute; z-index: 2060; background-color: blue; @@ -931,7 +982,7 @@ input[type="range"] { left: 0; right: 0; text-align: center; - margin-top: 20vh; + margin-top: 15vh; box-shadow: 5px 5px -5px -5px rgba(200,200,200,0.1); padding: 4px; background: #191b31EE; @@ -946,4 +997,108 @@ input[type="range"] { z-index: 2055; background-color: #00000066; } +.mes_edit{ + display: inline-block; + float:right; + //right:8px; + cursor:pointer; + margin-right: 4px; + opacity:0.07; +} +.mes_edit_done{ + display: none; + float:right; + right:8px; + cursor:pointer; + margin-right: 15px; + opacity:0.5; +} +.mes_edit_done img{ + width: 23px; + height: 23px; +} +.mes_edit_cancel{ + display: none; + float:right; + //right:8px; + margin-right: 4px; + cursor:pointer; + opacity:0.5; +} +.mes_edit_cancel img{ + width: 23px; + height: 23px; +} +.edit_textarea{ + padding: 0px; + margin: 0px; + border: none; + border-color: transparent; + outline: none; + box-shadow: none; + background-color: transparent; +} +#your_name{ + outline: none; + //box-shadow: 0 2px 0px rgba(255, 255, 255, 0.1); + box-shadow: 0 0px 0px rgba(255, 255, 255, 0.0); + border: none; + background: transparent; + border: 0; + border-bottom: 1px dashed rgba(255, 255, 255, 0.12); +} +#your_name_button { + opacity: 0.5; + margin-left: 10px; + cursor: pointer; +} +#form_change_name{ + margin-bottom: 15px; +} +.checkbox{ + display: block; +} +label.checkbox input[type="checkbox"] {display:none;} +label.checkbox span { + display:inline-block; + border:1px solid #BBBBBB33; + border-radius:3px; + width:20px; + height:20px; + background:rgba(19,21,44,0.75); + vertical-align:middle; + margin:0px; + position: relative; + transition:width 0.1s, height 0.1s, margin 0.1s; + +} +label.checkbox :checked + span { + background:rgba(19,21,44,0.75); + width:20px; + height:20px; + margin: 0px; +} +label.checkbox :checked + span:after { + content: '\2714'; + font-size: 18px; + position: absolute; + top: -3px; + left: 2px; + color: #99a1a7; +} +#anchor_order{ + width:284px; + margin-left: 10px; + margin-bottom: 15px; + color: #ffffff9d; + box-shadow: 0 0 2px rgba(200,200,200,0.5); + background-color:#13152c; +} +#anchor_checkbox{ + margin-left: 10px; + float: left; + display: grid; + grid-template-rows: 30px auto; + grid-template-columns: auto auto; +} diff --git a/server.js b/server.js index 98837c7f0..c15029888 100644 --- a/server.js +++ b/server.js @@ -10,8 +10,11 @@ var client = new Client(); var api_server = "";//"http://127.0.0.1:5000"; var server_port = 8000; +var api_novelai = "https://api.novelai.net"; + var response_get_story; var response_generate; +var response_generate_novel; var request_promt; var response_promt; var characters = {}; @@ -20,6 +23,8 @@ var response_create; var response_edit; var response_dw_bg; var response_getstatus; +var response_getstatus_novel; +var api_key_novel; const jsonParser = express.json(); const urlencodedParser = express.urlencoded({extended: false}); @@ -86,16 +91,16 @@ app.post("/generate", jsonParser, function(request, response_generate = response } if(response.statusCode == 422){ console.log('Validation error'); - response_getstatus.send({error: true}); + response_generate.send({error: true}); } if(response.statusCode == 501 || response.statusCode == 503 || response.statusCode == 507){ console.log(data); - response_getstatus.send({error: true}); + response_generate.send({error: true}); } }).on('error', function (err) { //console.log(''); //console.log('something went wrong on the request', err.request.options); - response_getstatus.send({error: true}); + response_generate.send({error: true}); }); }); app.post("/savechat", jsonParser, function(request, response){ @@ -396,7 +401,73 @@ app.post("/savesettings", jsonParser, function(request, response){ }); }); -app.post("/getsettings", jsonParser, function(request, response){ +app.post('/getsettings', jsonParser, (request, response) => { //Wintermute's code + const koboldai_settings = []; + const koboldai_setting_names = []; + const novelai_settings = []; + const novelai_setting_names = []; + const settings = fs.readFileSync('public/settings.json', 'utf8', (err, data) => { + if (err) return response.sendStatus(500); + + return data; + }); + //Kobold + const files = fs + .readdirSync('public/KoboldAI Settings') + .sort( + (a, b) => + new Date(fs.statSync(`public/KoboldAI Settings/${b}`).mtime) - + new Date(fs.statSync(`public/KoboldAI Settings/${a}`).mtime) + ); + + files.forEach(item => { + const file = fs.readFileSync( + `public/KoboldAI Settings/${item}`, + 'utf8', + (err, data) => { + if (err) return response.sendStatus(500) + + return data; + } + ); + koboldai_settings.push(file); + koboldai_setting_names.push(item.replace(/\.[^/.]+$/, '')); + }); + + //Novel + const files2 = fs + .readdirSync('public/NovelAI Settings') + .sort( + (a, b) => + new Date(fs.statSync(`public/NovelAI Settings/${b}`).mtime) - + new Date(fs.statSync(`public/NovelAI Settings/${a}`).mtime) + ); + + files2.forEach(item => { + const file2 = fs.readFileSync( + `public/NovelAI Settings/${item}`, + 'utf8', + (err, data) => { + if (err) return response.sendStatus(500); + + return data; + } + ); + + novelai_settings.push(file2); + novelai_setting_names.push(item.replace(/\.[^/.]+$/, '')); + }); + + response.send({ + settings, + koboldai_settings, + koboldai_setting_names, + novelai_settings, + novelai_setting_names + }); +}); + +app.post("/getsettings2", jsonParser, function(request, response){//Elder var koboldai_settings = []; var koboldai_setting_names = []; fs.stat('public/settings.json', function(err, stat) { @@ -487,6 +558,109 @@ function getDirectories(path) { return new Date(fs.statSync(path + '/' + a).mtime) - new Date(fs.statSync(path + '/' + b).mtime); }).reverse(); } + +//***********Novel.ai API + +app.post("/getstatus_novelai", jsonParser, function(request, response_getstatus_novel =response){ + if(!request.body) return response_generate.sendStatus(400); +    api_key_novel = request.body.key; + var data = {}; + var args = { + data: data, + + headers: { "Content-Type": "application/json", "Authorization": "Bearer "+api_key_novel} + }; + client.get(api_novelai+"/user/subscription",args, function (data, response) { + if(response.statusCode == 200){ + //console.log(data); + response_getstatus_novel.send(data);//data); + } + if(response.statusCode == 401){ + console.log('Access Token is incorrect.'); + response_getstatus_novel.send({error: true}); + } + if(response.statusCode == 500 || response.statusCode == 501 || response.statusCode == 501 || response.statusCode == 503 || response.statusCode == 507){ + console.log(data); + response_getstatus_novel.send({error: true}); + } + }).on('error', function (err) { + //console.log(''); + //console.log('something went wrong on the request', err.request.options); + response_getstatus_novel.send({error: true}); + }); +}); + + + +app.post("/generate_novelai", jsonParser, function(request, response_generate_novel = response){ + if(!request.body) return response_generate_novel.sendStatus(400); + + console.log(request.body); + var data = { + "input": request.body.input, + "model": request.body.model, + "parameters": { + "use_string": request.body.use_string, + "temperature": request.body.temperature, + "max_length": request.body.max_length, + "min_length": request.body.min_length, + "tail_free_sampling": request.body.tail_free_sampling, + "repetition_penalty": request.body.repetition_penalty, + "repetition_penalty_range": request.body.repetition_penalty_range, + "repetition_penalty_frequency": request.body.repetition_penalty_frequency, + "repetition_penalty_presence": request.body.repetition_penalty_presence, + //"stop_sequences": {{187}}, + //bad_words_ids = {{50256}, {0}, {1}}; + //generate_until_sentence = true; + "use_cache": request.body.use_cache, + //use_string = true; + "return_full_text": request.body.return_full_text, + "prefix": request.body.prefix, + "order": request.body.order + } +}; + + var args = { + data: data, + + headers: { "Content-Type": "application/json", "Authorization": "Bearer "+api_key_novel} + }; + client.post(api_novelai+"/ai/generate",args, function (data, response) { + if(response.statusCode == 201){ + console.log(data); + response_generate_novel.send(data); + } + if(response.statusCode == 400){ + console.log('Validation error'); + response_generate_novel.send({error: true}); + } + if(response.statusCode == 401){ + console.log('Access Token is incorrect'); + response_generate_novel.send({error: true}); + } + if(response.statusCode == 402){ + console.log('An active subscription is required to access this endpoint'); + response_generate_novel.send({error: true}); + } + if(response.statusCode == 500 || response.statusCode == 409){ + console.log(data); + response_generate_novel.send({error: true}); + } + }).on('error', function (err) { + //console.log(''); + //console.log('something went wrong on the request', err.request.options); + response_getstatus.send({error: true}); + }); +}); + + + + + + + + + app.listen(server_port, function() { console.log('Server started: http://127.0.0.1:'+server_port);