... Preface ... 15
... Objective of This Book ... 15
... Target Audience ... 16
... Prerequisites: What You Should Already Know ... 16
... Structure of This Book ... 17
... How to Use This Book Effectively ... 20
... Downloadable Code and Additional Materials ... 21
... System Setup ... 21
... Acknowledgments ... 27
... Conventions Used in This Book ... 28
1 ... Introduction to Generative AI ... 29
1.1 ... Introduction to Artificial Intelligence ... 30
1.2 ... Pillars of Generative AI Advancement ... 35
1.3 ... Deep Learning ... 38
1.4 ... Narrow AI and General AI ... 40
1.5 ... Natural Language Processing Models ... 42
1.6 ... Large Language Models ... 47
1.7 ... Large Multimodal Models ... 51
1.8 ... Generative AI Applications ... 52
1.9 ... Summary ... 54
2 ... Pretrained Models ... 57
2.1 ... Hugging Face ... 58
2.2 ... Coding: Text Summarization ... 60
2.3 ... Exercise: Translation ... 62
2.4 ... Coding: Zero-Shot Classification ... 64
2.5 ... Coding: Fill-Mask ... 67
2.6 ... Coding: Question Answering ... 68
2.7 ... Coding: Named Entity Recognition ... 70
2.8 ... Coding: Text-to-Image ... 71
2.9 ... Exercise: Text-to-Audio ... 72
2.10 ... Capstone Project: Customer Feedback Analysis ... 74
2.11 ... Summary ... 77
3 ... Large Language Models ... 79
3.1 ... Brief History of Language Models ... 80
3.2 ... Simple Use of LLMs via Python ... 81
3.3 ... Model Parameters ... 93
3.4 ... Model Selection ... 96
3.5 ... Messages ... 99
3.6 ... Prompt Templates ... 101
3.7 ... Chains ... 104
3.8 ... Safety and Security ... 117
3.9 ... Model Improvements ... 124
3.10 ... New Trends ... 125
3.11 ... Summary ... 130
4 ... Prompt Engineering ... 133
4.1 ... Prompt Basics ... 134
4.2 ... Coding: Few-Shot Prompting ... 142
4.3 ... Coding: Chain-of-Thought ... 144
4.4 ... Coding: Self-Consistency Chain-of-Thought ... 145
4.5 ... Coding: Prompt Chaining ... 149
4.6 ... Coding: Self-Feedback ... 151
4.7 ... Summary ... 155
5 ... Vector Databases ... 157
5.1 ... Introduction ... 157
5.2 ... Data Ingestion Process ... 159
5.3 ... Loading Documents ... 160
5.4 ... Splitting Documents ... 167
5.5 ... Embeddings ... 182
5.6 ... Storing Data ... 195
5.7 ... Retrieving Data ... 202
5.8 ... Capstone Project ... 207
5.9 ... Summary ... 218
6 ... Retrieval-Augmented Generation ... 221
6.1 ... Introduction ... 222
6.2 ... Coding: Simple Retrieval-Augmented Generation ... 225
6.3 ... Advanced Techniques ... 232
6.4 ... Coding: Prompt Caching ... 250
6.5 ... Evaluation ... 256
6.6 ... Summary ... 261
7 ... Agentic Systems ... 263
7.1 ... Introduction to AI Agents ... 264
7.2 ... Available Frameworks ... 265
7.3 ... Simple Agent ... 267
7.4 ... Agentic Framework: LangGraph ... 275
7.5 ... Agentic Framework: AG2 ... 289
7.6 ... Agentic Framework: CrewAI ... 303
7.7 ... Agentic Framework: OpenAI Agents ... 328
7.8 ... Agentic Framework: Pydantic AI ... 333
7.9 ... Monitoring Agentic Systems ... 336
7.10 ... Summary ... 342
8 ... Deployment ... 345
8.1 ... Deployment Architecture ... 345
8.2 ... Deployment Strategy ... 347
8.3 ... Self-Contained App Development ... 355
8.4 ... Deployment to Heroku ... 361
8.5 ... Deployment to Streamlit ... 369
8.6 ... Deployment with Render ... 372
8.7 ... Summary ... 374
9 ... Outlook ... 375
9.1 ... Advances in Model Architecture ... 375
9.2 ... Limitations and Issues of LLMs ... 376
9.3 ... Regulatory Developments ... 381
9.4 ... Artificial General Intelligence and Artificial Superintelligence ... 381
9.5 ... AI Systems in the Near Term ... 382
9.6 ... Useful Resources ... 384
9.7 ... Summary ... 384
... The Author ... 387
... Index ... 389