From a2ef7fdf1a8523948097dbd50703e65e9bbad840 Mon Sep 17 00:00:00 2001 From: Paul Alesius Date: Wed, 13 Aug 2025 17:09:55 +0200 Subject: [PATCH] Format toggle for LLamaCPPCLIPTextEncode(LLamaCPP Universal) --- __init__.py | 3 ++- mz_llama_core_nodes.py | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/__init__.py b/__init__.py index 30f5b73..c92edd7 100644 --- a/__init__.py +++ b/__init__.py @@ -235,9 +235,10 @@ class MZ_LLamaCPPCLIPTextEncode: "required": { "style_presets": (style_presets, {"default": style_presets[1]}), "text": ("STRING", {"multiline": True}), - "translate": ([False, True], {"default": False}), "keep_device": ([False, True], {"default": False}), "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), + "translate": ([False, True], {"default": False}), + "format": ([False, True], {"default": True}), }, "optional": { "clip": ("CLIP",), diff --git a/mz_llama_core_nodes.py b/mz_llama_core_nodes.py index 580d0f5..f45399a 100644 --- a/mz_llama_core_nodes.py +++ b/mz_llama_core_nodes.py @@ -88,6 +88,7 @@ def llama_cpp_node_encode(args_dict): keep_device = args_dict.get("keep_device", False) seed = args_dict.get("seed", -1) translate_option = args_dict.get("translate", False) + format_option = args_dict.get("format", True) options["seed"] = seed options["chat_format"] = chat_format @@ -201,19 +202,20 @@ def llama_cpp_node_encode(args_dict): if keep_device is False: mz_llama_cpp.freed_gpu_memory(model_file=model_file) - # 去除换行 - while response.find("\n") != -1: - response = response.replace("\n", " ") + if format_option is True: + # 去除换行 + while response.find("\n") != -1: + response = response.replace("\n", " ") - # 句号换成逗号 - while response.find(".") != -1: - response = response.replace(".", ",") + # 句号换成逗号 + while response.find(".") != -1: + response = response.replace(".", ",") - # 去除多余逗号 - while response.find(",,") != -1: - response = response.replace(",,", ",") - while response.find(", ,") != -1: - response = response.replace(", ,", ",") + # 去除多余逗号 + while response.find(",,") != -1: + response = response.replace(",,", ",") + while response.find(", ,") != -1: + response = response.replace(", ,", ",") if translate_option is True: response = mz_prompt_utils.Utils.prompt_zh_to_en(response)