Nodes/ComfyUI-QG-Tools/文本合并
ComfyUI Node

文本合并

QG_TextConcat

By live1617·Created 15 days ago·Updated a day ago· 3
文本合并
    • STRING
    ◄text1►
    ◄text2►
    ◄separator►

    The most common prompt shape in this ecosystem isn't a paragraph someone typed. It's a paragraph plus a variable: your style block, then whatever the LoRA's trigger words happen to be. Or the character description, then the scene. Keeping them as two strings is the right call - one of them changes per run and lives upstream - but every text encoder you own wants a single string.

    QG_TextConcat does the smallest possible version of that job: text1 + separator + text2. Nothing else. No trimming, no smart spacing, no deduplication.

    How it works

    The source is about ten lines of actual logic, and it's honest about it:

    def concat_text(self, text1="", text2="", separator=""):
        return (text1 + separator + text2,)
    

    Both texts are forceInput STRING slots, which means exactly what it sounds like: you cannot type into them on the node. They are sockets, and they want wires. The separator is a normal widget - a small text field you fill in on the card.

    That asymmetry is the design. The two things being joined usually come from somewhere upstream (a trigger-words output from a LoRA loader, a prompt from a text node, an LLM's response). The separator is the one bit of punctuation that's genuinely authored by you, once, and never changes.

    Nothing is trimmed, and the author says so plainly in the tooltip. Join "a" and "b" with a separator of "-" and you get -b if text1 is empty - not an error, not a cleanup, just the string. If you want a space between your style block and your trigger words, put the space in the separator. If you want a comma-space, type , . If you want a line break, type one in the separator field.

    It's ported from Comfyroll Studio's CR_TextConcatenate (MIT, credited in the pack's notices), with a small but real fix: the original declared a second output called something like show_help and never returned a value for it, so that socket could never carry anything. The QG version deletes it. One output, STRING.

    Where it fits in a real graph

    The canonical pattern: LoRA loader outputs a triggers string → QG_TextConcat text1; your style prompt comes from a text node → text2; separator ", "; output goes to a CLIP Text Encode. Now adding a LoRA adds its trigger words to your prompt without you touching the prompt.

    The other pattern that shows up constantly: chaining. Two of these in series gives you three strings joined, which is usually enough for [subject] + [style] + [quality spam]. Past three, ask yourself whether you actually want a template file instead - the pack has a document loader for reading prompts off disk, and that scales much better than a wall of concat nodes.

    The output socket is declared as * with the name STRING. ComfyUI has a wildcard type and this uses it, which means it'll connect to any input, including ones that aren't text. The value is always a string; if you plug it into something expecting an IMAGE you'll get an error downstream rather than at the wire. Standard wildcard trade-off, nothing unusual.

    Inputs and outputs

    • text1 (STRING, wire only) - first piece.
    • text2 (STRING, wire only) - second piece.
    • separator (STRING widget) - inserted verbatim between them. Default empty, which glues them into one word.
    • output STRING - the joined text.

    Installing

    Ships in ComfyUI-QG-tools, alongside 31 other nodes, with no third-party pip requirements - its requirements.txt is comments only, which tells ComfyUI Manager to skip pip.

    cd ComfyUI/custom_nodes
    git clone https://github.com/live1617/ComfyUI-QG-tools
    

    Then a full restart of ComfyUI, not a tab refresh. The console banner should report 32 nodes loaded. Find it under QG-tools/文本, or search concat, join, merge or 合并.

    Gotchas worth knowing before you debug a weird prompt

    Both slots want a wire. If you dropped the node and expected to type in it, you grabbed the wrong one of this pack's text nodes - there's a separate plain text node for authoring strings by hand. This one joins things.

    An empty text1 leaves a dangling separator. "" + ", " + "style" is , style, and CLIP will happily tokenize the leading comma instead of complaining. Time-box that one: if a prompt starts with a comma, look at your concat's inputs.

    The separator is not escaped or cleaned. Multi-line separators work, which is handy for splitting prompt blocks - just remember that newlines in a prompt are cosmetically nice and semantically almost meaningless to a text encoder.

    No dedupe, no ordering logic. If both branches contain masterpiece, best quality, you get it twice. That's fine for many models and wasteful for others; it's not this node's job to notice.

    CategoryQG-tools/文本

    Inputs (3)

    NameTypeDefaultDescription
    text1optSTRING第一段文本,从上游连过来。
    text2optSTRING第二段文本,从上游连过来。
    separatoroptSTRING两段文本之间的分隔符,原样插入(想用空格或换行就填什么)

    Outputs (1)

    NameTypeDescription
    STRING*text1 + 分隔符 + text2 的结果,不做任何去空格处理。