|
157 | 157 | embedded_lcpp_ui_gz = None |
158 | 158 | embedded_musicui = None |
159 | 159 | embedded_musicui_gz = None |
| 160 | +preloaded_custom_jinja = "" |
160 | 161 | voicebank = {} |
161 | 162 | voicelist = ["kobo","cheery","sleepy","shouty","chatty"] |
162 | 163 | sslvalid = False |
@@ -259,6 +260,7 @@ class load_model_inputs(ctypes.Structure): |
259 | 260 | ("quant_k", ctypes.c_int), |
260 | 261 | ("quant_v", ctypes.c_int), |
261 | 262 | ("check_slowness", ctypes.c_bool), |
| 263 | + ("jinja_template", ctypes.c_char_p), |
262 | 264 | ("highpriority", ctypes.c_bool), |
263 | 265 | ("swa_support", ctypes.c_bool), |
264 | 266 | ("swa_padding", ctypes.c_int), |
@@ -1955,6 +1957,7 @@ def load_model(model_filename): |
1955 | 1957 | inputs.override_tensors = args.overridetensors.encode("UTF-8") if args.overridetensors else "".encode("UTF-8") |
1956 | 1958 | inputs.moecpu = (200 if args.moecpu > 200 else args.moecpu) |
1957 | 1959 | inputs.check_slowness = (not args.highpriority and os.name == 'nt' and 'Intel' in platform.processor()) |
| 1960 | + inputs.jinja_template = preloaded_custom_jinja.encode("UTF-8") |
1958 | 1961 | inputs.highpriority = args.highpriority |
1959 | 1962 | inputs.swa_support = args.useswa |
1960 | 1963 | inputs.swa_padding = args.swapadding if args.useswa else 0 |
@@ -7287,6 +7290,7 @@ def hide_tooltip(event): |
7287 | 7290 | customrope_base = ctk.StringVar(value="10000") |
7288 | 7291 | customrope_nativectx = ctk.StringVar(value=str(default_native_ctx)) |
7289 | 7292 | chatcompletionsadapter_var = ctk.StringVar(value="AutoGuess") |
| 7293 | + jinjatemplate_var = ctk.StringVar() |
7290 | 7294 | jinja_var = ctk.IntVar(value=0) |
7291 | 7295 | jinja_tools_var = ctk.IntVar(value=0) |
7292 | 7296 | jinja_kwargs_var = ctk.StringVar() |
@@ -8091,10 +8095,11 @@ def pickpremadetemplate(): |
8091 | 8095 | if fnam: |
8092 | 8096 | chatcompletionsadapter_var.set(fnam) |
8093 | 8097 | ctk.CTkButton(model_tab, 64, text="Pick Premade", command=pickpremadetemplate).grid(row=24, column=0, padx=(350), pady=2, stick="nw") |
| 8098 | + makefileentry(model_tab, "Jinja Template:", "Select a custom Jinja chat template", jinjatemplate_var, 30, width=280, filetypes=[("Jinja Template", "*.jinja")], singlerow=True, tooltiptxt="Select a custom Jinja chat template, will overwrite model jinja chat template") |
8094 | 8099 |
|
8095 | 8100 | mmproj_var.trace_add("write", gui_changed_modelfile) |
8096 | 8101 | draftmodel_var.trace_add("write", gui_changed_modelfile) |
8097 | | - makefileentry(model_tab, "Download Dir:", "Select directory to store all model downloads", download_dir_var, 27, width=280, singlerow=True, dialog_type=2, tooltiptxt="Specify a directory to store any downloaded models.") |
| 8102 | + makefileentry(model_tab, "Download Dir:", "Select directory to store all model downloads", download_dir_var, 35, width=280, singlerow=True, dialog_type=2, tooltiptxt="Specify a directory to store any downloaded models.") |
8098 | 8103 | makecheckbox(model_tab, "Allow Launch Without Models", nomodel, 40, tooltiptxt="Allows running the WebUI with no model loaded.") |
8099 | 8104 |
|
8100 | 8105 | # Network Tab |
@@ -8431,6 +8436,8 @@ def export_vars(): |
8431 | 8436 | args.jinja_tools = (jinja_tools_var.get()==1) |
8432 | 8437 | if jinja_kwargs_var.get() != "": |
8433 | 8438 | args.jinja_kwargs = jinja_kwargs_var.get() |
| 8439 | + if jinjatemplate_var.get() != "": |
| 8440 | + args.jinjatemplate = jinjatemplate_var.get() |
8434 | 8441 | args.enableguidance = (enableguidance_var.get()==1) |
8435 | 8442 | args.overridekv = None if override_kv_var.get() == "" else override_kv_var.get() |
8436 | 8443 | args.overridetensors = None if override_tensors_var.get() == "" else override_tensors_var.get() |
@@ -8719,6 +8726,7 @@ def import_vars(mydict): |
8719 | 8726 | if isinstance(jinja_kwargs, type({})): |
8720 | 8727 | jinja_kwargs = json.dumps(jinja_kwargs) |
8721 | 8728 | jinja_kwargs_var.set(jinja_kwargs) |
| 8729 | + jinjatemplate_var.set(mydict["jinjatemplate"] if ("jinjatemplate" in mydict and mydict["jinjatemplate"]) else "") |
8722 | 8730 |
|
8723 | 8731 | enableguidance_var.set(mydict["enableguidance"] if ("enableguidance" in mydict) else 0) |
8724 | 8732 | if "overridekv" in mydict and mydict["overridekv"]: |
@@ -10177,7 +10185,7 @@ def disableSwappedFieldsInConfig(args, swapReqType): |
10177 | 10185 |
|
10178 | 10186 | def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False): |
10179 | 10187 | global embedded_kailite, embedded_kcpp_docs, embedded_kcpp_sdui, embedded_kailite_gz, embedded_kcpp_docs_gz, embedded_kcpp_sdui_gz, embedded_lcpp_ui_gz, embedded_musicui, embedded_musicui_gz, start_time, exitcounter, global_memory, using_gui_launcher |
10180 | | - global libname, args, friendlymodelname, friendlysdmodelname, fullsdmodelpath, password, fullwhispermodelpath, ttsmodelpath, embeddingsmodelpath, musicdiffusionmodelpath, musicllmmodelpath, friendlyembeddingsmodelname, has_audio_support, has_vision_support, cached_chat_template |
| 10188 | + global libname, args, friendlymodelname, friendlysdmodelname, fullsdmodelpath, password, fullwhispermodelpath, ttsmodelpath, embeddingsmodelpath, musicdiffusionmodelpath, musicllmmodelpath, friendlyembeddingsmodelname, has_audio_support, has_vision_support, cached_chat_template, preloaded_custom_jinja |
10181 | 10189 |
|
10182 | 10190 | start_server = True |
10183 | 10191 |
|
@@ -10408,6 +10416,23 @@ def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False): |
10408 | 10416 | dlfile = download_model_from_url(args.musicvae,[".gguf"],min_file_size=500000) |
10409 | 10417 | if dlfile: |
10410 | 10418 | args.musicvae = dlfile |
| 10419 | + if args.mcpfile and args.mcpfile!="": |
| 10420 | + dlfile = download_model_from_url(args.mcpfile,[".json"],min_file_size=64) |
| 10421 | + if dlfile: |
| 10422 | + args.mcpfile = dlfile |
| 10423 | + if args.jinjatemplate and args.jinjatemplate!="": |
| 10424 | + dlfile = download_model_from_url(args.jinjatemplate,[".jinja"],min_file_size=64) |
| 10425 | + if dlfile: |
| 10426 | + args.jinjatemplate = dlfile |
| 10427 | + |
| 10428 | + if args.jinjatemplate and os.path.exists(args.jinjatemplate): |
| 10429 | + try: |
| 10430 | + print(f"Using custom Jinja template: {args.jinjatemplate}") |
| 10431 | + with open(args.jinjatemplate, 'r', encoding='utf-8', errors='ignore') as f: |
| 10432 | + preloaded_custom_jinja = f.read() |
| 10433 | + except Exception as e: |
| 10434 | + print(f"Error loading jinja templat: {e}") |
| 10435 | + preloaded_custom_jinja = "" |
10411 | 10436 |
|
10412 | 10437 | # sanitize and replace the default vanity name. remember me.... |
10413 | 10438 | if args.model_param and args.model_param!="": |
@@ -11224,7 +11249,8 @@ def range_checker(arg: str): |
11224 | 11249 | advparser.add_argument("--chatcompletionsadapter", metavar=('[filename]'), help="Select an optional ChatCompletions Adapter JSON file to force custom instruct tags.", default="AutoGuess") |
11225 | 11250 | advparser.add_argument("--jinja", help="Enables using jinja chat template formatting for chat completions endpoint. Other endpoints are unaffected. Tool calls are done without jinja.", action='store_true') |
11226 | 11251 | advparser.add_argument("--jinja_tools","--jinja-tools","--jinjatools", help="Enables using jinja chat template formatting for chat completions endpoint. Other endpoints are unaffected. Tool calls are done with jinja.", action='store_true') |
11227 | | - advparser.add_argument("--jinja_kwargs","--jinja-kwargs","--jinjakwargs","--chat-template-kwargs", metavar=('{"parameter":"value",...}'), help="Set additiona fields for Jinja JSON template parser, must be a valid JSON object.", default="") |
| 11252 | + advparser.add_argument("--jinja_kwargs","--jinja-kwargs","--jinjakwargs","--chat-template-kwargs", metavar=('{"parameter":"value",...}'), help="Set additional fields for Jinja JSON template parser, must be a valid JSON object.", default="") |
| 11253 | + advparser.add_argument("--jinjatemplate","--chat-template-file", metavar=('[filename]'), help="Select a custom Jinja chat template, will overwrite model jinja chat template", default="") |
11228 | 11254 | advparser.add_argument("--noflashattention","--no-flash-attn","-nofa", help="Disables flash attention.", action='store_true') |
11229 | 11255 | advparser.add_argument("--lowvram","-nkvo","--no-kv-offload", help="If supported by the backend, do not offload KV to GPU (lowvram mode). Not recommended, will be slow.", action='store_true') |
11230 | 11256 | advparser.add_argument("--quantkv", help="Sets the KV cache data type quantization, options are f16/bf16/q8_0/q5_1/q4_0. Requires Flash Attention for full effect, otherwise only K cache is quantized.",metavar=('[quantization level f16/bf16/q8_0/q5_1/q4_0]'), type=str, choices=["f16","bf16","q8_0","q5_1","q4_0","0","1","2","3"], default="f16") |
|
0 commit comments