Ollama Exercises

These Ollama exercises help you practise everything from this tutorial. Try each one yourself before looking at the hint.

Exercise 1: A Custom Assistant

Write a Modelfile for a "Git helper" that only answers Git questions, uses temperature 0.2 and refuses other topics politely.

FROM llama3.2
SYSTEM "You are a Git expert. Only answer questions about Git. For anything else, say you can only help with Git."
PARAMETER temperature 0.2
ollama create githelper -f Modelfile
ollama run githelper "How do I undo my last commit?"
-> Use git reset --soft HEAD~1 to undo the commit but keep your changes staged.
(Sample response.)

Exercise 2: Chat with Memory

Write a Python loop that reads input, appends it to a messages list, calls chat, prints the reply and appends it too.

from ollama import chat

messages = []
while True:
    text = input("You: ")
    if text == "quit":
        break
    messages.append({"role": "user", "content": text})
    reply = chat(model="llama3.2", messages=messages).message
    messages.append(reply)
    print("Bot:", reply.content)
You: My name is Hina.
Bot: Nice to meet you, Hina!
You: What is my name?
Bot: Your name is Hina.
(Sample response.)

Exercise 3: Invoice Extractor

Use a JSON schema in format to extract invoice_number, total and currency from a pasted invoice text. Validate with Pydantic and print the total.

Exercise 4: FAQ Search

Embed 20 FAQ entries with nomic-embed-text, then answer user questions by finding the closest entry and asking a chat model to rewrite it in a friendly tone.

More Project Ideas

  • A command-line commit message generator that reads git diff.
  • A Laravel admin page that summarises customer support tickets.
  • A Node.js Discord or Slack bot backed by a local model.
  • A private "chat with my notes" app using embeddings and Open WebUI.
  • A benchmark script comparing tokens per second across models with ollama ps.

Frequently asked questions

What is a good first Ollama project?

A small command-line or web chatbot with a custom system prompt. It covers models, the chat API and conversation history.

How can I measure Ollama speed?

Use ollama run with --verbose, or divide eval_count by eval_duration from the API response to get tokens per second.

What should I learn after Ollama?

Prompt engineering, RAG with a vector database, and evaluation, so you can measure whether your AI features actually work.