From cf8a95b736ecd3dccff1d7b9ae9ed6587018e29c Mon Sep 17 00:00:00 2001 From: bedovyy Date: Tue, 23 Jun 2026 02:53:57 +0900 Subject: [PATCH] truncate long strings on PreviewAnyStorable --- nodes_utils.py | 16 ++++++++++++++-- pyproject.toml | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/nodes_utils.py b/nodes_utils.py index f3a06c3..020e6cf 100644 --- a/nodes_utils.py +++ b/nodes_utils.py @@ -33,6 +33,18 @@ class PreviewAnyStorable(io.ComfyNode): def check_lazy_status(cls, source=None, output_value=False, **kwargs): return ["stored"] if output_value[0] else ["source"] + @staticmethod + def _truncate_nested_strings(obj, max_len=1000, keep_len=20): + if isinstance(obj, dict): + return {k: PreviewAnyStorable._truncate_nested_strings(v, max_len, keep_len) for k, v in obj.items()} + elif isinstance(obj, list): + return [PreviewAnyStorable._truncate_nested_strings(item, max_len, keep_len) for item in obj] + elif isinstance(obj, str): + if len(obj) >= max_len: + return f"{obj[:keep_len]}...{obj[-keep_len:]}" + return obj + return obj + @classmethod def execute(cls, source=None, output_value=False, stored='[""]') -> io.NodeOutput: use_stored = output_value[0] @@ -54,12 +66,12 @@ class PreviewAnyStorable(io.ComfyNode): if source is None: value = "None" elif isinstance(source, str): - value = source + value = cls._truncate_nested_strings(source) elif isinstance(source, (int, float, bool)): value = str(source) else: try: - value = json.dumps(source, indent=4) + value = json.dumps(cls._truncate_nested_strings(source), indent=2, ensure_ascii=False) except Exception: try: value = str(source) diff --git a/pyproject.toml b/pyproject.toml index 1ecf495..df9b6c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "ComfyUI-LLM-Helper" description = "A custom nodes for LLM API" -version = "1.0.1" # Custom Node version. Must be semantically versioned. +version = "1.0.2" # Custom Node version. Must be semantically versioned. license = { file = "LICENSE" } dependencies = [ "python-dotenv"