Prompt Engineering for Generative AI

by James Phoenix and Michael Taylor

Artificial Intelligence

Book Details

Book Title

Prompt Engineering for Generative AI

Author

James Phoenix and Michael Taylor

Publisher

O'Reilly Media, Inc

Publication Date

2024

ISBN

9781098153434

Number of Pages

846

Language

English

Format

PDF

File Size

6.6MB

Subject

Artificial Intelligence

Table of Contents

  • Preface
  • 1. The Five Principles of Prompting
  • Overview of the Five Principles of Prompting
  • 1. Give Direction
  • 2. Specify Format
  • 3. Provide Examples
  • 4. Evaluate Quality
  • 5. Divide Labor
  • Summary
  • 2. Introduction to Large Language Models for Text Generation
  • What Are Text Generation Models?
  • Historical Underpinnings: The Rise of Transformer Architectures
  • OpenAI’s Generative Pretrained Transformers
  • GPT-4
  • Google’s Gemini
  • Meta’s Llama and Open Source
  • Leveraging Quantization and LoRA
  • Mistral
  • Anthropic: Claude
  • GPT-4V(ision)
  • Model Comparison
  • Summary
  • 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
  • Retrieval Augmented Generation (RAG)
  • Introducing Embeddings
  • Document Loading
  • Memory Retrieval with FAISS
  • RAG with LangChain
  • Hosted Vector Databases with Pinecone
  • Self-Querying
  • Alternative Retrieval Mechanisms
  • Summary
  • 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
  • OpenAI DALL-E
  • Midjourney
  • Stable Diffusion
  • Google Gemini
  • Text to Video
  • Model Comparison
  • Summary
  • 8. Standard Practices for Image Generation with Midjourney
  • Format Modifiers
  • Art Style Modifiers
  • Reverse Engineering Prompts
  • Quality Boosters
  • Negative Prompts
  • Weighted Terms
  • Prompting with an Image
  • Inpainting
  • Outpainting
  • Consistent Characters
  • Prompt Rewriting
  • Meme Unbundling
  • Meme Mapping
  • Prompt Analysis
  • Summary
  • 9. Advanced Techniques for Image Generation with Stable Diffusion
  • Running Stable Diffusion
  • AUTOMATIC1111 Web User Interface
  • Img2Img
  • Upscaling Images
  • Interrogate CLIP
  • SD Inpainting and Outpainting
  • ControlNet
  • Segment Anything Model (SAM)
  • DreamBooth Fine-Tuning
  • Stable Diffusion XL Refiner
  • Summary
  • 10. Building AI-Powered Applications
  • AI Blog Writing
  • Topic Research
  • Expert Interview
  • Generate Outline
  • Text Generation
  • Writing Style
  • Title Optimization
  • AI Blog Images
  • User Interface
  • Summary
  • Index
  • About the Authors