The right settings make outputs consistent for automation and lively for creative tasks.
Parameters change how the model picks each next token. You can set them in four places: /set parameter in a chat, PARAMETER in a Modelfile, the options field of an API request, or options= in the Python library. Request options override Modelfile defaults.
The ones you'll use most:
temperature: randomness. Low values (0 to 0.3) give focused, repeatable answers for extraction, classification and code; higher values (0.7 to 1) give more variety for brainstorming and writing. Ollama's default is 0.8, but many models ship their own defaults.top_pandtop_k: limit which tokens may be picked to the most likely ones. Change these rarely; adjust temperature first.num_predict: the maximum number of tokens to generate. The default -1 means no limit; set a limit to bound cost and time.stop: text sequences that end the answer immediately, such as"\n\n"or a closing tag.seed: with a fixed seed and the same prompt and settings, the output is usually repeatable, which helps testing.repeat_penalty: discourages repeating the same words; raise it slightly if a model loops.num_ctx: the context length (its own lesson).
Model creators tune defaults for their model, visible with ollama show MODEL --parameters. Start from those and change one setting at a time while testing on real examples.
Reasoning ("thinking") models often recommend specific settings in their model card. Follow them; very low temperatures can make some of these models repeat themselves.
Example
from ollama import chat
prompt = [{"role": "user", "content": "Invent a name for a coffee shop."}]
for t in (0.0, 1.0):
names = [chat(model="gemma4:e2b", messages=prompt,
options={"temperature": t, "num_predict": 12}).message.content
for _ in range(3)]
print(t, names)
# 0.0 ['Bean There', 'Bean There', 'Bean There'] (same every time)
# 1.0 ['The Daily Grind', 'Brew Haven', 'Morning Ritual'] (varies)
fixed = {"temperature": 0.7, "seed": 42}
a = chat(model="gemma4:e2b", messages=prompt, options=fixed).message.content
b = chat(model="gemma4:e2b", messages=prompt, options=fixed).message.content
print(a == b) # usually True: same seed, same output
short = chat(model="gemma4:e2b", messages=prompt, options={"stop": ["\n"]})Remember
- Set options via chat, Modelfile, API
optionsoroptions=in Python - Low temperature for automation, higher for creative work
num_predict,stopandseedbound length and aid reproducibility
Watch out for
- Tuning top_p, top_k and temperature all at once, making it impossible to tell which change helped.