What you’ll learn
- What an AI model is and what it does with your words
- The difference between using a chatbot and building an AI app
- The path a message takes from your app to the AI and back
- Why AI models don’t remember anything by themselves, and how apps fix that
- What AI is good at, and where it makes mistakes
What is an AI model?
An AI model is a computer program that has learned patterns from a huge amount of text. When you give it some words, it predicts good words to come next, one small piece at a time. That’s how it writes answers, explains ideas, and even writes code.
The words you send to the model are called the prompt. What comes back is called the response.
The models you’ll use in this course are called large language models, or LLMs. They run on powerful computers owned by AI companies like OpenAI and Anthropic. You don’t download them. Your program sends them messages over the internet.
Chatbot vs. AI app
When you use ChatGPT or Claude in a browser, you’re using a chatbot that someone else built. You type, it answers.
An AI app is a program you write that uses an AI model as one of its parts. Your code decides:
- What the app is for (studying, recipes, writing help)
- What instructions the AI gets before the user types anything
- What the user sees on the screen
- What gets saved, and what happens when something goes wrong
Think of the AI model as a very smart engine. Your app is the car built around it.
How a message travels
Every time someone uses your app, the same five steps happen:
- The user types a message into your app.
- Your Python code builds a request. It packs the instructions, the conversation so far, and the new message together.
- The request travels over the internet to the AI provider’s API (you’ll learn exactly what an API is in the next lesson).
- The AI model reads the request and writes a response.
- Your code receives the response and shows it to the user.
This whole trip usually takes a second or two.
Example: what a request looks like
Here’s a simplified version of what your Python code will send. It’s just a Python dictionary with a list of messages inside:
request = {
"model": "example-model",
"messages": [
{"role": "system", "content": "You are a friendly study buddy."},
{"role": "user", "content": "What is photosynthesis?"}
]
}
You already know dictionaries and lists from Python for Absolute Beginners. Each message has a role (who is speaking) and content (what they said):
- system is the instructions you give the AI. The user never sees them.
- user is what the person typed.
- assistant is what the AI answered earlier.
AI models don’t remember
This surprises almost everyone: an AI model has no memory between requests. Each request is brand new to it.
So if the user says “My name is Sam” and then asks “What’s my name?”, the model only knows the answer if your app sends the earlier messages again. That’s why the request holds a list of messages. Your app keeps the conversation in a list and sends the whole list every time.
You’ll build exactly this in Part 2. In today’s Try it widget, you can switch memory on and off and see the difference.
What AI is good at, and where it slips
AI models are great at explaining ideas, summarizing, brainstorming, rewriting text, and writing code.
They also make mistakes:
- They can sound confident while being wrong. This is called a hallucination.
- They may not know about very recent events.
- They can give different answers to the same question.
Good AI apps are designed with this in mind. For example, a study buddy app can tell users to double-check important facts.
Common mistakes
- Thinking the AI runs on your computer. It runs on the provider’s computers. Your app sends it messages over the internet, so you need an internet connection.
- Expecting the AI to remember on its own. It doesn’t. Your app has to send the conversation each time.
- Mixing up system and user messages. System messages are your instructions to the AI. User messages are what the person types.
- Trusting every answer. AI can be wrong while sounding sure. Test your app and double-check facts that matter.
- Forgetting the quotes in dictionaries. Keys like “role” and “content” are strings, so they need straight quotes.
Try it, exercise and practice file
Try it: Follow a Message
Students send a message and watch it light up five boxes in turn: You, Your app, Internet, AI model, Your app. Below the chat, they see the exact Python request dictionary their app sent. A Memory switch shows the key idea of the lesson: with memory on, the AI knows their name; with memory off, the app sends only the newest message and the AI forgets. Quick-message buttons (“Hi! My name is Sam.”, “What’s my name?”) make the challenge easy to try.
Placement: after “Common mistakes,” before “Hands-on exercise.” Add a heading “Try it: Follow a Message,” then a Custom HTML block with the whole contents of lesson2_try_it_widget.html. Install it the same way as Lesson 1 (WP Editor, logged in as an admin).
Text above the widget: Send a message and watch it travel through each step. Then try the challenge: tell the AI your name, ask “What’s my name?”, switch memory off, and ask again. Look at the request box each time and count the messages.
Hands-on exercise
- Download ai_app_flow.py into your ai-app-course folder and open it in VS Code.
- Run it once before changing anything. Every check fails, and that’s expected.
- TODO 1: set SYSTEM_PROMPT to one sentence of instructions for your AI.
- TODO 2: finish build_request so the messages list holds the system message, then the history, then the new user message.
- TODO 3: finish remember so it appends the user message and the AI’s reply to history.
- Run the file again. Watch the demo: the second request should send 4 messages, and the AI should answer “Your name is Sam.”
- Bonus: comment out the remember line in run_demo, run it again, and see the AI forget.
Practice file
- ai_app_flow.py (give to students): three TODOs, a pretend AI model that only knows what’s in the request it receives, a two-message demo, and five automatic checks. No API key or internet needed.
- ai_app_flow_solution.py (for you only): the finished version for support questions. Don’t attach it to the lesson.
You’re done when: the last line says “All 5 checks passed! You built your first AI request.”
Example of a finished run:
You: Hi! My name is Sam.
(your app sent 2 message(s) to the AI)
AI: Nice to meet you!
You: What's my name?
(your app sent 4 message(s) to the AI)
AI: Your name is Sam.
Check 1: PASS - SYSTEM_PROMPT has instructions in it
Check 2: PASS - build_request works with no history
Check 3: PASS - build_request includes the history in order
Check 4: PASS - remember adds the user and assistant messages
Check 5: PASS - the AI remembered Sam's name in the demo
All 5 checks passed! You built your first AI request.
Solution code for TODO 2 and TODO 3 (for your support replies):
messages = [{"role": "system", "content": system_prompt}]
messages += history
messages.append({"role": "user", "content": user_message})
history.append({"role": "user", "content": user_message})
history.append({"role": "assistant", "content": reply})
Key takeaways
- An AI model predicts good words to come next. You send a prompt, and it sends back a response.
- The model runs on the provider’s computers. Your app talks to it over the internet.
- An AI app is your own program that uses a model as one part, the way a car uses an engine.
- A request is a Python dictionary with a list of messages. Each message has a role (system, user or assistant) and content.
- AI models don’t remember. Your app keeps the conversation in a list and sends it every time.
- AI can be confidently wrong (a hallucination), so good apps are designed with that in mind.