- Preface — Why I Wrote This Book
- Getting the companion code
- Chapter 0 — Starting here
- Section 1 — How language models work
- Chapter 1 — What a language model is
- Chapter 2 — Tokens, vocabularies, and context
- Chapter 3 — Inside the transformer
- Chapter 4 — How a model is trained
- Chapter 5 — How a model generates
- Chapter 6 — Embeddings and semantic similarity
- Chapter 7 — Multimodal models
- Section 2 — Working with models from PHP
- Chapter 8 — Talking to a model over HTTP
- Chapter 9 — Prompting as engineering
- Chapter 10 — Getting structured output
- Chapter 11 — Tools and function calling
- Chapter 12 — Representing your data efficiently
- Chapter 13 — Memory and conversation state
- Chapter 14 — Prompt and context optimization
- Section 3 — Architecture patterns for AI features
- Chapter 15 — Retrieval-augmented generation
- Chapter 16 — Retrieval depth
- Chapter 17 — Agents and multi-step reasoning
- Chapter 18 — Queues, jobs, and real-time delivery
- Chapter 19 — Designing the abstraction layer
- Chapter 20 — Choosing and running models
- Section 4 — Running models locally
- Chapter 21 — The Unified Memory revolution: breaking the VRAM wall
- Chapter 22 — Ollama: a model on your machine in ten minutes
- Chapter 23 — llama.cpp and llama-server
- Chapter 24 — vLLM and high-throughput GPU serving
- Chapter 25 — NVIDIA Triton Inference Server and operational deployment
- Appendices
- Appendix A — HTTP API anatomy
- Appendix C — Model reference
- Appendix D — Vector store and search engine reference
- Appendix E — Hardware sizing and unified memory reference
- Appendix G — Serving and quantization reference
- Appendix K — Glossary
- Appendix L — Companion app, local model, and workstation setup
- Appendix N — Self-check answers
- Where to go from here: Volume 2
- Sample chapter from Volume 2 — Chapter 32: Direct and indirect prompt injection
The Foundations of Large Language Models
How Models Work and How to Build with Them in PHP, from Raw HTTP Calls to RAG, Agents, and Local Models
Stop treating large language models as magic. Learn how they actually work, from tokens to transformers, then build real AI features in Laravel over raw HTTP: prompting, structured output, tools, RAG, and agents, all running free on your own machine with Ollama.
Minimum price
$29.00
$39.00
You pay
Author earns
Buying multiple copies for your team? See below for a discount!
About
About the Book
Most AI tutorials give you a package and a one-line call, and the model stays a black box. This book shows you what’s underneath. You’ll learn what a large language model actually is: a stateless function that takes text and predicts the next token, reached over HTTP. Then you’ll build real features on top of it in Laravel, with nothing hidden.
The book is principles first and packages last. You start with how models work: tokens, the transformer, how training and generation work, embeddings, and multimodal input. Next you call models from plain PHP and Laravel’s HTTP client. Along the way you’ll handle prompting as engineering, structured output with validation and repair loops, tool calling and MCP, conversation memory, and prompt caching. After that come the architecture patterns: retrieval-augmented generation with pgvector, rerankers and document parsing, agents, queues and streaming, and a provider-agnostic abstraction layer. The last section covers running models on your own hardware with Ollama, llama.cpp, vLLM, and NVIDIA Triton, plus an honest look at unified memory and GPU sizing.
Everything runs locally and for free by default. OpenAI, Anthropic, and Google are shown side by side as options, never as requirements. Every hands-on step builds Ledgerly, a companion invoicing app whose support assistant grows chapter by chapter. Its code is in a public GitHub repository with a tag for every chapter, so you can check out the app exactly as any chapter leaves it.
Volume 1 takes you from beginner to intermediate across 26 chapters (Chapter 0 through 25). It includes reference appendices, a glossary, and answers to every chapter’s self-check questions. It ends with a full sample chapter from Volume 2 on prompt injection. You should be comfortable with PHP and Laravel. You don’t need any AI background.
The series continues with Volume 2, Running, Training and Securing Large Language Models, and Volume 3, Projects, Lifecycle, and Reference.
Categories
Feedback
Team Discounts
Team Discounts
Get a team discount on this book!
Up to 3 members
- Minimum price
- $79.00
- Suggested price
- $99.00
Up to 5 members
- Minimum price
- $116
- Suggested price
- $156
Up to 10 members
- Minimum price
- $203
- Suggested price
- $273
Up to 15 members
- Minimum price
- $290
- Suggested price
- $390
Up to 25 members
- Minimum price
- $435
- Suggested price
- $585
Author
About the Author
Jeremy Kavuncuoglu is a software engineer and technical lead with a decade of PHP and AWS experience. He builds HIPAA-compliant, high-volume systems powered by language models, and leads security and compliance work. He wrote this series for the developers he works with: people who ship web applications and want to understand AI well enough to build with it, not just call it.
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.