Preface....5
Conventions Used in This Book....6
Using Code Examples....6
O’Reilly Online Learning....7
How to Contact Us....8
Acknowledgments....9
1. GPT-4 and ChatGPT Essentials....10
Introducing Large Language Models....10
Exploring the Foundations of Language Models and NLP....11
Understanding the Transformer Architecture and Its Role in LLMs....14
Demystifying the Tokenization and Prediction Steps in GPT Models....18
A Brief History: From GPT-1 to GPT-4....19
GPT-1....20
GPT-2....21
GPT-3....22
From GPT-3 to InstructGPT....23
GPT-3.5, Codex, and ChatGPT....27
LLM Use Cases and Example Products....29
Be My Eyes....30
Morgan Stanley....30
Khan Academy....31
Duolingo....32
Yabble....33
Waymark....33
Inworld AI....34
Beware of AI Hallucinations: Limitations and Considerations....34
Optimizing GPT Models with Plug-ins and Fine-Tuning....39
Summary....40
2. A Deep Dive into the GPT-4 and ChatGPT APIs....42
Essential Concepts....43
Models Available in the OpenAI API....44
Trying GPT Models with the OpenAI Playground....46
Getting Started: The OpenAI Python Library....52
OpenAI Access and API Key....53
“Hello World” Example....55
Using ChatGPT and GPT-4....57
Input Options for the Chat Completion Endpoint....58
Output Result Format for the Chat Completion Endpoint....66
From Text Completions to Functions....70
Using Other Text Completion Models....73
Input Options for the Text Completion Endpoint....74
Output Result Format for the Text Completion Endpoint....77
Considerations....78
Pricing and Token Limitations....78
Security and Privacy: Caution!....80
Other OpenAI APIs and Functionalities....81
Embeddings....81
Moderation Model....84
Whisper and DALL-E....89
Summary (and Cheat Sheet)....90
3. Building Apps with GPT-4 and ChatGPT....92
App Development Overview....92
API Key Management....92
Security and Data Privacy....95
Software Architecture Design Principles....96
LLM-Powered App Vulnerabilities....97
Analyzing Inputs and Outputs....98
The Inevitability of Prompt Injection....99
Example Projects....99
Project 1: Building a News Generator Solution....100
Project 2: Summarizing YouTube Videos....103
Project 3: Creating an Expert for Zelda BOTW....107
Project 4: Voice Control....114
Summary....123
4. Advanced GPT-4 and ChatGPT Techniques....124
Prompt Engineering....124
Designing Effective Prompts....125
Thinking Step by Step....133
Implementing Few-Shot Learning....136
Improving Prompt Effectiveness....138
Fine-Tuning....141
Getting Started....141
Fine-Tuning with the OpenAI API....145
Fine-Tuning Applications....149
Generating and Fine-Tuning Synthetic Data for an Email Marketing Campaign....152
Cost of Fine-Tuning....161
Summary....161
5. Advancing LLM Capabilities with the LangChain Framework and Plug-ins....166
The LangChain Framework....166
Dynamic Prompts....168
Agents and Tools....170
Memory....174
Embeddings....176
GPT-4 Plug-ins....180
Overview....182
The API....183
The Plug-in Manifest....184
The OpenAPI Specification....187
Descriptions....189
Summary....190
Conclusion....191
Glossary of Key Terms....192
Index....200
About the Authors....265
This minibook is a comprehensive guide for Python developers who want to learn how to build applications with large language models. Authors Olivier Caelen and Marie-Alice Blete cover the main features and benefits of GPT-4 and ChatGPT and explain how they work. You'll also get a step-by-step guide for developing applications using the GPT-4 and ChatGPT Python library, including text generation, Q&A, and content summarization tools.
Written in clear and concise language, Developing Apps with GPT-4 and ChatGPT includes easy-to-follow examples to help you understand and apply the concepts to your projects. Python code examples are available in a GitHub repository, and the book includes a glossary of key terms. Ready to harness the power of large language models in your applications? This book is a must.