mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-08-18 21:05:36 +00:00
added config overwriting
This commit is contained in:
parent
5f0038cdc9
commit
be6ff2602d
2 changed files with 52 additions and 14 deletions
|
|
@ -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.
|
|||
|
||||
<div>
|
||||
<b class="color_white" style="padding: 5px;">Change Loaded Model / Config:</b><br>
|
||||
<div style="display:flex;padding: 5px;">
|
||||
<select title="Select New Config" style="padding:4px; width:100%" class="form-control" id="adminconfigdropdown" onchange="change_admin_config_selection()">
|
||||
<div class="color_white" style="padding: 5px;">
|
||||
<div style="padding-top:3px">
|
||||
Select New Target: <select title="Select New Config" style="padding:4px; width:100%" class="form-control" id="adminconfigdropdown" onchange="change_admin_config_selection()">
|
||||
</select>
|
||||
<select title="Override Config" style="padding:4px; width:100%" class="form-control hidden" id="adminconfigoverridedropdown">
|
||||
</div>
|
||||
<div style="padding-top:3px">
|
||||
Select Base Config: <select title="Override Config" style="padding:4px; width:100%" class="form-control" id="adminconfigoverridedropdown">
|
||||
</select>
|
||||
<button type="button" style="margin-left:2px;width:146px" class="btn btn-primary" onclick="trigger_admin_reload()">Reload KoboldCpp</button>
|
||||
</div>
|
||||
<div style="display:flex; padding: 5px; justify-content: center;">
|
||||
<button type="button" class="btn btn-primary" onclick="trigger_admin_reload()">Reload KoboldCpp</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="menutext">Warning: This will terminate the current KoboldCpp instance and relaunch it with a new config. If an invalid configuration is selected, the new server may fail to relaunch!</div>
|
||||
<br>
|
||||
|
|
|
|||
11
koboldcpp.py
11
koboldcpp.py
|
|
@ -5638,10 +5638,10 @@ Change Mode<br>
|
|||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue