This commit is contained in:
SillyLossy
2023-03-21 17:17:05 +02:00
2 changed files with 40 additions and 17 deletions

View File

@@ -88,6 +88,7 @@ export {
nai_settings, nai_settings,
token, token,
is_send_press, is_send_press,
api_server_textgenerationwebui,
default_avatar, default_avatar,
system_message_types, system_message_types,
talkativeness_default, talkativeness_default,
@@ -271,8 +272,7 @@ let style_anchor = true;
let character_anchor = true; let character_anchor = true;
let extension_prompts = {}; let extension_prompts = {};
var main_api = "kobold"; var main_api;// = "kobold";
//novel settings //novel settings
let novel_tier; let novel_tier;
let novelai_settings; let novelai_settings;
@@ -1560,7 +1560,7 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
// regenerate with character speech reenforced // regenerate with character speech reenforced
// to make sure we leave on swipe type while also adding the name2 appendage // to make sure we leave on swipe type while also adding the name2 appendage
const newType = type == "swipe" ? "swipe" : "force_name2"; const newType = type == "swipe" ? "swipe" : "force_name2";
Generate(newType, automatic_trigger=false, force_name2=true); Generate(newType, automatic_trigger = false, force_name2 = true);
} }
} else { } else {

View File

@@ -9,6 +9,7 @@ import {
main_api, main_api,
api_server, api_server,
nai_settings, nai_settings,
api_server_textgenerationwebui,
is_send_press, is_send_press,
} from "../script.js"; } from "../script.js";
@@ -39,6 +40,10 @@ var create_save_mes_example;
var count_tokens; var count_tokens;
var perm_tokens; var perm_tokens;
var connection_made = false;
var retry_delay = 100;
var RA_AC_retries = 1;
const observerConfig = { childList: true, subtree: true }; const observerConfig = { childList: true, subtree: true };
const observer = new MutationObserver(function (mutations) { 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_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; $("#send_but").css("display", "none"); //send button is hidden when not connected;
$("#API-status-top").addClass("redOverlayGlow"); $("#API-status-top").addClass("redOverlayGlow");
connection_made = false;
} else { } else {
if (online_status !== undefined && online_status !== "no_connection") { if (online_status !== undefined && online_status !== "no_connection") {
$("#send_textarea").attr("placeholder", "Type a message..."); //on connect, placeholder tells user to type message $("#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 $("#send_form").css("background-color", "rgba(0,0,0,0.7)"); //on connect, form BG changes to transprent black
$("#API-status-top").removeClass("redOverlayGlow"); $("#API-status-top").removeClass("redOverlayGlow");
connection_made = true;
if (!is_send_press && !(selected_group && is_group_generating)) { if (!is_send_press && !(selected_group && is_group_generating)) {
$("#send_but").css("display", "inline"); //on connect, send button shows $("#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) //Auto-connect to API (when set to kobold, API URL exists, and auto_connect is true)
function RA_autoconnect() { function RA_autoconnect() {
console.log(main_api); if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) {
if (typeof online_status !== 'undefined' && (api_server !== '' || nai_settings.api_key_novel !== '')) { switch (main_api) {
if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) { case 'kobold':
if (isUrlOrAPIKey(api_server) && main_api === "kobold") { if (api_server && isUrlOrAPIKey(api_server)) {
$("#api_button").click(); $("#api_button").click();
} retry_delay = 100;
if (main_api === "novel") { RA_AC_retries = 1;
$("#api_button_novel").click(); }
} break;
if (isUrlOrAPIKey(api_server) && main_api === "textgenerationwebui") { case 'novel':
$("#api_button_textgenerationwebui").click(); 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);
} }
} }