Text Generation
The prompt-generator node — and the trap that makes it lie to you
- generated_text
Want your graph to write its own prompts? TextGenerationPipeline runs a causal language model (GPT-2 by default) on whatever text you give it and returns the generated continuation. Hook it into a text branch that feeds a CLIP encoder and you've got an automatic prompt-expansion loop - take a short seed like "cyberpunk alley," let the model spin it into a paragraph, and pipe that into your sampler. It's the kind of node that sounds gimmicky until you realize it's a surprisingly cheap way to add variation to otherwise static prompts.
It's from kadirnar/ComfyUI-Transformers, the pack that wraps Hugging Face's transformers.pipeline() as one node per task. The default model is plain gpt2 (~500 MB), which is ancient by 2026 standards and writes like a 2019 Twitter feed - but it's also tiny, fast, and the safest default for a node whose job is "add words," not "be Claude."
How it works
Mechanically it's pipeline("text-generation", model=model_name) called with max_new_tokens and temperature, returning result[0]["generated_text"]. Nothing exotic. But there are two behaviors you need to understand before it surprises you.
The big one: the output includes your prompt. For a causal LM like GPT-2, generated_text is the full string - your input plus the continuation. The node doesn't strip the prefix, so if you feed it "a cat" and it generates "wearing a tiny hat," you get back "a cat wearing a tiny hat" as one string. That's often what you want (full prompt in, full prompt out), but if you expected only the new part, you'll wonder why your prompt keeps doubling.
Temperature is your only dial, and it matters. Default 1.0 is the model's natural gibberish level. Crank to 0.7 for tamer output, push toward 1.5 for "let's get weird" variation generation. max_new_tokens caps the continuation (default 50, up to 2048) - this is also your runtime budget, since generation is roughly linear in token count and these models run on CPU in this pack.
Inputs and outputs
prompt- multiline STRING, your seed text.model_name- defaultgpt2; free text. Swap indistilgpt2(~350 MB) to save RAM or a small modern model if you want better prose.max_new_tokens- INT, default 50.temperature- FLOAT, default 1.0.- Output:
generated_text- a single STRING.
Wire generated_text into any text node that feeds a CLIP encoder, or into a Show Text node to eyeball the output before it goes anywhere.
Installing it
Pack-standard:
cd ComfyUI/custom_nodes
git clone https://github.com/kadirnar/ComfyUI-Transformers
cd ComfyUI-Transformers
pip install -r requirements.txt
or search "ComfyUI-Transformers" in ComfyUI Manager, then restart. The README's cd custom/nodes is a typo. First run downloads the model from the Hub to ~/.cache/huggingface - expect a console stall. Note this pack also requires sentencepiece and accelerate per its requirements, which the install pulls in automatically.
Where people get burned
- Prompt-doubling output - see above. It's not a bug, it's how causal LMs report. If you need only the continuation, slice the prefix off with a string-manipulation node.
- First generation is slow. Model load on every run (the pack's cache is dead code), then generation. Be patient on the first call.
- GPT-2's vocabulary is a time capsule. It won't know "Flux," "LoRA," or most 2026 concepts. If your seeds are full of modern jargon, pick a newer model or accept nonsense.
The verdict: it's the least "diffusion-native" node in the pack, and its output needs a critical eye. But as a variation engine feeding your prompt pipeline, it punches above its weight - just remember it's a muse, not a writer.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | — | |
| model_name | STRING | gpt2 | — |
| max_new_tokens | INT | 501–2048 | — |
| temperature | FLOAT | 1.000.01–2 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| generated_text | STRING | — |