Cheatsheet 11 — Ollama Commands

Easiest local inference. Full: Phase 6.04.

Essentials

ollama pull llama3.1:8b           # download
ollama run llama3.1:8b            # interactive chat
ollama run llama3.1:8b "Summarize: ..."   # one-shot
ollama list                       # local models
ollama ps                         # running models + memory
ollama rm llama3.1:8b             # delete
ollama show llama3.1:8b           # model details (params, quant, template)

OpenAI-compatible API (port 11434)

curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"llama3.1:8b","messages":[{"role":"user","content":"hi"}],"temperature":0}'
# Use the OpenAI SDK pointed at Ollama
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
r = client.chat.completions.create(model="llama3.1:8b",
        messages=[{"role":"user","content":"hi"}])

Model tags = quant/size

  • llama3.1:8b (default quant, usually Q4), llama3.1:8b-instruct-q8_0, llama3.1:70b, etc.
  • Check available tags on the Ollama library; tag suffix = quantization (cheatsheet 06).

Customize with a Modelfile

# Modelfile
FROM llama3.1:8b
PARAMETER temperature 0
PARAMETER num_ctx 8192
SYSTEM "You are a terse code assistant."
ollama create mybot -f Modelfile
ollama run mybot

Useful env / flags

SettingWhat
OLLAMA_HOSTBind address (e.g., 0.0.0.0:11434 for remote)
OLLAMA_NUM_PARALLELConcurrent requests
OLLAMA_KEEP_ALIVEHow long to keep a model in memory
num_ctx (PARAMETER)Context window
num_gpu (PARAMETER)Layers to offload to GPU

When to use Ollama vs alternatives

  • Ollama: quick local dev, an OpenAI-compatible local endpoint, embedding into apps.
  • Need max control / edge / custom buildsllama.cpp.
  • Need GPU production throughputvLLM.

Next: 12 — API Provider Comparison · Full: Phase 6.04