diff --git a/public/index.html b/public/index.html index 06596b583..bc81dc949 100644 --- a/public/index.html +++ b/public/index.html @@ -156,6 +156,7 @@ var online_status = 'no_connection'; var api_server = ""; + var api_server_textgenerationwebui = ""; //var interval_timer = setInterval(getStatus, 2000); var interval_timer_novel = setInterval(getStatusNovel, 3000); const groupAutoModeInterval = setInterval(groupChatAutoModeWorker, 5000); @@ -193,6 +194,16 @@ var rep_pen = 1; var rep_pen_size = 100; + var textgenerationwebui_settings = { + temp: 0.5, + top_p: 0.9, + top_k: 0, + typical_p: 1, + rep_pen: 1.1, + rep_pen_size: 0, + penalty_alpha: 0, + } + var is_pygmalion = false; var tokens_already_generated = 0; var message_already_generated = ''; @@ -353,6 +364,8 @@ $("#online_status_text2").html(online_status); $("#online_status_indicator3").css("background-color", "green"); $("#online_status_text3").html(online_status); + $("#online_status_indicator4").css("background-color", "green"); + $("#online_status_text4").html(online_status); } } async function getLastVersion(){ @@ -394,7 +407,8 @@ type: 'POST', // url: '/getstatus', // data: JSON.stringify({ -                      api_server: api_server +                      api_server: (main_api == "kobold" ? api_server : api_server_textgenerationwebui), +                      main_api: main_api,                  }), beforeSend: function(){ if(is_api_button_press){ @@ -446,6 +460,8 @@ checkOnlineStatus(); $("#api_loading").css("display", 'none'); $("#api_button").css("display", 'inline-block'); + $("#api_loading_textgenerationwebui").css("display", 'none'); + $("#api_button_textgenerationwebui").css("display", 'inline-block'); } async function getSoftPromptsList() { @@ -1433,38 +1449,36 @@ finalPromt = worldInfoBefore+storyString+worldInfoAfter+extension_prompt+mesExmString+mesSendString+generatedPromtCache+promptBias; finalPromt = finalPromt.replace(/\r/gm, ''); + //if we aren't using the kobold GUI settings... + if (main_api == 'textgenerationwebui' || main_api == 'kobold' && preset_settings != 'gui') { + var this_settings = koboldai_settings[koboldai_setting_names[preset_settings]]; + + 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); // otherwise, make as much as the max amount request. + } + } + 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 + } + else{ + this_amount_gen = tokens_cycle_count; // otherwise make the standard cycle amont (frist 50, and 30 after that) + } + } + } + } + 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 we aren't using the kobold GUI settings... + if(preset_settings != 'gui'){ - var this_settings = koboldai_settings[koboldai_setting_names[preset_settings]]; - 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); // 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; // 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, @@ -1490,6 +1504,35 @@ }; } } + + if(main_api == 'textgenerationwebui'){ + const doSample = textgenerationwebui_settings.penalty_alpha == 0; + var generate_data = { + data: [ + finalPromt, + this_amount_gen, // min_length + doSample, // do_sample + textgenerationwebui_settings.temp, // temperature + textgenerationwebui_settings.top_p, // top_p + textgenerationwebui_settings.typical_p, // typical_p + textgenerationwebui_settings.rep_pen, // repetition_penalty + textgenerationwebui_settings.top_k, // top_k + 0, // min_length + textgenerationwebui_settings.rep_pen_size, // no_repeat_ngram_size + 1, // num_beams + textgenerationwebui_settings.penalty_alpha, // penalty_alpha + 1, // length_penalty + false, // early_stopping + name1, // name1 + name2, // name2 + "", // Context + true, // stop at newline + 1300, // Maximum prompt size in tokens + 1, // num attempts + ] + }; + } + if(main_api == 'novel'){ var this_settings = novelai_settings[novelai_setting_names[preset_settings_novel]]; generate_data = {"input": finalPromt, @@ -1516,8 +1559,9 @@ var generate_url = ''; if(main_api == 'kobold'){ generate_url = '/generate'; - } - if(main_api == 'novel'){ + } else if(main_api == 'textgenerationwebui') { + generate_url = '/generate_textgenerationwebui'; + } else if(main_api == 'novel'){ generate_url = '/generate_novelai'; } jQuery.ajax({ @@ -1537,14 +1581,21 @@ //console.log('Tokens requested in total: '+tokens_already_generated); //$("#send_textarea").focus(); //$("#send_textarea").removeAttr('disabled'); - is_send_press = false; - if(data.error != true){ + is_send_press = false; + if(!data.error) { //const getData = await response.json(); + var getMessage = ""; if(main_api == 'kobold'){ - var getMessage = data.results[0].text; - } - if(main_api == 'novel'){ - var getMessage = data.output; + getMessage = data.results[0].text; + } else if (main_api == 'textgenerationwebui') { + getMessage = data.data[0]; + if (getMessage == null) { + runGenerate(""); + return; + } + getMessage = getMessage.substring(finalPromt.length); + } else if(main_api == 'novel'){ + getMessage = data.output; } //Pygmalion run again // to make it continue generating so long as it's under max_amount and hasn't signaled @@ -2970,6 +3021,7 @@ api_server = api_server+"/api"; } //console.log("2: "+api_server); + main_api = "kobold"; saveSettings(); is_get_status = true; is_api_button_press = true; @@ -2979,8 +3031,27 @@ } }); - - $(document).on('click', function(event) { // this makes the input bar's option menu disappear when clicked away from + + $( "#api_button_textgenerationwebui" ).click(function() { + if($('#textgenerationwebui_api_url_text').val() != ''){ + $("#api_loading_textgenerationwebui").css("display", 'inline-block'); + $("#api_button_textgenerationwebui").css("display", 'none'); + api_server_textgenerationwebui = $('#textgenerationwebui_api_url_text').val(); + api_server_textgenerationwebui = $.trim(api_server_textgenerationwebui); + if(api_server_textgenerationwebui.substr(api_server_textgenerationwebui.length-1,1) == "/"){ + api_server_textgenerationwebui = api_server_textgenerationwebui.substr(0,api_server_textgenerationwebui.length-1); + } + //console.log("2: "+api_server_textgenerationwebui); + main_api = "textgenerationwebui"; + saveSettings(); + is_get_status = true; + is_api_button_press = true; + getStatus(); + } + }); + + + $( "body" ).click(function() { if($("#options").css('opacity') == 1.0){ $('#options').transition({ opacity: 0.0, @@ -3231,14 +3302,26 @@ if($('#main_api').find(":selected").val() == 'kobold'){ $('#kobold_api').css("display", "block"); $('#novel_api').css("display", "none"); + $('#textgenerationwebui_api').css("display", "none"); main_api = 'kobold'; $('#max_context_block').css('display', 'block'); $('#amount_gen_block').css('display', 'block'); $('#softprompt_block').css('display', 'block'); } + if($('#main_api').find(":selected").val() == 'textgenerationwebui'){ + $('#kobold_api').css("display", "none"); + $('#novel_api').css("display", "none"); + $('#textgenerationwebui_api').css("display", "block"); + main_api = 'textgenerationwebui'; + $('#max_context_block').css('display', 'block'); + $('#amount_gen_block').css('display', 'block'); + $('#softprompt_block').css('display', 'block'); + } + if($('#main_api').find(":selected").val() == 'novel'){ $('#kobold_api').css("display", "none"); $('#novel_api').css("display", "block"); + $('#textgenerationwebui_api').css("display", "none"); main_api = 'novel'; $('#max_context_block').css('display', 'none'); $('#amount_gen_block').css('display', 'none'); @@ -3285,6 +3368,21 @@ highlightSelectedAvatar(); } + for (var i of ["temp", "rep_pen", "rep_pen_size", "top_k", "top_p", "typical_p", "penalty_alpha"]) { + $('#' + i + '_textgenerationwebui').attr('x-setting-id', i); + $(document).on('input', '#' + i + '_textgenerationwebui', function() { + var i = $(this).attr('x-setting-id'); + var val = $(this).val(); + if(isInt(val)){ + $('#' + i + '_counter_textgenerationwebui').html( $(this).val()+".00" ); + }else{ + $('#' + i + '_counter_textgenerationwebui').html( $(this).val() ); + } + textgenerationwebui_settings[i] = parseFloat(val); + setTimeout(saveSettings, 500); + }); + } + $(document).on('input', '#temp', function() { temp = $(this).val(); if(isInt(temp)){ @@ -3453,6 +3551,9 @@ preset_settings = settings.preset_settings; //Load AI model config settings (temp, context length, anchors, and anchor order) + + textgenerationwebui_settings = settings.textgenerationwebui_settings || textgenerationwebui_settings; + temp = settings.temp; amount_gen = settings.amount_gen; if(settings.max_context !== undefined) max_context = parseInt(settings.max_context); @@ -3589,8 +3690,18 @@ active_character = settings.active_character; } } - } + api_server_textgenerationwebui = settings.api_server_textgenerationwebui; + $("#textgenerationwebui_api_url_text").val(api_server_textgenerationwebui); + + + for (var i of ["temp", "rep_pen", "rep_pen_size", "top_k", "top_p", "typical_p", "penalty_alpha"]) { + $("#" + i + "_textgenerationwebui") + .val(textgenerationwebui_settings[i]); + $("#" + i + "_counter_textgenerationwebui") + .html(textgenerationwebui_settings[i]); + } + } if(!is_checked_colab) isColab(); }, error: function (jqXHR, exception) { @@ -3599,8 +3710,8 @@ } }); - } + async function saveSettings(type){ //console.log('saveSettings() -- pinging server to save settings.'); jQuery.ajax({ @@ -3609,6 +3720,7 @@ data: JSON.stringify({ username: name1,                      api_server: api_server, +                      api_server_textgenerationwebui: api_server_textgenerationwebui, preset_settings: preset_settings, preset_settings_novel: preset_settings_novel, user_avatar: user_avatar, @@ -3631,7 +3743,8 @@ world_info: world_info, world_info_depth: world_info_depth, world_info_budget: world_info_budget, - active_character: active_character + active_character: active_character, + textgenerationwebui_settings: textgenerationwebui_settings,                  }), beforeSend: function(){ //console.log('saveSettings() -- active_character -- '+active_character); @@ -5019,6 +5132,7 @@

API

@@ -5076,6 +5190,39 @@ + +