Nodes/comfyui-bulk-prompt/πŸ¦™ Bulk Prompt Ollama Improver
ComfyUI Node

πŸ¦™ Bulk Prompt Ollama Improver

A local LLM that improves every prompt in your batch β€” without the chat-scaffolding garbage

By sifatradsΒ·Created 3 months agoΒ·Updated 3 months agoΒ· 0
πŸ¦™ Bulk Prompt Ollama Improver
    • result
    • context
    • meta
    β—„instructionYou are an expert prompt engineer for image generation. Rewrite the following prompt to be more vivid and detailed. Output ONLY the improved prompt, with no preamble or explanation.β–Ί
    β—„urlhttp://127.0.0.1:11434β–Ί
    β—„modelβ–Ύβ–Ί
    β—„keep_alive_minutes5β–Ί
    β—„timeout120β–Ί
    β—„enabledtrueβ–Ί
    β—„trim_outputtrueβ–Ί
    β—„positiveβ€”β–Ί
    β—„contextβ€”β–Ί

    Wire a Bulk Prompt Loader into this node and every prompt in your batch gets rewritten by a local Ollama model before it ever reaches a CLIP Text Encode. That's the whole job, and it's a good one: you feed it a rough idea like "a red apple on a wooden table" and it hands back a more vivid, detailed version, offline, uncensored, free per call. The reason to care about this node specifically is that it solves the one problem that sinks every other prompt-enhancer: chat models love to wrap their answers in "Sure! Here's an improved version:" and markdown fences, and that scaffolding lands in your conditioning as literal prompt tokens if nobody strips it.

    How it works

    It uses the official ollama Python library against a running Ollama server - so Ollama is a separate process, not something loaded in-graph. Each run calls generate() with your prompt, your instruction as the system prompt, and a keep_alive value. The node is version-tolerant across ollama-python 0.4β†’0.6 and declares VALIDATE_INPUTS, so the dynamically-fetched model list passes ComfyUI's backend validation instead of throwing the classic "unknown required inputs" error on load.

    The star is trim_output (on by default). After the model replies, the node runs a real cleaning pass: leading preambles, --- rules, ``` code fences, Prompt: headers, surrounding quotes, and trailing "let me know if you'd like changes!" offers all get stripped, leaving just the prompt. The KB's writeup on local-LLM prompting calls dirty output the #1 failure mode of this category of node - a model's conversational habits bleeding into your conditioning is worse than no enhancer at all. This node bakes the fix in. Turn trim_output off and you get the raw reply if you want to see what the model really said.

    Inputs and outputs

    Set these and forget them:

    • url - default http://127.0.0.1:11434. Change it for a remote host (http://192.168.1.50:11434), then hit πŸ”„ Reconnect to refresh the model dropdown.
    • model - populated by clicking Reconnect. Pick the one you ollama pull'd.
    • instruction - the system prompt telling the model what to do. The default ("Rewrite the following prompt to be more vivid and detailed. Output ONLY the improved prompt...") is genuinely good; tighten it if you want a specific style.
    • timeout - default 120 seconds. Bump to 300+ for big models (14B+), because the first call also has to load the model into VRAM and that counts against the budget.
    • keep_alive_minutes - how long Ollama keeps the model resident after a call. -1 keeps it forever, 0 unloads immediately. If you're batch-running hundreds of prompts, this is the difference between fast and "waiting for a model load every row."
    • enabled - flip off to pass prompts through unchanged, no Ollama call. Cheap A/B toggle.

    Optional context input accepts comma-separated ints for multi-turn continuity. Outputs: result (the improved, trimmed prompt - wire it to your CLIP Text Encode), context (Ollama's context tokens, for chaining), and meta (JSON with the model, timing, token counts, and a trimmed flag - handy if you want to see how long the rewrite actually took).

    Installing it

    The one node in the pack with a dependency. The pack's requirements.txt pins ollama>=0.4.0; ComfyUI Manager will install it automatically, or do it yourself:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sifatrads/comfyui-bulk-prompt.git
    pip install ollama
    

    Then make sure Ollama is running (ollama serve) and pull a model, e.g. ollama pull qwen2.5:7b or llama3.1. The pack's __init__.py is defensive here: if the ollama package is missing, this node is silently disabled but the core loader nodes keep working - so a missing import won't take down your whole batch setup.

    Where people get burned

    • Timeouts on the first few rows - that's the model loading into VRAM. Raise timeout, or set keep_alive_minutes to -1 so it stays warm.
    • Model dropdown is empty / "No Ollama model selected." - click πŸ”„ Reconnect. The list is cached; pulling a new model in the terminal won't show up until you refresh.
    • Ollama on a different machine - you can point url anywhere reachable, and the node normalizes a bare localhost:11434 to a proper URL for you.
    • VRAM - you're now budgeting for two models at once (LLM + checkpoint). Keep the LLM small (an 8B, or 3B on tight cards) and lean on keep_alive so it doesn't sit resident when you're not batching. The KB's guidance is blunt: the job doesn't need a big reasoning model, it needs a small obedient one that follows a format and stops.
    CategoryBulkPrompt

    Inputs (9)

    NameTypeDefaultDescription
    instructionSTRINGYou are an expert prompt engineer for image generation. Rewrite the following prompt to be more vivid and detailed. Output ONLY the improved prompt, with no preamble or explanation.System prompt β€” tell the model what to do with the prompt.
    urlSTRINGhttp://127.0.0.1:11434Ollama server URL. Change this for a custom host/port (e.g. http://192.168.1.50:11434), then click πŸ”„ Reconnect.
    modelCOMBOPick a model (auto-loaded from the Ollama server at the default URL). After changing url or pulling new models, click πŸ”„ Reconnect to refresh the list.
    keep_alive_minutesINT5-1–1440Minutes Ollama keeps the model loaded after inference (-1 = keep forever, 0 = unload immediately).
    timeoutINT1205–3600Max seconds to wait for the response. Large models (e.g. 14B) need more β€” the first run also loads the model into VRAM. Use 300+ if you hit timeouts.
    enabledBOOLEANtrueIf off, the prompt passes through unchanged (no Ollama call).
    trim_outputBOOLEANtrueKeep only the prompt: strip any chat wrapper the model adds (preambles, '---'/code-fence/'Prompt:' headers, trailing offers). Turn off to use the raw reply.
    positiveSTRINGβ€”
    contextoptSTRINGOptional Ollama context (comma-separated ints) for multi-turn continuity.

    Outputs (3)

    NameTypeDescription
    resultSTRINGβ€”
    contextSTRINGβ€”
    metaSTRINGβ€”