Overview

1 Peeking inside the black box

This chapter introduces generative AI as both familiar and puzzling: while tools like ChatGPT and Copilot are easy to use, building them reveals that they behave very differently from traditional software. The book’s purpose is to help readers develop a practical mental model for designing GenAI applications, focusing on the main building blocks, how they fit together, and the limitations they bring. It also emphasizes hands-on learning through low-code development, while keeping the underlying ideas usable across tools, vendors, and frameworks.

At a high level, the chapter explains that GenAI programming is unique because an application must work around an LLM, a probabilistic black box that takes natural-language input and produces natural-language output. Unlike conventional code, which is deterministic and explicitly controlled, LLMs are non-deterministic, stateless, and pre-trained, so they do not remember prior turns or know new information unless the application supplies it. Real GenAI systems solve this by adding components such as conversation memory, external knowledge, retrieval, tools, and prompt engineering, which extend the model beyond what it can do alone.

The chapter then opens a window into how LLMs work internally, using GPT-3 as the main example. It describes a simplified view in which text is tokenized, converted into embeddings, combined into context, and used to predict the next word, then contrasts that toy explanation with the real scale of modern models built with deep neural networks, transformers, and massive training datasets. It closes by stressing that LLM knowledge is fixed at training time, so up-to-date or domain-specific information must be injected during inference or added through fine-tuning, which is why building effective GenAI applications is really about orchestrating the model with the right surrounding systems.

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 makes GenAI applications different from traditional applications?GenAI applications differ because they rely on an LLM that behaves non-deterministically and is driven by natural-language prompts, rather than fixed step-by-step code alone. As a result, developers must manage randomness, context, and supporting components around the model.
Why is an LLM described as a “magic black box”?An LLM is called a black box because it takes text in and generates text out, but its internal reasoning is not transparent. You can observe the input and output, but you cannot directly know why a specific answer was produced.
Why can’t an LLM remember past conversations by itself?LLMs are stateless, meaning they do not retain memory between calls. Each prompt is processed as a fresh request, so the application must resend relevant conversation history if it wants the model to behave as if it remembers.
How do GenAI applications simulate memory?They store earlier user inputs and model outputs, then include the relevant parts in later prompts. This makes each LLM call self-sufficient while preserving conversation context for the user.
Why do LLMs sometimes give generic answers to specific questions?Because LLMs are pre-trained on fixed datasets and do not automatically know private, recent, or company-specific information. If that knowledge is not included in the prompt or retrieved from an external source, the model may respond in a generic way.
How can an application give an LLM fresh knowledge?By attaching relevant context to the prompt, such as company policies, document snippets, or other external data. In larger systems, this is often done through retrieval methods that find the most useful information before the LLM is called.
What are the main building blocks needed for real-world GenAI applications?Besides the LLM itself, you often need memory management, knowledge retrieval, tool use, prompt engineering, and agentic structures. These components help the application stay context-aware, accurate, and useful.
How does GPT generate text one token at a time?GPT tokenizes the input text, converts tokens into embeddings, computes context from the prompt, and then selects the most likely next token. It repeats this process iteratively to produce longer completions.
What is the difference between the simplified GPT example and a real model like GPT-3?The simplified example uses a tiny vocabulary and basic calculations, while GPT-3 uses about 12,288 numbers per token, 96 layers, and 175 billion parameters. Real models rely on deep neural networks and transformers to handle context and next-token prediction at scale.
How are LLMs trained and improved over time?They are first pre-trained on massive text datasets to learn language patterns, then often refined through supervised learning and reinforcement learning from human feedback. Fine-tuning can further specialize the model for particular tasks or domains.

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