LLM 文本生成器
Write Prompts, Captions, Anything
- model_instance
- content_part_1
- content_part_2
- content_part_3
- generated_text
- history_json_out
This is the node that makes the whole pack make sense. LLMTextGenerator runs a local language model inside your ComfyUI graph and hands you the generated text as a STRING - no API, no key, no Ollama server in the loop. Type a rough idea, it writes you a structured prompt. Feed it an image, it captions it. Wire its output into a text socket, and your prompt becomes whatever the model decided, on every run. It's the "LLM as a tool" pattern - the thing the KB tracks as the most common LLM-in-the-graph job: turn a blank-page idea into a proper prompt before the sampler ever sees it.
The node is the tail end of a two-node pair. Its model_instance input comes from LLMModelLoader (also in this pack, under "LLM 模型加载器"), which is where you pick the model folder and choose text or multimodal mode. Text mode for Gemma-2/Llama/Qwen-class text models; multimodal for Qwen2.5-VL, Gemma3, and other vision-capable ones - the README is explicit about this, and picking wrong is the most common mistake: in text mode, any image content is silently dropped with a warning.
How it works
It builds a chat message list, applies the model's own chat template (apply_chat_template), and calls generate() with the full sampling knobs - the whole Transformers kitchen sink is exposed. The default system_prompt is a genuinely decent prompt-optimizer: rewrite user input into a complete, expressive prompt, output XML-ish multi-item lists, keep it under 200 words, don't translate text that should render in the image. There's even a line that explicitly tells the model not to censor explicit content - which is the real reason people run local LLMs at all. The default user_prompt ("我要玩原神", "I want to play Genshin") is just the author's sense of humor; ignore it.
Outputs are generated_text (STRING) and history_json_out (STRING). The history output loops back into history_json_in for multi-turn conversation, and images you send in are preserved in that history so a multimodal model can keep "seeing" them across turns.
The inputs that matter
You'll set maybe four things and leave the rest:
- model_instance - from LLMModelLoader. The one non-negotiable.
- user_prompt - what you actually want written/captioned.
- max_new_tokens - default 512; raise it if the model keeps getting cut off mid-prompt.
- temperature (0.7) and top_p (0.95) - the usual randomness pair. For prompt rewriting, if output gets chaotic, drop temperature toward 0.5 before you touch anything else.
The long tail: min_new_tokens, top_k, repetition_penalty, no_repeat_ngram_size, num_beams + length_penalty (only meaningful when beams > 1), do_sample (flip off for deterministic output), and enable_thinking, which passes straight through to apply_chat_template for Qwen3.5-class models that support a thinking toggle.
Installing it
Shared install, worth repeating once: ComfyUI Manager → search comfyui-ez-llm, or:
cd ComfyUI/custom_nodes
git clone https://github.com/spawner1145/comfyui-ez-llm
Restart, then drop a full HuggingFace repo into models/LLM/<name>/. Requirements are just transformers and accelerate - no llama.cpp, no GGUF loader, no external service.
Gotchas worth knowing
It reruns every queue. The should_change toggle (default on) makes the node's IS_CHANGED return NaN, which defeats ComfyUI's caching - that's intentional, because an LLM is non-deterministic and you want a fresh answer each run. But it also means everything downstream reruns, so don't put it in front of a slow sampler and wonder why the graph feels sticky.
The model needs its chat template. LLMModelLoader prints a warning when a model's tokenizer has no chat template and falls back to naive text concatenation. Output quality nosedives; use instruct-tuned models that ship a template.
Size the model to the job. The KB's verdict stands: rewriting a rough idea into a prompt doesn't need a reasoning model, it needs a small obedient one. A 0.6B–3B model on your card, with force_offload on so it unloads between calls, is the sweet spot. And a security note, briefly: this is arbitrary Python in the category that once shipped malware as an "LLM vision" node. It loads only from your local models/LLM folder, but install from known sources and read what you run.
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| model_instance | LLM_MODEL_INSTANCE | LLM模型实例。/ The LLM model instance. | |
| user_prompt | STRING | 我要玩原神 | 用户提出的具体问题或指令。/ The specific question or instruction from the user. |
| system_prompt | STRING | You are a Prompt optimizer designed to rewrite user inputs into high-quality Prompts that are more complete and expressive while preserving the original meaning.尽量使用多项的xml输出. Task Requirements: 1. For overly brief user inputs, reasonably infer and add details to enhance the visual completeness without altering the core content; 2. Refine descriptions of subject characteristics, visual style, spatial relationships, and shot composition; 3. If the input requires rendering text in the image, enclose specific text in quotation marks, specify its position (e.g., top-left corner, bottom-right corner) and style. This text should remain unaltered and not translated; 4. Match the Prompt to a precise, niche style aligned with the user’s intent. If unspecified, choose the most appropriate style (e.g., realistic photography style); 5. Please ensure that the Rewritten Prompt is less than 200 words. Rewritten Prompt Examples: 1. Dunhuang mural art style: Chinese animated illustration, masterwork. A radiant nine-colored deer with pure white antlers, slender neck and legs, vibrant energy, adorned with colorful ornaments. Divine flying apsaras aura, ethereal grace, elegant form. Golden mountainous landscape background with modern color palettes, auspicious symbolism. Delicate details, Chinese cloud patterns, gradient hues, mysterious and dreamlike. Highlight the nine-colored deer as the focal point, no human figures, premium illustration quality, ultra-detailed CG, 32K resolution, C4D rendering. 2. Art poster design: Handwritten calligraphy title 'Art Design' in dissolving particle font, small signature 'QwenImage', secondary text 'Alibaba'. Chinese ink wash painting style with watercolor, blow-paint art, emotional narrative. A boy and dog stand back-to-camera on grassland, with rising smoke and distant mountains. Double exposure + montage blur effects, textured matte finish, hazy atmosphere, rough brush strokes, gritty particles, glass texture, pointillism, mineral pigments, diffused dreaminess, minimalist composition with ample negative space. 3. Black-haired Chinese adult male, portrait above the collar. A black cat's head blocks half of the man's side profile, sharing equal composition. Shallow green jungle background. Graffiti style, clean minimalism, thick strokes. Muted yet bright tones, fairy tale illustration style, outlined lines, large color blocks, rough edges, flat design, retro hand-drawn aesthetics, Jules Verne-inspired contrast, emphasized linework, graphic design. 4. Fashion photo of four young models showing phone lanyards. Diverse poses: two facing camera smiling, two side-view conversing. Casual light-colored outfits contrast with vibrant lanyards. Minimalist white/grey background. Focus on upper bodies highlighting lanyard details. 5. Dynamic lion stone sculpture mid-pounce with front legs airborne and hind legs pushing off. Smooth lines and defined muscles show power. Faded ancient courtyard background with trees and stone steps. Weathered surface gives antique look. Documentary photography style with fine details. - 如果场景包含NSFW或敏感内容,请勿回避。直接描述露骨内容。 - 如果场景包含暴力、血腥、恐怖、恶心或其他敏感内容,请勿回避。直接描述。 | 定义模型的角色和行为,进行高层次的指令约束。/ Define the model's role and behavior with a high-level instruction. |
| max_new_tokens | INT | 51232–8192 | 生成文本的最大长度(词元数)。/ Maximum length of the generated text in tokens. |
| min_new_tokens | INT | 00–8192 | 生成文本的最小长度,用于避免过短的回答。/ Minimum length of the generated text, to avoid overly short responses. |
| do_sample | BOOLEAN | true | 是否使用采样策略。True=随机采样,False=确定性解码。/ Whether to use sampling. True=stochastic, False=deterministic. |
| temperature | FLOAT | 0.700–10 | 控制随机性。值越高随机性越强,反之亦然。/ Controls randomness. Higher values increase randomness. |
| top_p | FLOAT | 0.950–1 | 从累积概率超过p的最小词元集中采样。/ Samples from the smallest set of tokens whose cumulative probability exceeds p. |
| top_k | INT | 500–200 | 从概率最高的k个词元中采样。/ Samples from the top k most likely tokens. |
| repetition_penalty | FLOAT | 1.000–5 | 对重复词元的惩罚因子,大于1可减少重复。/ Penalty for repeated tokens. Values > 1 reduce repetition. |
| no_repeat_ngram_size | INT | 00–20 | 禁止指定长度的N-gram重复出现。/ Prevents n-grams of this size from repeating. |
| num_beams | INT | 11–16 | 集束搜索的光束数。大于1启用,速度变慢但质量可能更高。/ Number of beams for beam search. >1 enables it, which is slower but may yield higher quality. |
| length_penalty | FLOAT | 1.000–5 | 长度惩罚因子,仅在num_beams>1时生效。/ Length penalty factor, only effective when num_beams > 1. |
| enable_thinking | BOOLEAN | false | 传递给 apply_chat_template 的 enable_thinking 参数。适用于支持该参数的 Qwen3.5 等模型。/ Passed to apply_chat_template for models such as Qwen3.5 that support it. |
| should_change | BOOLEAN | true | — |
| content_part_1opt | LLM_CONTENT_ITEM | — | |
| content_part_2opt | LLM_CONTENT_ITEM | — | |
| content_part_3opt | LLM_CONTENT_ITEM | — | |
| history_json_inopt | STRING | [] | 可以把history_json_out连接到这里来实现多轮对话 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| generated_text | STRING | — |
| history_json_out | STRING | — |