🦙 Running Local Models with Ollama
Time to test the same puzzles (easy one) on local models running directly on your machine.
easy_puzzle = [
{"role": "user", "content":
"You toss 2 coins. One of them is heads. What's the probability the other is tails? Answer with the probability only."},
]
💡 If Ollama isn't running, open a terminal and type:
ollama serve
We will continue on Level2 folder → part1.ipynb file
▶️ Create a new code cell and run it:
# Sends a GET request to a local server running on port 11434 (commonly Ollama)
# And returns the raw response body as bytes.
requests.get("<http://localhost:11434/>").content👉 So in short, this line is typically a health check to confirm that a local server (often Ollama) is running and reachable from your notebook.
▶️ Create a new code cell and run it:
!ollama pull llama3.2▶️ Create a new code cell and run it:
# Only do this if you have a large machine - at least 16GB RAM
!ollama pull gpt-oss:20b▶️ Create a new code cell and run it:
response = ollama.chat.completions.create(model="llama3.2", messages=easy_puzzle)
display(Markdown(response.choices[0].message.content))✅ Expected Output: 0.5 ( ❌ wrong)
▶️ Create a new code cell and run it:
response = ollama.chat.completions.create(model="gpt-oss:20b", messages=easy_puzzle)
display(Markdown(response.choices[0].message.content))
✅ Expected Output: 2/3 ( ✅ Correct)