added automatic recovery if bad config is loaded, will restore to known good config

This commit is contained in:
Concedo 2025-02-15 17:16:21 +08:00
parent 302fedc649
commit f48bd3f919
2 changed files with 52 additions and 16 deletions

View file

@ -9167,6 +9167,7 @@ Current version indicated by LITEVER below.
document.getElementById("featherlessdesc").classList.add("hidden");
document.getElementById("grokdesc").classList.add("hidden");
document.getElementById("oaidesc").classList.add("hidden");
document.getElementById("openrouterproviderbox").classList.add("hidden");
if(epchoice==2)
{
document.getElementById("oaidesc").classList.remove("hidden");
@ -9209,6 +9210,7 @@ Current version indicated by LITEVER below.
{
document.getElementById("openrouterdesc").classList.remove("hidden");
document.getElementById("custom_openrouter_model").classList.remove("hidden");
document.getElementById("openrouterproviderbox").classList.remove("hidden");
document.getElementById("custom_oai_endpoint").value = default_openrouter_base;
document.getElementById("custom_oai_endpoint").classList.add("hidden");
document.getElementById("custom_oai_key").value = localsettings.saved_openrouter_key;
@ -14183,6 +14185,12 @@ Current version indicated by LITEVER below.
if(targetep.toLowerCase().includes("openrouter.ai"))
{
oaiheaders["HTTP-Referer"] = "https://lite.koboldai.net";
if (document.getElementById("openrouterproviders").value.trim() != "") {
oai_payload.provider = {
"order": [document.getElementById("openrouterproviders").value.trim()],
"allow_fallbacks": false, //always explicitly selected
};
}
}
if(is_browser_supports_sse() && document.getElementById("oaistreaming").checked)
@ -20357,8 +20365,10 @@ Current version indicated by LITEVER below.
<textarea class="form-control" rows="3" style="resize: vertical; line-height:1.1; padding:4px; display:inline; width: 100%;" type="text" id="jailbreakprompttext2" placeholder="(Enter Assistant Postfix)"
value="" onload="togglejailbreak2();"></textarea>
</div>
</span>
<span id="openrouterproviderbox" class="hidden"><br>Preferred Provider: <input style="height: 25px; font-size:12px;padding:4px;display:inline;width:calc(100% - 140px)" class="form-control" type="text" id="openrouterproviders" placeholder="(Automatic)" value="">
<div style="display:inline;width:210px;">
</div>
</span>
</div>

View file

@ -8,6 +8,7 @@
# editing tools, save formats, memory, world info, author's note, characters,
# scenarios and everything Kobold and KoboldAI Lite have to offer.
import copy
import ctypes
import multiprocessing
import os
@ -47,7 +48,7 @@ logit_bias_max = 512
dry_seq_break_max = 128
# global vars
KcppVersion = "1.83.1"
KcppVersion = "1.84"
showdebug = True
kcpp_instance = None #global running instance
global_memory = {"tunnel_url": "", "restart_target":"", "input_to_exit":False, "load_complete":False}
@ -4796,6 +4797,7 @@ def unload_libs():
def reload_new_config(filename): #for changing config after launch
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
try:
config = json.load(f)
args.istemplate = False
for key, value in config.items(): #do not overwrite certain values
@ -4806,6 +4808,8 @@ def reload_new_config(filename): #for changing config after launch
setattr(args,"prompt","")
setattr(args,"config",None)
setattr(args,"launch",None)
except Exception as e:
print(f"Reload New Config Failed: {e}")
def load_config_cli(filename):
print("Loading .kcpps configuration file...")
@ -5023,15 +5027,36 @@ def main(launch_args):
setuptunnel(global_memory, True if args.sdmodel else False)
# invoke the main koboldcpp process
original_args = copy.deepcopy(args)
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "g_memory": global_memory, "gui_launcher": using_gui_launcher})
kcpp_instance.daemon = True
kcpp_instance.start()
fault_recovery_mode = False #if a config reload fails, recover back to old settings
while True: # keep the manager alive
try:
restart_target = ""
if not kcpp_instance or not kcpp_instance.is_alive():
break
if fault_recovery_mode:
#attempt to recover
print("Attempting to recover to safe mode, launching known-good config...")
fault_recovery_mode = False
args = copy.deepcopy(original_args) #restore known good original launcher args
if kcpp_instance:
kcpp_instance.terminate()
kcpp_instance.join(timeout=10) # Ensure process is stopped
kcpp_instance = None
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "g_memory": global_memory, "gui_launcher": False})
kcpp_instance.daemon = True
kcpp_instance.start()
global_memory["restart_target"] = ""
time.sleep(3)
else:
break # kill the program
if fault_recovery_mode and global_memory["load_complete"]:
fault_recovery_mode = False
restart_target = global_memory["restart_target"]
if restart_target!="":
print(f"Reloading new config: {restart_target}")
@ -5047,12 +5072,13 @@ def main(launch_args):
kcpp_instance.join(timeout=10) # Ensure process is stopped
kcpp_instance = None
print("Restarting KoboldCpp...")
fault_recovery_mode = True
reload_new_config(targetfilepath)
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "g_memory": global_memory, "gui_launcher": using_gui_launcher})
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "g_memory": global_memory, "gui_launcher": False})
kcpp_instance.daemon = True
kcpp_instance.start()
global_memory["restart_target"] = ""
time.sleep(1)
time.sleep(3)
else:
time.sleep(0.2)
except (KeyboardInterrupt,SystemExit):