Nodes/ComfyUi-Ollama-YN/My Ollama Generate Advance
ComfyUI Node

My Ollama Generate Advance

The Ollama node you'll actually reach for to write SD prompts

By wujm424606·Created 2 years ago·Updated 2 years ago· 84
My Ollama Generate Advance
    • response
    • context
    prompt1个女孩在森林里散步
    debug
    urlhttp://127.0.0.1:11434
    model
    extra_modelnone
    systemYou are creating a prompt for Stable Diffusion to generate an image. First step: understand the input and generate a text prompt for the input. Second step: only respond in English with the prompt itself in phrase, but embellish it as needed but keep it under 200 tokens.
    seed0
    top_k40
    top_p0.90
    temperature0.50
    num_predict-1
    tfs_z1.00
    keep_alive
    context

    If you only add one node from ComfyUi-Ollama-YN to a workflow, this is it. MyOllamaGenerateAdvance is the "embellish my prompt" node: you type a rough idea, a local LLM turns it into a proper Stable Diffusion prompt, and the text comes out the other side ready to wire into your CLIPTextEncode. No API key, no cloud, nothing leaving your machine.

    It earns the "Advance" in the name by doing two things the plain My Ollama Generate node doesn't: it sends a system prompt alongside your input, and it hands back Ollama's internal context array so you can chain turns together. The default system prompt is where the magic lives - it tells the model "you are creating a prompt for Stable Diffusion," to only respond in English, and to keep it under 200 tokens. That's what turns "1个女孩在森林里散步" (the shipped example) into something your checkpoint actually likes.

    How it works

    Under the hood it's the official ollama Python client talking to your local Ollama server (default http://127.0.0.1:11434). It sends prompt + system plus a handful of sampling knobs - top_k, top_p, temperature, num_predict, tfs_z - and gets back the generated text. If you don't already have the selected model, it runs ollama pull in a subprocess first, streaming progress into the ComfyUI console, and records the model in the pack's file/category.csv so it shows up in the dropdown next time.

    The context output is worth understanding, because it's not your conversation history in plain text - it's Ollama's token-context array, a list of token ids the model can resume from. That's why it flows back into the optional context input for a second call: each turn appends, and the conversation stays coherent without you pasting the whole transcript back in.

    The inputs that matter

    Most of the knobs are pass-through sampling settings with sane defaults. The ones a beginner actually touches:

    • prompt - your rough idea. Multiline, so don't be shy.
    • system - the prompt-engineering instructions. Defaults to the SD-embellisher. This is where you'd change the output style, language, or token budget.
    • temperature and top_p - lower them if the model starts rambling; 0.5/0.9 is a fine starting point.
    • extra_model - leave as none to use the dropdown, or type any Ollama library model name (e.g. llama3:latest) and it auto-downloads and runs it.
    • keep_alive - 0 unloads the model from VRAM the instant the call finishes; 60m keeps it warm for an hour. Pick 0 if you're memory-constrained, 60m if you're doing many runs.

    Outputs: response (the generated prompt) wires into your CLIPTextEncode's text input, and context wires into My Ollama Save Context or straight back into this node's own optional context input.

    Installing and getting it running

    Install via ComfyUI Manager (search "ComfyUi-Ollama-YN") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wujm424606/ComfyUi-Ollama-YN.git
    # restart ComfyUI
    

    The requirements.txt pulls in ollama, pandas, and aiohttp (pandas does the CSV bookkeeping, aiohttp powers the node's model-list endpoint). The big dependency isn't Python - it's Ollama itself. Install it from ollama.com, make sure it's actually running in the background, and download models either from the Ollama library or by typing the name in extra_model. This pack has been effectively dormant since September 2024, but that matters less than you'd think: the Ollama API it wraps is stable, and it still works.

    Where people get burned

    The dropdown of available models is built when the node loads, from ollama list filtered against the CSV. Three classic gotchas:

    1. You pull a model and it never appears in the dropdown. Add the node fresh (search for it again) or restart ComfyUI - don't use right-click "Reload," which the README warns throws an error.
    2. The :latest trap. A model name without a tag gets auto-suffixed with :latest by the code, but if you're typing into extra_model, write the full model:latest yourself or you may pull the wrong tag.
    3. "Connection refused." Ollama isn't running, or the url doesn't point at http://127.0.0.1:11434. Flip debug to enable and the console will print the exact request it's making, which makes all three easy to diagnose.
    CategoryMy Ollama

    Inputs (14)

    NameTypeDefaultDescription
    promptSTRING1个女孩在森林里散步
    debugCOMBO2 options: disable, enable
    urlSTRINGhttp://127.0.0.1:11434
    modelCOMBO0 options:
    extra_modelSTRINGnone
    systemSTRINGYou are creating a prompt for Stable Diffusion to generate an image. First step: understand the input and generate a text prompt for the input. Second step: only respond in English with the prompt itself in phrase, but embellish it as needed but keep it under 200 tokens.
    seedINT00–18446744073709550000
    top_kFLOAT400–100
    top_pFLOAT0.900–1
    temperatureFLOAT0.500–1
    num_predictFLOAT-1-2–2048
    tfs_zFLOAT1.001–1000
    keep_aliveCOMBO2 options: 0, 60m
    contextoptSTRING

    Outputs (2)

    NameTypeDescription
    responseSTRING
    contextSTRING