HF Transformers unpack conversation
Get the LLM's answer out as plain text
- conversation
- role
- text
- image
The unglamorous node that makes the pack's LLM side actually usable. A HuggingFace conversation is a list of message dicts - roles, content, sometimes multi-part content with images - and nothing in ComfyUI natively knows how to read that. HFTUnpackConversation pulls one message out of a conversation and hands you its role, text, and image as separate outputs. It's the "get the answer out" step, and for most workflows it's the last node in the LLM chain.
Inputs:
- conversation - an
HFT_CONVERSATION. Feed it the conversation output ofHFTRunPipeline(the generated reply) or chain several in for history. - index - which message to unpack. Default
-1, which in Python indexing means the last one - exactly the message you want when you just ran the model and its answer is at the end. Use0for the first message,-2for the second-to-last, and so on. Range is capped at ±1024.
Outputs: role (STRING), text (STRING), image (PIL_IMAGE). Wire the text straight into a CLIPTextEncode or a prompt input, and that's the whole loop closed: system prompt in, enhanced prompt out, no API, no leaving the graph.
How it works
It's a tolerant little parser. It handles three message shapes, because Transformers conversations aren't one shape: a bare string, a dict with a content string, and a dict whose content is a list of {type: text|image, ...} parts (the multi-modal form that HFTCreateConversation builds when you include an image). Whichever shape a message is, the node finds the role, the text, and any image in it and hands them out. Whatever it can't find comes back as None - a role-less or image-less message doesn't error, it just gives you empty outputs.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/Yahweasel/ComfyUI-HF-Diffusers
or search ComfyUI-HF-Diffusers in ComfyUI Manager, then restart. requirements.txt pins diffusers~=0.36.0.
Gotchas
- The image output is PIL. If the assistant replied with an image and you want it in native ComfyUI format, you need the PIL bridge (
ComfyUI_Ib_CustomNodes), same as everywhere in this pack. -1is the whole point. People type1expecting "the last message" and get the second message instead, because this uses real Python list indexing. If your unpacked text looks wrong, check the index.- It unpacks one message, not the whole transcript. Want the full conversation as text? You'd chain multiple unpack nodes or use
raw_resultfromHFTRunPipeline. For the common case - the model just answered - the default does exactly what you want.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| conversation | HFT_CONVERSATION | — | |
| index | INT | -1-1024–1024 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| role | STRING | — |
| text | STRING | — |
| image | PIL_IMAGE | — |