Overview

1 Peeking inside the black box

Generative AI applications feel familiar when we use tools like ChatGPT, but building them reveals a very different kind of programming. Unlike traditional software, where code defines a deterministic sequence of steps, GenAI systems must handle natural-language inputs and non-deterministic outputs from a language model. The chapter explains that successful GenAI applications are not just “LLM in, answer out” systems; they require orchestration around the model so the application can preserve context, inject relevant knowledge, trigger actions, and shape behavior for real-world use.

The chapter’s main idea is that an LLM is a powerful but limited black box: it is probabilistic, stateless, not inherently explanatory, and trained on fixed knowledge. To make an application seem conversational or informed, the developer must supply conversation history, relevant documents, or other external context each time the model is called. This is how systems like ChatGPT and Copilot appear to remember users or know company-specific information—by combining the LLM with memory, retrieval, tools, and other components that extend what the model can do on its own.

The chapter then peeks under the hood of an LLM by describing it as a text-completion engine built from machine learning stages. In a simplified view, text is tokenized, converted into embeddings, transformed into context, and used to predict the most likely next token; in a real model like GPT-3, these steps are implemented with massive neural networks, transformers, and extensive pre-training on huge datasets. The chapter closes by emphasizing that model knowledge is static unless refreshed through techniques such as prompting, retrieval, or fine-tuning, and that the rest of the book will teach how to combine these pieces into practical, context-rich GenAI applications.

GenAI applications have an LLM (Magic Black Box) somewhere.
The magic box. Gets text as input and generates text as output.
LLM relationships: every chat is a first date.
Taming the GenAI beast.
The three types of machine learning: Unsupervised, supervised, and reinforcement.
The learning stages of ChatGPT.
Words are numbers in the eyes of an LLM.
Given a prompt, you can calculate the context.
Guess the next best word by combining embeddings with context.
The GPT sentence completion process.
How a GPT architecture generates sentences.
The two stages of GPT-3. First, it gets trained, and then the sentence completion is inferred.
Enhancing a pre-trained model through fine-tuning.

FAQ

What is the main goal of Chapter 1, “Peeking inside the black box”?The main goal is to help you understand how GenAI applications are built. The chapter focuses on the practical building blocks, how they fit together, the problems they solve, and their limitations, so you can develop a clear mental model for designing real-world GenAI apps.
How is a GenAI application different from a traditional program?A traditional program follows explicit, deterministic code instructions in a formal programming language. A GenAI application, by contrast, includes an LLM that works probabilistically and is instructed through natural language prompts, which makes its behavior less predictable.
Why is an LLM described as a “magic black box”?Because it takes text as input and generates text as output, but its internal reasoning is not directly visible or fully explainable. You can observe the input and output, but not exactly why a specific answer was produced.
What are the four key characteristics of LLMs mentioned in the chapter?LLMs are non-deterministic, not explanatory, stateless, and pre-trained. That means they produce probabilistic outputs, their inner workings are opaque, they do not remember previous calls by default, and their knowledge is fixed after training.
Why do real GenAI apps seem to remember conversation history if LLMs are stateless?Because the application, not the LLM itself, stores prior conversation history and sends it back with each new request. This makes the LLM appear to remember, even though each call starts from a clean slate.
How do GenAI applications provide fresh or private knowledge to an LLM?They include the relevant knowledge in the prompt when needed, or retrieve the right information from a document repository and attach it to the query. This lets the model answer using up-to-date or domain-specific context it did not learn during pre-training.
What extra components do GenAI applications need beyond the LLM itself?They often need memory management, retrieval of external knowledge, tool use, prompt engineering, and sometimes agent-like structures. These components help extend the LLM’s capabilities and make the application useful in real scenarios.
How does the chapter explain GPT’s sentence-completion behavior?It presents GPT as an advanced autocomplete system that predicts the next best token based on the prompt. The model converts text into tokens and embeddings, calculates context, and selects the most likely next token repeatedly to build a completion.
What are the three main stages of training described for ChatGPT?The chapter describes unsupervised learning to learn language patterns, supervised fine-tuning on conversation examples, and reinforcement learning from human feedback (RLHF) to improve responses through human evaluation and feedback.
Why is keeping knowledge up to date important in GenAI systems?Because a pre-trained model’s knowledge is fixed up to its training cutoff date. To answer with recent or real-time information, the application must enrich prompts or retrieve fresh data dynamically, rather than relying only on the model’s original training.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Applications ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Applications ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Applications ebook for free