diff --git a/public/script.js b/public/script.js index 2bfcc4e09..60c40d9f8 100644 --- a/public/script.js +++ b/public/script.js @@ -76,6 +76,7 @@ export { api_key_novel, token, is_send_press, + api_server_textgenerationwebui, default_avatar, system_message_types, talkativeness_default, @@ -269,7 +270,7 @@ var style_anchor = true; var character_anchor = true; let extension_prompts = {}; -var main_api = "kobold"; +var main_api;// = "kobold"; //novel settings var temp_novel = 0.5; var rep_pen_novel = 1; @@ -1564,7 +1565,7 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs"). // regenerate with character speech reenforced // to make sure we leave on swipe type while also adding the name2 appendage const newType = type == "swipe" ? "swipe" : "force_name2"; - Generate(newType, automatic_trigger=false, force_name2=true); + Generate(newType, automatic_trigger = false, force_name2 = true); } } else { diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 9698a7080..0af6641fd 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -9,6 +9,7 @@ import { main_api, api_server, api_key_novel, + api_server_textgenerationwebui, is_send_press, } from "../script.js"; @@ -39,6 +40,10 @@ var create_save_mes_example; var count_tokens; var perm_tokens; +var connection_made = false; +var retry_delay = 100; +var RA_AC_retries = 1; + const observerConfig = { childList: true, subtree: true }; const observer = new MutationObserver(function (mutations) { @@ -188,11 +193,13 @@ function RA_checkOnlineStatus() { $("#send_form").css("background-color", "rgba(100,0,0,0.7)"); //entire input form area is red when not connected $("#send_but").css("display", "none"); //send button is hidden when not connected; $("#API-status-top").addClass("redOverlayGlow"); + connection_made = false; } else { if (online_status !== undefined && online_status !== "no_connection") { $("#send_textarea").attr("placeholder", "Type a message..."); //on connect, placeholder tells user to type message $("#send_form").css("background-color", "rgba(0,0,0,0.7)"); //on connect, form BG changes to transprent black $("#API-status-top").removeClass("redOverlayGlow"); + connection_made = true; if (!is_send_press && !(selected_group && is_group_generating)) { $("#send_but").css("display", "inline"); //on connect, send button shows @@ -203,21 +210,37 @@ function RA_checkOnlineStatus() { //Auto-connect to API (when set to kobold, API URL exists, and auto_connect is true) function RA_autoconnect() { - console.log(main_api); - if (typeof online_status !== 'undefined' && (api_server !== '' || api_key_novel !== '')) { - if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) { - if (isUrlOrAPIKey(api_server) && main_api === "kobold") { - $("#api_button").click(); - } - if (main_api === "novel") { - $("#api_button_novel").click(); - } - if (isUrlOrAPIKey(api_server) && main_api === "textgenerationwebui") { - $("#api_button_textgenerationwebui").click(); - } + if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) { + switch (main_api) { + case 'kobold': + if (api_server && isUrlOrAPIKey(api_server)) { + $("#api_button").click(); + retry_delay = 100; + RA_AC_retries = 1; + } + break; + case 'novel': + if (api_key_novel) { + $("#api_button_novel").click(); + retry_delay = 100; + RA_AC_retries = 1; + } + break; + case 'textgenerationwebui': + if (api_server_textgenerationwebui && isUrlOrAPIKey(api_server_textgenerationwebuiapi)) { + $("#api_button_textgenerationwebui").click(); + retry_delay = 100; + RA_AC_retries = 1; + } + break; + } + + if (!connection_made) { + setTimeout(RA_autoconnect, retry_delay); + RA_AC_retries++; + retry_delay = Math.min(retry_delay * 2, 30000); // double retry delay up to to 30 secs + console.log('connection attempts: ' + RA_AC_retries + ' delay: ' + (retry_delay / 1000) + 's'); } - } else { - setTimeout(RA_autoconnect, 100); } }