Learning Hub/AI App Development/Session 1

Session 1 of 5 · 60 minutes

How AI Apps Work

See the shape of every AI app: input, a model, and output. Plan an app idea and sketch how it will work.

Goals

By the end of this session you can:

  • Describe an AI app as input, model and output
  • Explain what an API is and how an app uses one
  • Name three things AI models are good at and three things they get wrong
  • Write a one-page plan for an AI app idea

Words to know

AI model
A program trained on lots of examples that turns an input into an output, such as text, an image or a prediction.
prompt
The instructions and information you send to an AI model.
API
A way for one program to ask another program to do something, like a restaurant menu and waiter.
hallucination
When an AI model gives an answer that sounds confident but is wrong or made up.
app
A program that real people use to get something done.

The lesson

Step 1: Every AI app has three parts

Think about a translation app. You type a sentence. Something figures out the meaning and matches it with another language. The new sentence appears on your screen.

Almost every AI app follows the same shape:

  1. Input: what the user gives the app (text, a photo, a voice recording).
  2. Model: the AI that turns the input into something useful.
  3. Output: what the app shows or does with the result.

The model is only one part. The app is everything around it: the screen, the code that connects the parts, and the checks that make the result safe and useful. That is the part you will build.

Step 2: A pretend model

In this workshop we’ll start by writing a pretend model, a simple Python function that stands in for a real one. It lets us build and test the whole app without any special accounts.

Python
def ask_model(prompt):
    # A real model would think about the prompt.
    # Our pretend model just returns a fixed reply.
    return "I am a pretend model. You asked: " + prompt

user_input = "What is photosynthesis?"
answer = ask_model(user_input)
print(answer)
Output
I am a pretend model. You asked: What is photosynthesis?

Later we will swap ask_model for a real one. Because the rest of the app only calls ask_model(prompt), nothing else has to change. That is good design.

Step 3: What is an API?

How does your app talk to a model that runs on a different computer? Through an API.

Think of a restaurant. You (the app) don’t walk into the kitchen. You tell the waiter (the API) what you want, using the menu. The waiter brings your request to the kitchen (the model) and brings back the food (the answer).

In code, an API request is usually:

  1. You send a request: a message that says what you want.
  2. The service sends back a response: the answer, often as structured data.

Here is what a request and response might look like as Python dictionaries:

Python
request = {"prompt": "Explain gravity to a 9-year-old"}
response = {"text": "Gravity is the invisible pull that keeps us on the ground."}

print(response["text"])
Output
Gravity is the invisible pull that keeps us on the ground.

Step 4: Strengths and limits

Modern language models are good at:

  • Explaining things in simple words.
  • Rewriting, summarizing and translating text.
  • Brainstorming ideas.

They also get things wrong:

  • They can hallucinate: state false things with total confidence.
  • They can reflect bias from the data they learned from.
  • They don’t know about events after their training, and may not know your local context.

So, a good AI app never treats the model’s answer as automatically true. It helps the user check it, and it is honest that an AI made it.

Try it: Ask any AI chat tool a question about something you know very well, such as your school or your own village or neighborhood. Did it get everything right?

Step 5: Plan before you build

Before writing code, write a plan. Answer these questions on one page:

  1. Who is the app for?
  2. What problem does it solve?
  3. Input → Model → Output. What goes in and what comes out?
  4. What could go wrong? And how will you check?
  5. What will the screen look like?

Good ideas for a first AI app are small and specific, like “a helper that explains a science word in simple language”, or “a bot that quizzes me on my vocabulary list”.

For the rest of this workshop you will build your app step by step.

Exercise

Spot the three parts

  1. Pick three apps you use that involve AI: a translator, a photo filter, a voice assistant, a recommendation list.
  2. For each, write the input (what you give it), the model's job (what it figures out) and the output (what you get back).
  3. For one of them, write what could go wrong if the model gets it wrong.
Need a hint?

Example: translator. Input: a sentence in Swahili. Model's job: find the matching English. Output: the English text.

Small project

One-page app plan

Design an AI app that solves a real problem for people you know. You will build a version of it over the next four sessions.

  1. Write one sentence: who is it for and what problem does it solve?
  2. Fill in the three parts: input, model's job, output.
  3. List three things that could go wrong and how you'd check the answer is right.
  4. Sketch the screen on paper: what does the user see and do?
  5. Pick a name. Share your plan with a partner and ask for one improvement.

Stretch it: Write the app's first function in Python: def ask_model(prompt): that returns a pretend answer.

Quiz

Check your understanding

Pick one answer for each question. Your score appears right in the page; nothing is sent anywhere.

  1. Question 1Every AI app can be described as…
  2. Question 2What is an API?
  3. Question 3An AI gives a confident answer that is false. This is called…
  4. Question 4Which is the best habit when using AI answers for something important?
  5. Question 5Which is a good first step when starting an AI app?