Book description
Large language models (LLMs) and diffusion models such as ChatGPT and Stable Diffusion have unprecedented potential. Because they have been trained on all the public text and images on the internet, they can make useful contributions to a wide variety of tasks. And with the barrier to entry greatly reduced today, practically any developer can harness LLMs and diffusion models to tackle problems previously unsuitable for automation.
With this book, you'll gain a solid foundation in generative AI, including how to apply these models in practice. When first integrating LLMs and diffusion models into their workflows, most developers struggle to coax reliable enough results from them to use in automated systems. Authors James Phoenix and Mike Taylor show you how a set of principles called prompt engineering can enable you to work effectively with AI.
Learn how to empower AI to work for you. This book explains:
- The structure of the interaction chain of your program's AI model and the fine-grained steps in between
- How AI model requests arise from transforming the application problem into a document completion problem in the model training domain
- The influence of LLM and diffusion model architecture—and how to best interact with it
- How these principles apply in practice in the domains of natural language processing, text and image generation, and code
Publisher resources
Table of contents
- Preface
- 1. The Five Principles of Prompting
- 2. Introduction to Large Language Models for Text Generation
-
3. Standard Practices for Text Generation with ChatGPT
- Generating Lists
- Hierarchical List Generation
- When to Avoid Using Regular Expressions
- Generating JSON
- Filtering YAML Payloads
- Handling Invalid Payloads in YAML
- Diverse Format Generation with ChatGPT
- Explain It like I’m Five
- Universal Translation Through LLMs
- Ask for Context
- Text Style Unbundling
- Identifying the Desired Textual Features
- Generating New Content with the Extracted Features
- Extracting Specific Textual Features with LLMs
- Summarization
- Summarizing Given Context Window Limitations
- Chunking Text
- Chunking Strategies
- Sentence Detection Using SpaCy
- Building a Simple Chunking Algorithm in Python
- Sliding Window Chunking
- Text Chunking Packages
- Text Chunking with Tiktoken
- Encodings
- Estimating Token Usage for Chat API Calls
- Sentiment Analysis
- Least to Most
- Role Prompting
- Benefits of Role Prompting
- Challenges of Role Prompting
- When to Use Role Prompting
- GPT Prompting Tactics
- Classification with LLMs
- Building a Classification Model
- Majority Vote for Classification
- Criteria Evaluation
- Meta Prompting
- Summary
-
4. Advanced Techniques for Text Generation with LangChain
- Introduction to LangChain
- Chat Models
- Streaming Chat Models
- Creating Multiple LLM Generations
- LangChain Prompt Templates
- LangChain Expression Language (LCEL)
- Using PromptTemplate with Chat Models
- Output Parsers
- LangChain Evals
- OpenAI Function Calling
- Parallel Function Calling
- Function Calling in LangChain
- Extracting Data with LangChain
- Query Planning
- Creating Few-Shot Prompt Templates
- Limitations with Few-Shot Examples
- Saving and Loading LLM Prompts
- Data Connection
- Document Loaders
- Text Splitters
- Text Splitting by Length and Token Size
- Text Splitting with Recursive Character Splitting
- Task Decomposition
- Prompt Chaining
- Summary
- 5. Vector Databases with FAISS and Pinecone
-
6. Autonomous Agents with
Memory and Tools
- Chain-of-Thought
- Agents
- Using LLMs as an API (OpenAI Functions)
- Comparing OpenAI Functions and ReAct
- Agent Toolkits
- Customizing Standard Agents
- Custom Agents in LCEL
- Understanding and Using Memory
- Memory in LangChain
- Other Popular Memory Types in LangChain
- OpenAI Functions Agent with Memory
- Advanced Agent Frameworks
- Callbacks
- Summary
- 7. Introduction to Diffusion Models for Image Generation
- 8. Standard Practices for Image Generation with Midjourney
- 9. Advanced Techniques for Image Generation with Stable Diffusion
- 10. Building AI-Powered Applications
- Index
- About the Authors
Product information
- Title: Prompt Engineering for Generative AI
- Author(s):
- Release date: May 2024
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781098153434
You might also like
book
AI Engineering
Recent breakthroughs in AI have not only increased demand for AI products, they've also lowered the …
book
Modern Generative AI with ChatGPT and OpenAI Models
Harness the power of AI with innovative, real-world applications, and unprecedented productivity boosts, powered by the …
book
Introduction to Generative AI
Generative AI tools like ChatGPT are amazing—but how will their use impact our society? This book …
audiobook
Introduction to Generative AI
Generative AI tools like ChatGPT are amazing—but how can you get the most out of them …