My Ollama Generate Advance
The Ollama node you'll actually reach for to write SD prompts
- response
- 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
noneto use the dropdown, or type any Ollama library model name (e.g.llama3:latest) and it auto-downloads and runs it. - keep_alive -
0unloads the model from VRAM the instant the call finishes;60mkeeps it warm for an hour. Pick0if you're memory-constrained,60mif 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:
- 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.
- The
:latesttrap. A model name without a tag gets auto-suffixed with:latestby the code, but if you're typing intoextra_model, write the fullmodel:latestyourself or you may pull the wrong tag. - "Connection refused." Ollama isn't running, or the
urldoesn't point athttp://127.0.0.1:11434. Flipdebugtoenableand the console will print the exact request it's making, which makes all three easy to diagnose.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | 1个女孩在森林里散步 | — |
| debug | COMBO | 2 options: disable, enable | |
| url | STRING | http://127.0.0.1:11434 | — |
| model | COMBO | 0 options: | |
| extra_model | STRING | none | — |
| system | STRING | You 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. | — |
| seed | INT | 00–18446744073709550000 | — |
| top_k | FLOAT | 400–100 | — |
| top_p | FLOAT | 0.900–1 | — |
| temperature | FLOAT | 0.500–1 | — |
| num_predict | FLOAT | -1-2–2048 | — |
| tfs_z | FLOAT | 1.001–1000 | — |
| keep_alive | COMBO | 2 options: 0, 60m | |
| contextopt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| response | STRING | — |
| context | STRING | — |