From be6ff2602defbeaf654ad5b6454857567aadc39f Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Fri, 3 Apr 2026 00:21:14 +0800 Subject: [PATCH] added config overwriting --- embd_res/klite.embd | 55 ++++++++++++++++++++++++++++++++++++--------- koboldcpp.py | 11 ++++++--- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/embd_res/klite.embd b/embd_res/klite.embd index 17b40345a..1698be7a7 100644 --- a/embd_res/klite.embd +++ b/embd_res/klite.embd @@ -4327,6 +4327,7 @@ Current version indicated by LITEVER below. var websearch_in_progress = false; var kcpp_tts_json = ""; var avoidwelcome = false; + var undisplayed_editing_text = ""; var localsettings = { my_api_key: "0000000000", //put here so it can be saved and loaded in persistent mode @@ -14384,7 +14385,6 @@ Current version indicated by LITEVER below. if(targetfile && targetfile.endsWith(".gguf")) { let overridedropdown = document.getElementById("adminconfigoverridedropdown"); - overridedropdown.classList.remove("hidden"); var dropdown = document.getElementById("adminconfigdropdown"); for (var i = overridedropdown.options.length; i >= 0; i--) { var option = overridedropdown.options[i]; @@ -14404,8 +14404,6 @@ Current version indicated by LITEVER below. el.value = str; overridedropdown.appendChild(el); } - }else{ - document.getElementById("adminconfigoverridedropdown").classList.add("hidden"); } } var adminrebootflag = 0; @@ -14421,7 +14419,7 @@ Current version indicated by LITEVER below. let header = {'Content-Type': 'application/json'}; let payload = {"filename": targetfile}; - if(!document.getElementById("adminconfigoverridedropdown").classList.contains("hidden")) + if(document.getElementById("adminconfigoverridedropdown").value && document.getElementById("adminconfigoverridedropdown").value!="") { payload["overrideconfig"] = document.getElementById("adminconfigoverridedropdown").value; } @@ -17963,6 +17961,23 @@ Current version indicated by LITEVER below. } } + //for display trimming + function splitAtWhitespaceFromEnd(str, maxLength) + { + if (str.length <= maxLength) { + return ["", str]; + } + const sliceStart = str.length - maxLength; + const visiblePart = str.slice(sliceStart); + const match = visiblePart.match(/[\s\n]/); + if (match) { + const splitIndex = match.index; + return [ str.slice(0, sliceStart + splitIndex + 1), visiblePart.slice(splitIndex + 1) ]; + } + + return [str.slice(0, sliceStart), visiblePart]; + } + //Prioritizes truncating example messages in memory function truncate_memory(current_memory, max_mem_len, to_boundary) { @@ -23956,6 +23971,7 @@ Current version indicated by LITEVER below. let oldInnerText = concat_gametext(false, "","",""); let gametext_elem = document.getElementById("gametext"); let editedmatcher = unstash_image_placeholders(gametext_elem.innerText); + editedmatcher = undisplayed_editing_text + editedmatcher; if (oldInnerText != editedmatcher) { gametext_arr = []; @@ -23985,7 +24001,7 @@ Current version indicated by LITEVER below. gametext_elem.innerHTML = htmlstr; //rather than dump it all into one history, let's split it into paragraphs - let fullmergedstory = gametext_elem.innerText; + let fullmergedstory = undisplayed_editing_text + gametext_elem.innerText; let newestChunk = ""; @@ -24430,6 +24446,7 @@ Current version indicated by LITEVER below. { document.getElementById("gametext").contentEditable = (document.getElementById("allowediting").checked && pending_response_id==""); let inEditMode = (document.getElementById("allowediting").checked ? true : false); + undisplayed_editing_text = ""; if(is_corpo_ui()) { @@ -24868,6 +24885,15 @@ Current version indicated by LITEVER below. if (inEditMode) //edit mode only { fulltxt = concat_gametext(false, "", "%SpnStg%", "%SpnEtg%",true); + if(localsettings.max_display_chars>0 && fulltxt.length > localsettings.max_display_chars) + { + let splitted = splitAtWhitespaceFromEnd(fulltxt,localsettings.max_display_chars); + undisplayed_editing_text = unescape_html(splitted[0]); + undisplayed_editing_text = replaceAll(undisplayed_editing_text, `%SpnStg%`, ``); + undisplayed_editing_text = replaceAll(undisplayed_editing_text, `%SclStg%`,``); + undisplayed_editing_text = replaceAll(undisplayed_editing_text, `%SpnEtg%`, ``); + fulltxt = splitted[1]; + } fulltxt = replaceAll(fulltxt, get_instruct_starttag(true), `%SclStg%`+escape_html(get_instruct_starttag(true))+`%SpnEtg%`); fulltxt = replaceAll(fulltxt, get_instruct_endtag(true), `%SclStg%`+escape_html(get_instruct_endtag(true))+`%SpnEtg%`); if (localsettings.separate_end_tags) { @@ -24974,9 +25000,10 @@ Current version indicated by LITEVER below. } else //all other modes besides instruct, non-edit { - if(localsettings.max_display_chars>0) + if(localsettings.max_display_chars>0 && fulltxt.length > localsettings.max_display_chars) { - fulltxt = fulltxt.length > localsettings.max_display_chars ? fulltxt.slice(-localsettings.max_display_chars) : fulltxt; //truncated + let splitted = splitAtWhitespaceFromEnd(fulltxt,localsettings.max_display_chars); + fulltxt = splitted[1]; } fulltxt = apply_display_only_regex(fulltxt); @@ -31243,12 +31270,18 @@ Current version indicated by LITEVER below.
Change Loaded Model / Config:
-
- - - +
+
+ +

diff --git a/koboldcpp.py b/koboldcpp.py index 42e734c54..6d65bfc4c 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -5638,10 +5638,10 @@ Change Mode
if (targetfile in allowed_files and os.path.commonpath([dirpath, targetfilepath]) == dirpath and os.path.exists(targetfilepath)): global_memory["restart_override_config_target"] = "" # Jail enforcement - if targetfile.lower().endswith(".gguf") and overrideconfig: + if targetfile and overrideconfig: overrideconfigfilepath = os.path.abspath(os.path.join(dirpath, overrideconfig)) if (overrideconfig in allowed_files and os.path.commonpath([dirpath, overrideconfigfilepath]) == dirpath and os.path.exists(overrideconfigfilepath)): - print(f"Admin: Override config set to {overrideconfig}") + print(f"Admin: Override base config set to {overrideconfig}") global_memory["restart_override_config_target"] = overrideconfig print(f"Admin: Received request to reload config to {targetfile}") global_memory["restart_target"] = targetfile @@ -8880,13 +8880,15 @@ def reload_from_new_args(newargs): except Exception as e: print(f"Reload New Config Failed: {e}") -def reload_new_config(filename,defaultargs): #for changing config after launch +def reload_new_config(filename,defaultargs,overwrite_blank=False): #for changing config after launch with open(filename, 'r', encoding='utf-8', errors='ignore') as f: try: config = json.load(f) for key, value in defaultargs.items(): # Fill missing defaults directly into config if key not in config: config[key] = value + elif overwrite_blank and key in config and not config[key]: + config[key] = value reload_from_new_args(config) except Exception as e: print(f"Reload New Config Failed: {e}") @@ -9496,6 +9498,9 @@ def main(launch_args, default_args): elif targetfilepath.endswith(".gguf") and restart_override_config_target!="": reload_new_config(targetfilepath2,defaultargs) args.model_param = targetfilepath + elif targetfilepath and targetfilepath2 and restart_override_config_target!="": + reload_new_config(targetfilepath2,defaultargs) + reload_new_config(targetfilepath,vars(args),True) else: reload_new_config(targetfilepath,defaultargs) global_memory["autoswapmode"] = args.autoswapmode