From 1dd2cdbb4d2d26583f0a1552fa1ed655bf275069 Mon Sep 17 00:00:00 2001 From: Paul Alesius Date: Wed, 13 Aug 2025 17:09:16 +0200 Subject: [PATCH] Translate toggle for LLamaCPPCLIPTextEncode(LLamaCPP Universal) --- __init__.py | 20 +++++++++++--------- mz_llama_core_nodes.py | 6 ++++-- mz_prompt_utils.py | 21 ++++++++++++--------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/__init__.py b/__init__.py index a62bc38..30f5b73 100644 --- a/__init__.py +++ b/__init__.py @@ -228,23 +228,25 @@ class MZ_LLamaCPPCLIPTextEncode: @classmethod def INPUT_TYPES(s): importlib.reload(mz_llama_cpp) + from . import mz_llama_core_nodes + style_presets = mz_llama_core_nodes.get_style_presets() - result = { + return { "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}), }, "optional": { + "clip": ("CLIP",), "llama_cpp_model": ("LLamaCPPModelConfig",), + "llama_cpp_options": ("LLamaCPPOptions",), + "customize_instruct": ("CustomizeInstruct",), }, } - common_input = getCommonCLIPTextEncodeInput() - for key in common_input["required"]: - result["required"][key] = common_input["required"][key] - for key in common_input["optional"]: - result["optional"][key] = common_input["optional"][key] - - return result - RETURN_TYPES = ("STRING", "CONDITIONING",) RETURN_NAMES = ("text", "conditioning",) OUTPUT_NODE = True diff --git a/mz_llama_core_nodes.py b/mz_llama_core_nodes.py index 4e954d4..580d0f5 100644 --- a/mz_llama_core_nodes.py +++ b/mz_llama_core_nodes.py @@ -87,6 +87,7 @@ def llama_cpp_node_encode(args_dict): options = args_dict.get("llama_cpp_options", {}) keep_device = args_dict.get("keep_device", False) seed = args_dict.get("seed", -1) + translate_option = args_dict.get("translate", False) options["seed"] = seed options["chat_format"] = chat_format @@ -214,7 +215,8 @@ def llama_cpp_node_encode(args_dict): while response.find(", ,") != -1: response = response.replace(", ,", ",") - response = mz_prompt_utils.Utils.prompt_zh_to_en(response) + if translate_option is True: + response = mz_prompt_utils.Utils.prompt_zh_to_en(response) style_presets_prompt_text = style_presets_prompt.get(style_presets, "") @@ -231,7 +233,7 @@ def llama_cpp_node_encode(args_dict): conditionings = mz_prompt_utils.Utils.a1111_clip_text_encode( clip, response, ) - return {"ui": {"string": [mz_prompt_utils.Utils.to_debug_prompt(response),]}, "result": (response, conditionings)} + return {"ui": {"string": [mz_prompt_utils.Utils.to_debug_prompt(response, translate_option),]}, "result": (response, conditionings)} def image_interrogator_captioner(args_dict): diff --git a/mz_prompt_utils.py b/mz_prompt_utils.py index d3d575f..32c410c 100644 --- a/mz_prompt_utils.py +++ b/mz_prompt_utils.py @@ -736,21 +736,24 @@ class Utils: return Utils.en2zh(text) - def to_debug_prompt(p): - if p is None: - return "" - zh = Utils.en2zh(p) - if p == zh: - return p - zh = Utils.split_en_to_zh(p) - p = p.strip() - return f""" + def to_debug_prompt(p, z): + if z is True: + if p is None: + return "" + zh = Utils.en2zh(p) + if p == zh: + return p + zh = Utils.split_en_to_zh(p) + p = p.strip() + return f""" 原文: {p} 中文翻译: {zh} """ + else: + return p def get_gguf_files(): gguf_dir = Utils.get_gguf_models_path()