0%

Chapter 1

An LLM Call Is an HTTP Request

Welcome to Building AI Apps with Python

Hi, I’m Erik. This course is about writing Python programs that use a language model, the kind of model behind chat assistants. You already know how to send an HTTP request with requests, check its status, and read JSON out of the reply. That turns out to be most of what calling a model takes. The rest of the course is about making that call reliable: answers that arrive while the model is still writing, answers your program can trust, a model that calls your own functions, and a program that keeps working when the model misbehaves.

What you will build

The whole course grows one project: a study assistant for a set of twelve short notes about Python. By the end it has three commands. ask answers a question from the notes and says which notes it used. quiz writes checked quiz questions from one note. chat holds a study conversation that streams its answers and stays on topic.

When it is finished, asking it something will look roughly like this:

$ python study_assistant.py ask "What does return do in a function?"
return ends the function and hands a value back to the code that called it. Without a return statement, a function gives back None.

Sources: [05-functions#2]

You will not write that in one go. Each chapter adds one piece, and every piece is a function you can test on its own.

This course does not teach how models are trained or the mathematics inside them. You will treat the model as a service that takes text and returns text, and learn to build reliable programs around it.

Two course models

Every lesson talks to a service called llm-api that runs next to your sandbox. It offers two models:

  • pl-scripted is the one you will use most. It is not a real language model. It follows fixed rules and gives the same answer to the same request every time, it is free, and every check in this course is written against it. When it does not recognize a question, it replies with a description of what it received, which is useful when you want to see exactly what your code sent.

  • pl-live is a real language model, reached through a service called OpenRouter. Some lessons offer an optional “try it live” step with it. Live access comes with Guided, and it is limited: a few requests a minute, a daily allowance, and a cap on how long an answer can be. On a free account pl-live answers with status 403. You never need it to finish a lesson.

Text you send to pl-live leaves Python Land and goes to OpenRouter and the company running the model. The course asks OpenRouter to use only providers that do not keep or train on what you send, but do not paste anything private into a live request: no passwords, keys, or personal details.

How this course works

From Lesson 3 on, each chapter’s project files open in the Project tab beside the lesson, and you run them by typing commands in the Shell tab. Reading lessons like this one have no project panel. Every lesson is open to you. A free account can complete a limited number of lessons each day, and the site shows how many you have left.

Checking your work never calls a model. The checks hand your functions a stand-in for the network, as Python in Practice Chapter 11 did, so a slow or broken service cannot fail a correct answer.

Meet Monty

Monty is Python Land’s learning guide, and it sits beside every lesson. Ask it what an error means, for a second explanation, or for a hint that gets you moving without handing you the answer. When you are signed in, a free account includes 5 Monty helps a day across all courses, and Guided gives you up to 50.

Try it now. Open Monty and ask:

What is the difference between a language model and the chat app I use it through?

Which model are the checks in this course written against?

What happens to the text you send to pl-live?