Common Scenarios & Code Samples
Quick one‑off query
ollama run llama2 "Write a haiku about sunrise."
Running with a custom temperature and max tokens
ollama run phi3 --temperature 0.4 --num-predict 64 "Summarise the following article in three bullet points:\n\n$(cat article.txt)"
Serve the API on a non‑standard port with GPU 1 only
ollama serve --port 8080 --gpu 1 --keep-alive 600
Pull a model and then delete it
ollama pull mistral --pull
# Verify it exists
ollama list
# Remove the model when you no longer need it
ollama rm mistral
Create a custom model from a Modelfile
# my-modelfile.txt FROM llama2 SYSTEM "You are a helpful coding assistant." TEMPLATE "{{ .Prompt }}"
# Build the model
ollama create my‑assistant -f my-modelfile.txt
# Use it
ollama run my‑assistant "Explain closures in JavaScript."
Benchmark a model
ollama run llama3 --benchmark 20 --num-predict 256 "Translate the following sentence to French: The quick brown fox jumps over the lazy dog."
Pipe JSON output into jq
ollama run llama2 --json "Give me a JSON object with fields name, age, and city." | jq