Ollama Option — Max Tokens
Ollama Option — Max Tokens
- options
- options
A model will happily keep writing until it runs out of context. Ollama Option - Max Tokens is the brake pedal: it caps how many tokens a single generation is allowed to produce, which in this pack is the difference between a 300-word caption and a 3,000-word essay you didn't ask for.
It's one of the pack's "option" nodes, and they all work the same way: each one takes a single parameter, wraps it into a shared OLLAMA_OPTIONS dict, and passes that dict on to the next option node in the chain until it lands in an Ollama Chat Completion's options input. Max Tokens is the one you'll actually touch, because unbounded generation is the easiest way to make a workflow feel broken.
How it works
Under the hood this node maps to Ollama's num_predict parameter - the "maximum number of tokens to generate" setting - and merges it into the options dict as the num_predict key. It's a ceiling, not a target: if the model hits a natural stopping point (end of sentence, a stop sequence), it'll stop early even if you allowed more.
The inputs and outputs
- max_tokens (required) - an INT. Defaults around 128 tokens, which is plenty for a caption or a prompt enrichment, and you can crank it into the thousands for story generation or JSON output. Raise it when the model's answers look cut off; the tell is a response that ends mid-word or a JSON blob that doesn't parse.
- options (optional) - the
OLLAMA_OPTIONSconnection from the previous option node in the chain, if you're stacking several. - options (output) - the merged dict, wired into the next option node or straight into Chat Completion.
Installing it
It ships with the ComfyUI Ollama Model Manager pack: Manager → search "Ollama Manager" → Install → restart, or git clone https://github.com/darth-veitcher/comfyui-ollama-model-manager into ComfyUI/custom_nodes and run python install.py. Python 3.12+; httpx, loguru, rich are handled for you.
Where people get burned
The main trap is thinking of this as a "response length" slider when it's really a safety cap. Set it too low and you'll wonder why the model stops mid-thought - that's the ceiling doing its job. And because it merges via the options chain, remember ordering: whatever node is last in the chain wins for a given key, so don't put two max-token nodes in the same chain. For prompt-enrichment pipelines a few hundred tokens is usually more than enough; save the long leash for actual generation work.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| max_tokens | INT | 5121–131072 | — |
| optionsopt | OLLAMA_OPTIONS | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| options | OLLAMA_OPTIONS | — |