Skip to content

AI basics: how a model works, in 30 minutes

For freshers, and for anyone who has used ChatGPT but never built with a model. No maths, no ML background. Read this before the first hour; it explains the words every lab uses.

Time: about 30 minutes: 20 reading, 10 running four small calls. Needs: the setup in step 1 of the README for section 4. You can read the rest without it.

1. Using AI vs building with AI (5 min)

Using AI Building with AI
Who talks to the model You, in a chat window Your code, thousands of times a day
What comes back Prose you read and judge Data your code acts on: a label, an order line, a price lookup
When it's wrong You notice and ask again Nobody notices, unless your code checks
What it knows What you typed What your code puts in each call: rules, documents, live data
The skill Asking well Designing the call, checking the answer, measuring how often it's right

This course teaches the right column. Coding assistants (tools that help you write code) are the left column, even when the output is code: useful, but not what this course is about.

2. What a model is (5 min)

A large language model (LLM) is a program that, given some text, predicts the next small piece of text, then the next, until it decides to stop. It learned to do that once, from a huge amount of public text. That training is done; you don't repeat it. You only send it text and read what comes back.

Three things follow, and they explain most surprises:

  • It knows language and general facts, not your business. It has never seen your price list, your customers or today's stock. Ask anyway and it will write something that sounds right.
  • Its knowledge stops at a date. Anything after its training (today's prices, a new product) it doesn't know.
  • It writes the likely answer, not the checked one. There is no lookup and no fact check inside. Fluent and correct are different things.

Analogy: a very well-read new hire on day one. Fast, articulate, knows how the world works in general, and has never seen a single document from your company. They'll answer anything you ask, so what you hand them matters.

3. Six words you'll meet in every lab (10 min)

Word What it means Why a builder cares
Token A piece of a word (roughly ¾ of an English word). Models read and write tokens. You pay per token and wait per token. Hinglish and Hindi take more tokens per word than English.
Context window The most tokens one call can hold: your instructions, documents, history and the answer together. Too much and the call fails or the model loses track. You choose what goes in.
Stateless The model remembers nothing between calls. A chat "remembers" only because code resends the history every time, and pays for it every time.
Temperature How much randomness goes into picking the next token. 0 = the same answer each time. Use 0 for anything your code reads. Higher only for drafts a person edits.
Hallucination A confident answer that isn't true: a made-up price, rule or citation. You can't prompt it away. You reduce it by giving the facts in the call, and you catch it with checks in code.
Structured output Asking the model for JSON in a fixed shape (a schema) instead of prose. This is the step from chatting to building: your code gets fields it can check and use.

More terms, one line each: Glossary.

4. Try it: four calls (10 min)

Start Python from the ai-learning folder (source .venv/bin/activate, then python) and paste each block. door is the course's one way to call a model; it uses Ollama on your laptop unless you've set up another provider. Your answers will differ from ours (qwen3:8b), and that is part of the lesson.

Call 1: one call, counted in tokens.

import door
r = door.chat([{"role": "user", "content": "In one sentence: what is a TMT bar?"}])
print(r.text)
print(r.in_tokens, r.out_tokens, r.ms)   # tokens in, tokens out, milliseconds

We got a good one-line answer, 27 30 6809: 27 tokens in, 30 out, about 7 seconds on a laptop. Run it again and it takes about 2 seconds: the first call loads the model into memory. The one sentence of answer cost about as many tokens as the question.

Call 2: it doesn't know your business, so give it the facts.

q = "What does a 50 kg bag of Acme Cement PSC cost on Acme Build today? Answer in one line."
print(door.chat([{"role": "user", "content": q}]).text)

facts = ("Acme Build price list (today): CEM-ACM-PSC Acme Cement PSC, 50 kg bag, Rs 365. "
         "Answer only from this list; if it isn't there, say so.")
print(door.chat([{"role": "system", "content": facts}, {"role": "user", "content": q}]).text)
print(door.chat([{"role": "system", "content": facts}, {"role": "user", "content": "And a 12 mm TMT bar?"}]).text)

We got:

A 50 kg bag of Acme Cement PSC costs $12.50 on Acme Build today.
A 50 kg bag of Acme Cement PSC costs Rs 365 on Acme Build today.
The 12 mm TMT bar is not listed in the provided price list.

The first answer is a hallucination: confident, specific and invented, in the wrong currency. With the facts in the call it is right, and it says so when a fact is missing. The third call never saw the cement question: every call stands alone, and it made sense of "And a 12 mm TMT bar?" only because the price list was in that call too. Giving the model the right facts at question time is the idea behind tool calling and RAG.

Call 3: temperature.

ask = [{"role": "user", "content": "Suggest one name for a new paint brand. Just the name."}]
for _ in range(3):
    print(door.chat(ask, temperature=1.0).text)   # varied
for _ in range(2):
    print(door.chat(ask).text)                    # door's default is 0: the same each time

We got Lumira, Aurelia Paints, Luminaire, then Velora Paints twice. Variety is good for brainstorming and bad for anything your code reads.

Call 4: from chatting to building.

from pydantic import BaseModel

class Order(BaseModel):
    product: str
    quantity: int
    unit: str

msg = [{"role": "user", "content": "Bhai 40 bag cement bhej do kal tak"}]
print(door.chat(msg).text)                          # prose
print(door.chat(msg, schema=Order).parse(Order))    # data

Without a schema we got a friendly Hinglish reply promising to check with "my supplier": nice to read, useless to code. With the schema: product='Cement' quantity=40 unit='bags'. Now code can look up the price, check stock and credit, and ask the buyer to confirm. The model reads the language; code does the business.

5. The building blocks, and where the course teaches them

Every AI feature in this course is a few of these, joined by ordinary code:

Block The problem it solves Topic
Prompt and structured output Turn messy text into data your code can trust prompting
Tool calling The model needs live data (stock, price, credit): it asks, your code fetches llm-api
RAG (retrieval) The answer is in your documents: find the right passages, put them in the call, cite them rag
MCP Package your tools once so any AI app can use them mcp-server
Agent The steps depend on what the model finds: a loop of think, call a tool, check agents, multi-agent
Guardrails, evals, tracing, cost Know it's safe, know it's right, see what happened, know what it costs rnr

Two rules run through all of them: the model proposes, code decides (prices, stock and money live in code), and no eval, no ship (a score on fixed test cases, not a demo).

6. Check yourself

Answer in a sentence each before you move on. If one is hard, reread its section.

  1. Why did the first price answer in call 2 come back confident and wrong?
  2. A chatbot seems to remember your name from earlier in the chat. Where is that memory, really?
  3. Your code reads the model's answer and creates an order. Which temperature, and why?
  4. What changed between the two answers in call 4, and why does it matter to your code?
  5. Name one thing that should never be decided by the model alone, and say where it belongs instead.

Next

  • New to Python? python-basics first: every lab runs in seconds.
  • Then the first hour: the prompting labs, which go deeper on everything in section 4.
  • Want to know what you'll be able to do at the end, and what comes after? Skills ladder.