
Call a Local Language Model from Python
Send prompts to a model running on your own machine through Ollama’s local HTTP API.
20 min 2 steps Local AI
A four-part prompt pattern — role, task, context, format — that turns vague answers into usable ones.
10 min4 stepsPublished

Tell the assistant who it should act as and exactly what to produce. “You are a travel planner. Plan a two-day visit to Novi Sad” beats “Novi Sad ideas?”.
Budget, audience, constraints and what you already tried. The model cannot guess these — and they change the answer the most.
Request a table, a numbered list or a fixed length. Structured answers are easier to verify and reuse.
Role: You are a patient maths tutor.
Task: Explain percentages to a 12-year-old.
Context: They understand fractions but not decimals.
Format: 3 short steps and one practice question.Reply with what to change: “shorter”, “more examples”, “explain step 2 differently”. Then verify any facts that matter.
Add more specific context and an example of what a good answer looks like.
Ask for sources, then check them yourself. Do not rely on unsourced facts.

Send prompts to a model running on your own machine through Ollama’s local HTTP API.
20 min 2 steps Local AI