diff --git a/koboldcpp.py b/koboldcpp.py index 6c07d999a..931481f8a 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -8388,7 +8388,14 @@ def show_gui(): args.model_param = None if model_var.get() == "" else model_var.get() args.lora = None if lora_var.get() == "" else ([lora_var.get()]) args.loramult = (float(loramult_var.get()) if loramult_var.get()!="" else 1.0) - args.preloadstory = None if preloadstory_var.get() == "" else preloadstory_var.get() + pls_str_or_obj = None if preloadstory_var.get() == "" else preloadstory_var.get() + if pls_str_or_obj and isinstance(pls_str_or_obj,str): + try: + temp = json.loads(pls_str_or_obj) + pls_str_or_obj = temp + except Exception: + pass + args.preloadstory = pls_str_or_obj args.savedatafile = None if savedatafile_var.get() == "" else savedatafile_var.get() args.mcpfile = None if mcpfile_var.get() == "" else mcpfile_var.get() args.downloaddir = download_dir_var.get() @@ -8503,64 +8510,64 @@ def show_gui(): args.adminunloadtimeout = (0 if admin_unload_timeout_var.get()=="" else int(admin_unload_timeout_var.get())) args.showgui = False #prevent showgui from leaking into configs, its cli only - def import_vars(dict): + def import_vars(mydict): global importvars_in_progress importvars_in_progress = True - dict = convert_invalid_args(dict) + mydict = convert_invalid_args(mydict) - if "threads" in dict: - threads_var.set(dict["threads"]) - usemlock.set(1 if "usemlock" in dict and dict["usemlock"] else 0) - if "debugmode" in dict: - debugmode.set(dict["debugmode"]) - launchbrowser.set(1 if "launch" in dict and dict["launch"] else 0) - highpriority.set(1 if "highpriority" in dict and dict["highpriority"] else 0) - usemmap.set(1 if "usemmap" in dict and dict["usemmap"] else 0) - smartcontext_var.set(1 if "smartcontext" in dict and dict["smartcontext"] else 0) - flashattention_var.set(0 if "noflashattention" in dict and dict["noflashattention"] else 1) - contextshift_var.set(0 if "noshift" in dict and dict["noshift"] else 1) - fastforward_var.set(0 if "nofastforward" in dict and dict["nofastforward"] else 1) - swa_var.set(1 if "useswa" in dict and dict["useswa"] else 0) - smartcache_var.set(1 if "smartcache" in dict and dict["smartcache"] else 0) - smartcacheslots_var.set(dict["smartcache"] if ("smartcache" in dict and dict["smartcache"] and int(dict["smartcache"])>1) else savestate_limit_default) - remotetunnel_var.set(1 if "remotetunnel" in dict and dict["remotetunnel"] else 0) - keepforeground.set(1 if "foreground" in dict and dict["foreground"] else 0) - terminalonly.set(1 if "cli" in dict and dict["cli"] else 0) - pipelineparallel.set(0 if "nopipelineparallel" in dict and dict["nopipelineparallel"] else 1) - quietmode.set(1 if "quiet" in dict and dict["quiet"] else 0) - nocertifymode.set(1 if "nocertify" in dict and dict["nocertify"] else 0) - nomodel.set(1 if "nomodel" in dict and dict["nomodel"] else 0) - lowvram_var.set(1 if "lowvram" in dict and dict["lowvram"] else 0) - if "quantkv" in dict: - quantkv_var.set(dict["quantkv"]) - if "usecuda" in dict and dict["usecuda"]: + if "threads" in mydict: + threads_var.set(mydict["threads"]) + usemlock.set(1 if "usemlock" in mydict and mydict["usemlock"] else 0) + if "debugmode" in mydict: + debugmode.set(mydict["debugmode"]) + launchbrowser.set(1 if "launch" in mydict and mydict["launch"] else 0) + highpriority.set(1 if "highpriority" in mydict and mydict["highpriority"] else 0) + usemmap.set(1 if "usemmap" in mydict and mydict["usemmap"] else 0) + smartcontext_var.set(1 if "smartcontext" in mydict and mydict["smartcontext"] else 0) + flashattention_var.set(0 if "noflashattention" in mydict and mydict["noflashattention"] else 1) + contextshift_var.set(0 if "noshift" in mydict and mydict["noshift"] else 1) + fastforward_var.set(0 if "nofastforward" in mydict and mydict["nofastforward"] else 1) + swa_var.set(1 if "useswa" in mydict and mydict["useswa"] else 0) + smartcache_var.set(1 if "smartcache" in mydict and mydict["smartcache"] else 0) + smartcacheslots_var.set(mydict["smartcache"] if ("smartcache" in mydict and mydict["smartcache"] and int(mydict["smartcache"])>1) else savestate_limit_default) + remotetunnel_var.set(1 if "remotetunnel" in mydict and mydict["remotetunnel"] else 0) + keepforeground.set(1 if "foreground" in mydict and mydict["foreground"] else 0) + terminalonly.set(1 if "cli" in mydict and mydict["cli"] else 0) + pipelineparallel.set(0 if "nopipelineparallel" in mydict and mydict["nopipelineparallel"] else 1) + quietmode.set(1 if "quiet" in mydict and mydict["quiet"] else 0) + nocertifymode.set(1 if "nocertify" in mydict and mydict["nocertify"] else 0) + nomodel.set(1 if "nomodel" in mydict and mydict["nomodel"] else 0) + lowvram_var.set(1 if "lowvram" in mydict and mydict["lowvram"] else 0) + if "quantkv" in mydict: + quantkv_var.set(mydict["quantkv"]) + if "usecuda" in mydict and mydict["usecuda"]: if cublas_option is not None or hipblas_option is not None: if cublas_option: runopts_var.set(cublas_option) elif hipblas_option: runopts_var.set(hipblas_option) - mmq_var.set(1 if "mmq" in dict["usecuda"] else 0) - rowsplit_var.set(1 if "rowsplit" in dict["usecuda"] else 0) + mmq_var.set(1 if "mmq" in mydict["usecuda"] else 0) + rowsplit_var.set(1 if "rowsplit" in mydict["usecuda"] else 0) gpu_choice_var.set("All") for g in range(4): - if str(g) in dict["usecuda"]: + if str(g) in mydict["usecuda"]: gpu_choice_var.set(str(g+1)) break - elif "usevulkan" in dict and dict['usevulkan'] is not None: - if "noavx2" in dict and dict["noavx2"]: + elif "usevulkan" in mydict and mydict['usevulkan'] is not None: + if "noavx2" in mydict and mydict["noavx2"]: if vulkan_noavx2_option is not None: runopts_var.set(vulkan_noavx2_option) gpu_choice_var.set("All") for opt in range(0,4): - if opt in dict["usevulkan"]: + if opt in mydict["usevulkan"]: gpu_choice_var.set(str(opt+1)) break - elif "failsafe" in dict and dict["failsafe"]: + elif "failsafe" in mydict and mydict["failsafe"]: if vulkan_failsafe_option is not None: runopts_var.set(vulkan_failsafe_option) gpu_choice_var.set("All") for opt in range(0,4): - if opt in dict["usevulkan"]: + if opt in mydict["usevulkan"]: gpu_choice_var.set(str(opt+1)) break else: @@ -8568,54 +8575,54 @@ def show_gui(): runopts_var.set(vulkan_option) gpu_choice_var.set("All") for opt in range(0,4): - if opt in dict["usevulkan"]: + if opt in mydict["usevulkan"]: gpu_choice_var.set(str(opt+1)) break - elif ("noavx2" in dict and "usecpu" in dict and dict["usecpu"] and dict["noavx2"]) or ("failsafe" in dict and dict["failsafe"]): + elif ("noavx2" in mydict and "usecpu" in mydict and mydict["usecpu"] and mydict["noavx2"]) or ("failsafe" in mydict and mydict["failsafe"]): if failsafe_option is not None: runopts_var.set(failsafe_option) - elif "noavx2" in dict and dict["noavx2"]: + elif "noavx2" in mydict and mydict["noavx2"]: if noavx2_option is not None: runopts_var.set(noavx2_option) - elif "usecpu" in dict and dict["usecpu"]: + elif "usecpu" in mydict and mydict["usecpu"]: if default_option is not None: runopts_var.set(default_option) - if "gpulayers" in dict and dict["gpulayers"]: - gpulayers_var.set(dict["gpulayers"]) + if "gpulayers" in mydict and mydict["gpulayers"]: + gpulayers_var.set(mydict["gpulayers"]) else: gpulayers_var.set("0") - if "maingpu" in dict: - maingpu_var.set(dict["maingpu"]) + if "maingpu" in mydict: + maingpu_var.set(mydict["maingpu"]) else: maingpu_var.set("-1") - if "tensor_split" in dict and dict["tensor_split"]: - tssep = ','.join(map(str, dict["tensor_split"])) + if "tensor_split" in mydict and mydict["tensor_split"]: + tssep = ','.join(map(str, mydict["tensor_split"])) tensor_split_str_vars.set(tssep) - if "draftgpusplit" in dict and dict["draftgpusplit"]: - tssep = ','.join(map(str, dict["draftgpusplit"])) + if "draftgpusplit" in mydict and mydict["draftgpusplit"]: + tssep = ','.join(map(str, mydict["draftgpusplit"])) draftgpusplit_str_vars.set(tssep) - if "blasthreads" in dict and dict["blasthreads"]: - blas_threads_var.set(str(dict["blasthreads"])) + if "blasthreads" in mydict and mydict["blasthreads"]: + blas_threads_var.set(str(mydict["blasthreads"])) else: blas_threads_var.set("") - if "device" in dict and dict["device"]: - deviceoverride_var.set(str(dict["device"])) + if "device" in mydict and mydict["device"]: + deviceoverride_var.set(str(mydict["device"])) else: deviceoverride_var.set("") - if "contextsize" in dict and dict["contextsize"]: - context_var.set(contextsize_text.index(str(dict["contextsize"]))) - if "overridenativecontext" in dict and dict["overridenativecontext"]>0: + if "contextsize" in mydict and mydict["contextsize"]: + context_var.set(contextsize_text.index(str(mydict["contextsize"]))) + if "overridenativecontext" in mydict and mydict["overridenativecontext"]>0: customrope_var.set(1) manualrope_var.set(0) - customrope_nativectx.set(str(dict["overridenativecontext"])) - elif "ropeconfig" in dict and dict["ropeconfig"] and len(dict["ropeconfig"])>1: + customrope_nativectx.set(str(mydict["overridenativecontext"])) + elif "ropeconfig" in mydict and mydict["ropeconfig"] and len(mydict["ropeconfig"])>1: customrope_nativectx.set(default_native_ctx) - if dict["ropeconfig"][0]>0: + if mydict["ropeconfig"][0]>0: customrope_var.set(1) manualrope_var.set(1) - customrope_scale.set(str(dict["ropeconfig"][0])) - customrope_base.set(str(dict["ropeconfig"][1])) + customrope_scale.set(str(mydict["ropeconfig"][0])) + customrope_base.set(str(mydict["ropeconfig"][1])) else: customrope_var.set(0) manualrope_var.set(0) @@ -8623,150 +8630,153 @@ def show_gui(): customrope_nativectx.set(default_native_ctx) customrope_var.set(0) manualrope_var.set(0) - if "moeexperts" in dict and dict["moeexperts"]: - moeexperts_var.set(dict["moeexperts"]) - if "moecpu" in dict and dict["moecpu"]: - moecpu_var.set(dict["moecpu"]) - if "defaultgenamt" in dict and dict["defaultgenamt"]: - defaultgenamt_var.set(dict["defaultgenamt"]) - if "genlimit" in dict and dict["genlimit"]: - genlimit_var.set(dict["genlimit"]) + if "moeexperts" in mydict and mydict["moeexperts"]: + moeexperts_var.set(mydict["moeexperts"]) + if "moecpu" in mydict and mydict["moecpu"]: + moecpu_var.set(mydict["moecpu"]) + if "defaultgenamt" in mydict and mydict["defaultgenamt"]: + defaultgenamt_var.set(mydict["defaultgenamt"]) + if "genlimit" in mydict and mydict["genlimit"]: + genlimit_var.set(mydict["genlimit"]) else: genlimit_var.set(str(0)) - nobostoken_var.set(dict["nobostoken"] if ("nobostoken" in dict) else 0) - jinja_var.set(dict["jinja"] if ("jinja" in dict) else 0) - jinja_tools_var.set(dict["jinja_tools"] if ("jinja_tools" in dict) else 0) - jinja_kwargs = (dict["jinja_kwargs"] if ("jinja_kwargs" in dict and dict["jinja_kwargs"]) else "") + nobostoken_var.set(mydict["nobostoken"] if ("nobostoken" in mydict) else 0) + jinja_var.set(mydict["jinja"] if ("jinja" in mydict) else 0) + jinja_tools_var.set(mydict["jinja_tools"] if ("jinja_tools" in mydict) else 0) + jinja_kwargs = (mydict["jinja_kwargs"] if ("jinja_kwargs" in mydict and mydict["jinja_kwargs"]) else "") if isinstance(jinja_kwargs, type({})): jinja_kwargs = json.dumps(jinja_kwargs) jinja_kwargs_var.set(jinja_kwargs) - enableguidance_var.set(dict["enableguidance"] if ("enableguidance" in dict) else 0) - if "overridekv" in dict and dict["overridekv"]: - override_kv_var.set(dict["overridekv"]) - if "overridetensors" in dict and dict["overridetensors"]: - override_tensors_var.set(dict["overridetensors"]) + enableguidance_var.set(mydict["enableguidance"] if ("enableguidance" in mydict) else 0) + if "overridekv" in mydict and mydict["overridekv"]: + override_kv_var.set(mydict["overridekv"]) + if "overridetensors" in mydict and mydict["overridetensors"]: + override_tensors_var.set(mydict["overridetensors"]) - if "batchsize" in dict and dict["batchsize"]: - blas_size_var.set(batchsize_values.index(str(dict["batchsize"]))) + if "batchsize" in mydict and mydict["batchsize"]: + blas_size_var.set(batchsize_values.index(str(mydict["batchsize"]))) - autofit_var.set(1 if "autofit" in dict and dict["autofit"] else 0) - model_var.set(dict["model_param"] if ("model_param" in dict and dict["model_param"]) else "") + autofit_var.set(1 if "autofit" in mydict and mydict["autofit"] else 0) + model_var.set(mydict["model_param"] if ("model_param" in mydict and mydict["model_param"]) else "") - if "autofitpadding" in dict and dict["autofitpadding"]: - autofit_padding_var.set(dict["autofitpadding"]) + if "autofitpadding" in mydict and mydict["autofitpadding"]: + autofit_padding_var.set(mydict["autofitpadding"]) else: autofit_padding_var.set(str(default_autofit_padding)) lora_var.set("") - if "lora" in dict and dict["lora"]: - if len(dict["lora"]) > 1: - lora_var.set(dict["lora"][0]) + if "lora" in mydict and mydict["lora"]: + if len(mydict["lora"]) > 1: + lora_var.set(mydict["lora"][0]) else: - lora_var.set(dict["lora"][0]) - loramult_var.set(str(dict["loramult"]) if ("loramult" in dict and dict["loramult"]) else "1.0") + lora_var.set(mydict["lora"][0]) + loramult_var.set(str(mydict["loramult"]) if ("loramult" in mydict and mydict["loramult"]) else "1.0") - mmproj_var.set(dict["mmproj"] if ("mmproj" in dict and dict["mmproj"]) else "") - mmprojcpu_var.set(1 if ("mmprojcpu" in dict and dict["mmprojcpu"]) else 0) - if "visionmaxres" in dict and dict["visionmaxres"]: - visionmaxres_var.set(dict["visionmaxres"]) - draftmodel_var.set(dict["draftmodel"] if ("draftmodel" in dict and dict["draftmodel"]) else "") - if "draftamount" in dict: - draftamount_var.set(dict["draftamount"]) - if "draftgpulayers" in dict: - draftgpulayers_var.set(dict["draftgpulayers"]) + mmproj_var.set(mydict["mmproj"] if ("mmproj" in mydict and mydict["mmproj"]) else "") + mmprojcpu_var.set(1 if ("mmprojcpu" in mydict and mydict["mmprojcpu"]) else 0) + if "visionmaxres" in mydict and mydict["visionmaxres"]: + visionmaxres_var.set(mydict["visionmaxres"]) + draftmodel_var.set(mydict["draftmodel"] if ("draftmodel" in mydict and mydict["draftmodel"]) else "") + if "draftamount" in mydict: + draftamount_var.set(mydict["draftamount"]) + if "draftgpulayers" in mydict: + draftgpulayers_var.set(mydict["draftgpulayers"]) ssl_cert_var.set("") ssl_key_var.set("") - if "ssl" in dict and dict["ssl"]: - if len(dict["ssl"]) == 2: - ssl_cert_var.set(dict["ssl"][0]) - ssl_key_var.set(dict["ssl"][1]) + if "ssl" in mydict and mydict["ssl"]: + if len(mydict["ssl"]) == 2: + ssl_cert_var.set(mydict["ssl"][0]) + ssl_key_var.set(mydict["ssl"][1]) - password_var.set(dict["password"] if ("password" in dict and dict["password"]) else "") - preloadstory_var.set(dict["preloadstory"] if ("preloadstory" in dict and dict["preloadstory"]) else "") - savedatafile_var.set(dict["savedatafile"] if ("savedatafile" in dict and dict["savedatafile"]) else "") - mcpfile_var.set(dict["mcpfile"] if ("mcpfile" in dict and dict["mcpfile"]) else "") - chatcompletionsadapter_var.set(dict["chatcompletionsadapter"] if ("chatcompletionsadapter" in dict and dict["chatcompletionsadapter"]) else "") - port_var.set(dict["port_param"] if ("port_param" in dict and dict["port_param"]) else defaultport) - host_var.set(dict["host"] if ("host" in dict and dict["host"]) else "") - multiuser_var.set(dict["multiuser"] if ("multiuser" in dict) else 1) - multiplayer_var.set(dict["multiplayer"] if ("multiplayer" in dict) else 0) - websearch_var.set(dict["websearch"] if ("websearch" in dict) else 0) - download_dir_var.set(dict["downloaddir"] if ("downloaddir" in dict and dict["downloaddir"]) else "") + password_var.set(mydict["password"] if ("password" in mydict and mydict["password"]) else "") + pls_obj = "" + if ("preloadstory" in mydict and mydict["preloadstory"]): + pls_obj = mydict["preloadstory"] if not isinstance(mydict["preloadstory"], dict) else json.dumps(mydict["preloadstory"]) + preloadstory_var.set(pls_obj) + savedatafile_var.set(mydict["savedatafile"] if ("savedatafile" in mydict and mydict["savedatafile"]) else "") + mcpfile_var.set(mydict["mcpfile"] if ("mcpfile" in mydict and mydict["mcpfile"]) else "") + chatcompletionsadapter_var.set(mydict["chatcompletionsadapter"] if ("chatcompletionsadapter" in mydict and mydict["chatcompletionsadapter"]) else "") + port_var.set(mydict["port_param"] if ("port_param" in mydict and mydict["port_param"]) else defaultport) + host_var.set(mydict["host"] if ("host" in mydict and mydict["host"]) else "") + multiuser_var.set(mydict["multiuser"] if ("multiuser" in mydict) else 1) + multiplayer_var.set(mydict["multiplayer"] if ("multiplayer" in mydict) else 0) + websearch_var.set(mydict["websearch"] if ("websearch" in mydict) else 0) + download_dir_var.set(mydict["downloaddir"] if ("downloaddir" in mydict and mydict["downloaddir"]) else "") - horde_name_var.set(dict["hordemodelname"] if ("hordemodelname" in dict and dict["hordemodelname"]) else "koboldcpp") - horde_context_var.set(dict["hordemaxctx"] if ("hordemaxctx" in dict and dict["hordemaxctx"]) else maxhordectx) - horde_gen_var.set(dict["hordegenlen"] if ("hordegenlen" in dict and dict["hordegenlen"]) else maxhordelen) - horde_apikey_var.set(dict["hordekey"] if ("hordekey" in dict and dict["hordekey"]) else "") - horde_workername_var.set(dict["hordeworkername"] if ("hordeworkername" in dict and dict["hordeworkername"]) else "") - usehorde_var.set(1 if ("hordekey" in dict and dict["hordekey"]) else 0) - if "maxrequestsize" in dict and dict["maxrequestsize"]: - maxrequestsize_var.set(dict["maxrequestsize"]) - if "ratelimit" in dict and dict["ratelimit"]: - ratelimit_var.set(dict["ratelimit"]) + horde_name_var.set(mydict["hordemodelname"] if ("hordemodelname" in mydict and mydict["hordemodelname"]) else "koboldcpp") + horde_context_var.set(mydict["hordemaxctx"] if ("hordemaxctx" in mydict and mydict["hordemaxctx"]) else maxhordectx) + horde_gen_var.set(mydict["hordegenlen"] if ("hordegenlen" in mydict and mydict["hordegenlen"]) else maxhordelen) + horde_apikey_var.set(mydict["hordekey"] if ("hordekey" in mydict and mydict["hordekey"]) else "") + horde_workername_var.set(mydict["hordeworkername"] if ("hordeworkername" in mydict and mydict["hordeworkername"]) else "") + usehorde_var.set(1 if ("hordekey" in mydict and mydict["hordekey"]) else 0) + if "maxrequestsize" in mydict and mydict["maxrequestsize"]: + maxrequestsize_var.set(mydict["maxrequestsize"]) + if "ratelimit" in mydict and mydict["ratelimit"]: + ratelimit_var.set(mydict["ratelimit"]) - sd_model_var.set(dict["sdmodel"] if ("sdmodel" in dict and dict["sdmodel"]) else "") - sd_clamped_var.set(int(dict["sdclamped"]) if ("sdclamped" in dict and dict["sdclamped"]) else 0) - sd_clamped_soft_var.set(int(dict["sdclampedsoft"]) if ("sdclampedsoft" in dict and dict["sdclampedsoft"]) else 0) - sd_threads_var.set(str(dict["sdthreads"]) if ("sdthreads" in dict and dict["sdthreads"]) else str(default_threads)) - sd_quant_var.set(sd_quant_choices[(dict["sdquant"] if ("sdquant" in dict and dict["sdquant"]>=0 and dict["sdquant"]=0 and mydict["sdquant"]