ComfyUI Node

Text to Key JNK

Turn a long model filename into a short, stable key

By AljnkΒ·Created about a year agoΒ·Updated 12 months agoΒ· 3
Text to Key JNK
    • STRING
    β—„textβ–Ί
    β—„cut_start0β–Ί
    β—„cut_end0β–Ί
    β—„cut_textβ–Ί

    Model names are the worst strings in any workflow. realistic_vision_v6.0_B1_noVAE_fp16.safetensors is a dozen characters of signal buried in a mile of cruft, and if you're saving results with the model name in the filename, that's what ends up in your output folder. "Text to Key JNK" (the class is literally Model2Key) squeezes a long name down to a short, stable key you can use in filenames, tags, or keys. The pack README: "Cuts beginning and end of text to create keys from these parts."

    The mechanism is a small pipeline, and understanding the order helps you set it. First it strips any path - it splits on both backslashes and forward slashes and keeps the last segment, so feeding it a full path like C:\models\checkpoints\dreamshaper_8.safetensors is fine. Then, if you've set cut_text, it truncates the name at the first occurrence of that substring - e.g. set it to .safetensors and the extension is gone. Finally, the actual "key" trick: if cut_start and cut_end are set, it takes the first cut_start characters and the last cut_end characters and joins them with a hyphen. dreamshaper_8.safetensors with cut_start=3, cut_end=3 becomes something like dre-ors. That's the "key from the parts" behavior - you keep a distinctive head and tail and drop the middle.

    The guard in the code is worth knowing: if cut_start or cut_end is larger than the whole name (or they overlap past it), it just returns the full name rather than crashing or slicing into garbage. So over-setting is safe - you get the name back unchanged instead of an error. That's forgiving, and it means the failure mode is "no shortening" rather than "broken string."

    The inputs:

    • text - the name (or full path) to shorten.
    • cut_start - how many leading characters to keep.
    • cut_end - how many trailing characters to keep.
    • cut_text - optional substring to truncate at (like a file extension).

    Output is a single STRING.

    Install: ComfyUI Manager β†’ search "JNK" β†’ Install, then restart. Or:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/Aljnk/ComfyUI-JNK-Tiny-Nodes.git
    

    Then restart. No dependencies - pure string handling.

    Gotchas: the hyphens can make keys collide - two models with the same first and last few characters produce the same key, so if you're using keys as unique identifiers, throw a hash in there (the pack has a Text to MD5 node for exactly that). And the cut_text truncation happens before the head/tail cut, so order matters: truncate the extension first, then decide how many head/tail characters you want from the shortened name. It's a tiny text utility, but for anyone who names outputs by model, it's the difference between a folder full of 80-character filenames and a folder you can actually skim.

    CategoryπŸ”§ JNK

    Inputs (4)

    NameTypeDefaultDescription
    textSTRINGβ€”
    cut_startINT0β€”
    cut_endINT0β€”
    cut_textSTRINGβ€”

    Outputs (1)

    NameTypeDescription
    STRINGSTRINGβ€”