QWEN 文本处理
Clean up LLM output before it poisons your prompt
- text
- count
There's a dirty secret about LLMs in ComfyUI: they're chatty. A model answering "describe this image" hands you paragraphs, blank lines, and formatting that has no business being in a prompt. If that text goes straight into a text encoder, the chat scaffolding and whitespace go with it. QWEN_TextProcess is the cleanup stage - strip the newlines, drop the empty lines, kill the stray spaces, optionally number the lines or count them, all before your prompt builder sees the result.
It's the lighter sibling of QWEN_TextOperation in the same pack, and the two complement each other. This one handles the "make this text tidy" jobs with two fixed operations; QWEN_TextOperation handles the "edit this text" jobs with five configurable slots. If you're captioning images with QWEN3VL_Image and feeding captions into a dataset file or a training set, this is the node that turns raw model prose into clean, one-per-line captions.
How it works
The mechanism is dead simple: the node takes your text, runs main_operation_1 on it, then feeds the result into main_operation_2. Two operations, in sequence, no more. The operations:
- 不改变 - leave it alone
- 去换行 - remove all line breaks (the classic "collapse a paragraph into one line" move)
- 去空行 - drop blank lines, keeping the rest
- 去空格 - strip every space and tab (aggressive; mostly for tag-style output)
- 添加编号 - number each non-empty line as
1.content,2.content... - 统计字数 - count characters
A typical setup: 去空行 to collapse the model's paragraphs, then 添加编号 to turn a caption list into a numbered one. The two-slot limit sounds restrictive until you remember the order matters and you can chain this node with QWEN_TextOperation for anything fancier.
The inputs and output
- text - the string to process. Required and force-input; connect it from a generation node.
- main_operation_1 / main_operation_2 - the two operations, run in order.
Outputs: text (the processed string) and count (an INT). The count is the number of paragraphs when you used 添加编号, or the character count when you used 统计字数, and otherwise 0 - the second operation's count wins if both produced one. It's a small extra, but wiring count into a display or a counter can be genuinely handy for "how many captions did we process" reporting.
Install
Ships with ComfyUI_QWEN3VL_API; no separate install and - importantly - no API key. This node is pure string manipulation:
cd ComfyUI/custom_nodes
git clone https://github.com/flywhale-666/ComfyUI_QWEN3VL_API
cd ComfyUI_QWEN3VL_API
pip install -r requirements.txt
Restart, or use ComfyUI Manager and search "ComfyUI_QWEN3VL_API".
Troubleshooting
- 去空格 ate more than you wanted - it removes every space and tab, not just leading/trailing ones. If the result is glued-together words, that's this operation working as coded; it's meant for tag lists, not prose.
- The count seems wrong - 添加编号 counts non-empty lines only, and 统计字数 counts characters including newlines. Both are slightly opinionated definitions, so sanity-check before you rely on the number.
- Chinese labels again - the dropdowns are Chinese (the pack author's native language). The mapping above covers all six options.
- You need more than two operations - that's what QWEN_TextOperation's five slots are for. This node is the quick-and-tidy pass.
It's the least exciting node in the pack and the one you'll use more than you expect. Raw model output into a prompt encoder is the exact place where invisible whitespace and stray formatting cause confusingly bad results, and this is the cheap fix.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| main_operation_1 | COMBO | 6 options: 不改变, 去换行, 去空行, 去空格, 添加编号, 统计字数 | |
| main_operation_2 | COMBO | 6 options: 不改变, 去换行, 去空行, 去空格, 添加编号, 统计字数 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| count | INT | — |