Module 4 — Giving the AI Context
Goal: move beyond single-shot prompts.
Every prompt so far has been the same shape: one string in, one result out. The model has no memory of anything that happened before it, and nothing to look at beyond whatever text you typed into the prompt itself. This module changes both of those, one chapter at a time.
What’s in this module
- Give the AI a File. Passing an actual file, an uploaded image, a document, as part of the prompt, instead of just describing it in words.
with_file()is the method, and it opens up things a text-only prompt genuinely can’t do, like asking the model to describe an image someone just uploaded. - Multi-Turn Conversations. Every example in this book so far forgets everything the moment it’s done running. This chapter covers why that’s true (LLMs are stateless by default) and how
with_history()fixes it, building toward something that actually feels like a back-and-forth conversation instead of a string of unrelated one-off questions.
Why these two belong together
Both chapters are really answering the same underlying question: what if a single string isn’t enough context for what you’re asking? A file gives the model something to look at beyond the prompt text. History gives it something to remember beyond the current turn. Neither is a new generation method, everything here still ends in a call to generate_text() or one of its siblings, these are new ways of building up what you hand that call in the first place.
On to Chapter 15.