Translate toggle for LLamaCPPCLIPTextEncode(LLamaCPP Universal)

This commit is contained in:
Paul Alesius
2025-08-13 17:09:16 +02:00
parent 2299b8af45
commit 1dd2cdbb4d
3 changed files with 27 additions and 20 deletions
+11 -9
View File
@@ -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
+4 -2
View File
@@ -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):
+12 -9
View File
@@ -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()