updated lite, added ability to export kcpps via CLI

This commit is contained in:
Concedo 2025-02-20 22:58:12 +08:00
parent a67044270a
commit 41350df81f
2 changed files with 61 additions and 4 deletions

View file

@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
--> -->
<script> <script>
const LITEVER = 215; const LITEVER = 216;
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
var localflag = true; var localflag = true;
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_"; const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@ -3005,6 +3005,8 @@ Current version indicated by LITEVER below.
var placeholder_tags_data = []; var placeholder_tags_data = [];
var thinking_pattern = "<think>([\\s\\S]+?)<\/think>"; var thinking_pattern = "<think>([\\s\\S]+?)<\/think>";
var thinking_action = 1; //0=display, 1=collapse, 2=hide, 3=remove var thinking_action = 1; //0=display, 1=collapse, 2=hide, 3=remove
var start_thinking_tag = "<think>";
var force_thinking_tag = false;
var voice_typing_mode = 0; //0=off, 1=on, 2=ptt var voice_typing_mode = 0; //0=off, 1=on, 2=ptt
var koboldcpp_has_whisper = false; //does backend support voice typing var koboldcpp_has_whisper = false; //does backend support voice typing
var voice_is_recording = false; //currently recording voice? var voice_is_recording = false; //currently recording voice?
@ -3127,6 +3129,7 @@ Current version indicated by LITEVER below.
inject_timestamps: false, inject_timestamps: false,
inject_chatnames_instruct: false, inject_chatnames_instruct: false,
inject_jailbreak_instruct: false, inject_jailbreak_instruct: false,
custom_jailbreak_text: "Sure, I will help with that:\\n\\n",
separate_end_tags: false, separate_end_tags: false,
idle_responses: 0, idle_responses: 0,
idle_duration: 60, idle_duration: 60,
@ -6368,6 +6371,8 @@ Current version indicated by LITEVER below.
new_save_storyobj.websearch_template = websearch_template; new_save_storyobj.websearch_template = websearch_template;
new_save_storyobj.thinking_pattern = thinking_pattern; new_save_storyobj.thinking_pattern = thinking_pattern;
new_save_storyobj.thinking_action = thinking_action; new_save_storyobj.thinking_action = thinking_action;
new_save_storyobj.start_thinking_tag = start_thinking_tag;
new_save_storyobj.force_thinking_tag = force_thinking_tag;
if (export_settings) { if (export_settings) {
new_save_storyobj.savedsettings = JSON.parse(JSON.stringify(localsettings)); new_save_storyobj.savedsettings = JSON.parse(JSON.stringify(localsettings));
@ -6695,6 +6700,14 @@ Current version indicated by LITEVER below.
{ {
thinking_action = storyobj.thinking_action; thinking_action = storyobj.thinking_action;
} }
if(storyobj.force_thinking_tag)
{
force_thinking_tag = storyobj.force_thinking_tag;
}
if(storyobj.start_thinking_tag)
{
start_thinking_tag = storyobj.start_thinking_tag;
}
} else { } else {
//v2 load //v2 load
if(storyobj.prompt != "") if(storyobj.prompt != "")
@ -8543,6 +8556,19 @@ Current version indicated by LITEVER below.
},false,true); },false,true);
} }
var pendingassistantjailbreak = "";
function set_assistant_jailbreak()
{
inputBox("Set Assistant Jailbreak","Enter Assistant Jailbreak Prefix",pendingassistantjailbreak,"(Enter Jailbreak Prefix)",()=>{
let userinput = getInputBoxValue();
if(userinput.trim()=="")
{
userinput = "Sure, I will help with that:\\n\\n";
}
pendingassistantjailbreak = userinput;
},false,false);
}
function expand_tokens_section(targetid) function expand_tokens_section(targetid)
{ {
let tablist = ["expandregexreplace","expandthinking","expandtokenbans","expandlogitbias","expandplaceholdertags"]; let tablist = ["expandregexreplace","expandthinking","expandtokenbans","expandlogitbias","expandplaceholdertags"];
@ -10638,6 +10664,7 @@ Current version indicated by LITEVER below.
document.getElementById("xtcunsupporteddiv").classList.remove("hidden"); document.getElementById("xtcunsupporteddiv").classList.remove("hidden");
} }
pendingsequencebreakers = localsettings.dry_sequence_breakers; pendingsequencebreakers = localsettings.dry_sequence_breakers;
pendingassistantjailbreak = localsettings.custom_jailbreak_text;
document.getElementById("setgrammar").disabled = !is_using_kcpp_with_grammar(); document.getElementById("setgrammar").disabled = !is_using_kcpp_with_grammar();
document.getElementById("voice_typing_mode").disabled = !is_using_kcpp_with_whisper(); document.getElementById("voice_typing_mode").disabled = !is_using_kcpp_with_whisper();
@ -11037,6 +11064,7 @@ Current version indicated by LITEVER below.
localsettings.dry_base = parseFloat(document.getElementById("dry_base").value); localsettings.dry_base = parseFloat(document.getElementById("dry_base").value);
localsettings.dry_allowed_length = parseInt(document.getElementById("dry_allowed_length").value); localsettings.dry_allowed_length = parseInt(document.getElementById("dry_allowed_length").value);
localsettings.dry_sequence_breakers = pendingsequencebreakers; localsettings.dry_sequence_breakers = pendingsequencebreakers;
localsettings.custom_jailbreak_text = pendingassistantjailbreak;
localsettings.xtc_threshold = parseFloat(document.getElementById("xtc_threshold").value); localsettings.xtc_threshold = parseFloat(document.getElementById("xtc_threshold").value);
localsettings.xtc_probability = parseFloat(document.getElementById("xtc_probability").value); localsettings.xtc_probability = parseFloat(document.getElementById("xtc_probability").value);
localsettings.token_count_multiplier = parseInt(document.getElementById("token_count_multiplier").value); localsettings.token_count_multiplier = parseInt(document.getElementById("token_count_multiplier").value);
@ -11582,6 +11610,8 @@ Current version indicated by LITEVER below.
thinking_pattern = "<think>([\\s\\S]+?)<\/think>"; thinking_pattern = "<think>([\\s\\S]+?)<\/think>";
} }
thinking_action = parseInt(document.getElementById("thinking_action").value); thinking_action = parseInt(document.getElementById("thinking_action").value);
force_thinking_tag = document.getElementById("force_thinking_tag").checked?true:false;
start_thinking_tag = document.getElementById("start_thinking_tag").value;
} }
function set_personal_notes() function set_personal_notes()
@ -11934,6 +11964,8 @@ Current version indicated by LITEVER below.
websearch_template = ""; websearch_template = "";
thinking_pattern = "<think>([\\s\\S]+?)<\/think>"; thinking_pattern = "<think>([\\s\\S]+?)<\/think>";
thinking_action = 1; thinking_action = 1;
force_thinking_tag = false;
start_thinking_tag = "<think>";
} }
warn_on_quit = false; warn_on_quit = false;
show_corpo_leftpanel(false); show_corpo_leftpanel(false);
@ -13171,7 +13203,11 @@ Current version indicated by LITEVER below.
if(localsettings.inject_jailbreak_instruct) if(localsettings.inject_jailbreak_instruct)
{ {
newgen = newgen + "Sure, I will help with that:\n\n"; newgen = newgen + localsettings.custom_jailbreak_text.replaceAll("\\n", "\n");
}
if(force_thinking_tag && start_thinking_tag!="")
{
newgen = newgen + start_thinking_tag.replaceAll("\\n", "\n");
} }
} }
else //may be continuting existing instruction OR starting a brand new session. check if first action else //may be continuting existing instruction OR starting a brand new session. check if first action
@ -17820,7 +17856,6 @@ Current version indicated by LITEVER below.
let newbodystr = ""; let newbodystr = "";
input = replace_instruct_placeholders(input); input = replace_instruct_placeholders(input);
input = apply_display_only_regex(input);
let chatunits = []; let chatunits = [];
if(localsettings.opmode==3) //chat mode if(localsettings.opmode==3) //chat mode
{ {
@ -17838,6 +17873,7 @@ Current version indicated by LITEVER below.
let curr = chatunits[i]; let curr = chatunits[i];
let foundimg = ""; let foundimg = "";
let processed_msg = curr.msg; let processed_msg = curr.msg;
processed_msg = apply_display_only_regex(processed_msg);
if(processed_msg && processed_msg!="") if(processed_msg && processed_msg!="")
{ {
processed_msg = replace_noninstruct_placeholders(processed_msg,true); processed_msg = replace_noninstruct_placeholders(processed_msg,true);
@ -18506,6 +18542,8 @@ Current version indicated by LITEVER below.
} }
document.getElementById("thinking_pattern").value = thinking_pattern; document.getElementById("thinking_pattern").value = thinking_pattern;
document.getElementById("thinking_action").value = thinking_action; document.getElementById("thinking_action").value = thinking_action;
document.getElementById("force_thinking_tag").checked = force_thinking_tag;
document.getElementById("start_thinking_tag").value = start_thinking_tag;
} }
function populate_placeholder_tags() function populate_placeholder_tags()
@ -20778,7 +20816,8 @@ Current version indicated by LITEVER below.
<div class="settinglabel"> <div class="settinglabel">
<div class="justifyleft settingsmall">Assistant Jailbreak <span class="helpicon">?<span <div class="justifyleft settingsmall">Assistant Jailbreak <span class="helpicon">?<span
class="helptext">Automatically injects a jailbreak message after every instruct query, to make the AI more likely to obey you.</span></span></div> class="helptext">Automatically injects a jailbreak message after every instruct query, to make the AI more likely to obey you.</span></span></div>
<input type="checkbox" title="Assistant Jailbreak" id="inject_jailbreak_instruct" style="margin:0px 0px 0px auto;"> <button title="Set Assistant Jailbreak" type="button" class="btn btn-primary bg_green" style="padding:1px 3px;margin:0px 0px 0px auto;font-size:10px;" onclick="set_assistant_jailbreak()">Set</button>
<input type="checkbox" title="Assistant Jailbreak" id="inject_jailbreak_instruct">
</div> </div>
<div class="settinglabel"> <div class="settinglabel">
<div class="justifyleft settingsmall">Separate End Tags <span class="helpicon">?<span <div class="justifyleft settingsmall">Separate End Tags <span class="helpicon">?<span
@ -21722,6 +21761,8 @@ Current version indicated by LITEVER below.
<option value="2">Hide</option> <option value="2">Hide</option>
<option value="3">Remove</option> <option value="3">Remove</option>
</select></div> </select></div>
<div style="padding:4px" class="settinglabel justifyleft">Force Insert Thinking Tag <input title="Force Insert Thinking Tag" type="checkbox" id="force_thinking_tag" style="margin:4px;"><input class="settinglabel miniinput" style="margin-left:4px;width:100px;" type="text" placeholder="" value="" id="start_thinking_tag"></div>
<div style="padding:4px" class="settinglabel justifyleft">Note: 'Force Insert Thinking Tags' does not work with the 'Remove' option of CoT handling regex.</div>
</div> </div>
<div style="padding:3px;" class="justifyleft settinglabel">Placeholder Tags <span class="helpicon">?<span <div style="padding:3px;" class="justifyleft settinglabel">Placeholder Tags <span class="helpicon">?<span

View file

@ -4828,6 +4828,17 @@ def load_config_cli(filename):
print("\nA .kcppt template was selected from CLI - automatically selecting your backend...") print("\nA .kcppt template was selected from CLI - automatically selecting your backend...")
auto_set_backend_cli() auto_set_backend_cli()
def save_config_cli(filename):
savdict = json.loads(json.dumps(args.__dict__))
if filename is None:
return
filenamestr = str(filename).strip()
filenamestr = f"{filenamestr}.kcpps" if ".kcpps" not in filenamestr.lower() else filenamestr
file = open(filenamestr, 'a')
file.write(json.dumps(savdict))
file.close()
print(f"\nSaved .kcpps configuration file as {filename}\nIt can be loaded with --config [filename] in future.")
pass
def delete_old_pyinstaller(): def delete_old_pyinstaller():
try: try:
@ -4993,6 +5004,10 @@ def main(launch_args):
analyze_gguf_model_wrapper(args.analyze) analyze_gguf_model_wrapper(args.analyze)
return return
if args.exportconfig and args.exportconfig!="":
save_config_cli(args.exportconfig)
return
if args.config and len(args.config)==1: #handle initial config loading for launch if args.config and len(args.config)==1: #handle initial config loading for launch
cfgname = args.config[0] cfgname = args.config[0]
if isinstance(cfgname, str): if isinstance(cfgname, str):
@ -5811,6 +5826,7 @@ if __name__ == '__main__':
advparser.add_argument("--forceversion", help="If the model file format detection fails (e.g. rogue modified model) you can set this to override the detected format (enter desired version, e.g. 401 for GPTNeoX-Type2).",metavar=('[version]'), type=int, default=0) advparser.add_argument("--forceversion", help="If the model file format detection fails (e.g. rogue modified model) you can set this to override the detected format (enter desired version, e.g. 401 for GPTNeoX-Type2).",metavar=('[version]'), type=int, default=0)
advparser.add_argument("--smartcontext", help="Reserving a portion of context to try processing less frequently. Outdated. Not recommended.", action='store_true') advparser.add_argument("--smartcontext", help="Reserving a portion of context to try processing less frequently. Outdated. Not recommended.", action='store_true')
advparser.add_argument("--unpack", help="Extracts the file contents of the KoboldCpp binary into a target directory.", metavar=('destination'), type=str, default="") advparser.add_argument("--unpack", help="Extracts the file contents of the KoboldCpp binary into a target directory.", metavar=('destination'), type=str, default="")
advparser.add_argument("--exportconfig", help="Exports the current selected arguments as a .kcpps settings file", metavar=('[filename]'), type=str, default="")
advparser.add_argument("--nomodel", help="Allows you to launch the GUI alone, without selecting any model.", action='store_true') advparser.add_argument("--nomodel", help="Allows you to launch the GUI alone, without selecting any model.", action='store_true')
advparser.add_argument("--moeexperts", metavar=('[num of experts]'), help="How many experts to use for MoE models (default=follow gguf)", type=int, default=-1) advparser.add_argument("--moeexperts", metavar=('[num of experts]'), help="How many experts to use for MoE models (default=follow gguf)", type=int, default=-1)
compatgroup2 = parser.add_mutually_exclusive_group() compatgroup2 = parser.add_mutually_exclusive_group()