BUILD A LOCAL CHATBOT · MODULE 1 — THE SMALLEST POSSIBLE CHATBOT · bc-01 Real Python, every page

Module 1.1 · Deepens pages 2 & 3

Ten lines, start to finish

Load a tokenizer, load a model, encode a prompt, generate, decode. That's the entire mechanism — no chat formatting, no memory, nothing hidden. Run it once before any of that gets added, so you see exactly what's missing.

you typed
Hi, how are you?
raw model output (continuing the same text)
Hi, how are you? I hope you're doing well. I've been thinking about the project for a while now, and I'm really excited about the idea of creating a
Notice: the model didn't answer your question — it kept writing, as if it were the one who said "Hi, how are you?" and is now continuing to talk. That's what "no chat formatting" actually looks like.

The script

Every line, annotated

bc-01-ten-lines.py
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct")
model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct")

prompt = "Hi, how are you?"
inputs = tokenizer(prompt, return_tensors="pt")          # text -> token ids (page bc-02)
outputs = model.generate(**inputs, max_new_tokens=30)     # ids in -> more ids out (page bc-03)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))  # ids -> text again

from_pretrained is doing the "download a folder, read config.json, build the right shape, load the weights in" work from the last page — one line hides all of that. Download bc-01-ten-lines.py ⬇

What you should see

terminal
python bc-01-ten-lines.py
Hi, how are you? I hope you're doing well. I've been thinking about the project for a while now, and I'm really excited about the idea of creating a

Real output from this exact script. Nothing about "reply" or "conversation" exists yet in these ten lines — that's Module 2, once a chat template is introduced.

Try this

Change prompt = "Hi, how are you?" to prompt = "The best way to learn to code is" and re-run. It reads much more like a normal reply this time — predict why before you run it: is the model doing something different, or is this prompt just a better fit for "keep writing the same kind of text"?

So what

Without a chat template, the model isn't ignoring you — it's doing exactly what it was asked: continue this text.