LLM Prompt Engineering For Developers
LLM Prompt Engineering For Developers
The Art and Science of Unlocking LLMs' True Potential
About the Book
In "LLM Prompt Engineering For Developers," we take a comprehensive journey into the world of LLMs and the art of crafting effective prompts for them.
The guide starts by laying the foundation, exploring the evolution of Natural Language Processing (NLP) from its early days to the sophisticated LLMs we interact with today. You will dive deep into the complexities of models such as GPT models, understanding their architecture, capabilities, and nuances.
As we progress, this guide emphasizes the importance of effective prompt engineering and its best practices. While LLMs like ChatGPT (gpt-3.5) are powerful, their full potential is only realized when they are communicated with effectively. This is where prompt engineering comes into play. It's not simply about asking the model a question; it's about phrasing, context, and understanding the model's logic.
Through chapters dedicated to Azure Prompt Flow, LangChain, and other tools, you'll gain hands-on experience in crafting, testing, scoring and optimizing prompts. We'll also explore advanced concepts like Few-shot Learning, Chain of Thought, Perplexity and techniques like ReAct and General Knowledge Prompting, equipping you with a comprehensive understanding of the domain.
This guide is designed to be hands-on, offering practical insights and exercises. In fact, as you progress, you'll familiarize yourself with several tools:
- openai Python library: You will dive into the core of OpenAI's LLMs and learn how to interact and fine-tune models to achieve precise outputs tailored to specific needs.
- promptfoo: You will master the art of crafting effective prompts. Throughout the guide, we'll use promptfoo to test and score prompts, ensuring they're optimized for desired outcomes.
- LangChain: You’ll explore the LangChain framework, which elevates LLM-powered applications. You’ll dive into understanding how a prompt engineer can leverage the power of this tool to test and build effective prompts.
- betterprompt: Before deploying, it's essential to test. With betterprompt, you'll ensure the LLM prompts are ready for real-world scenarios, refining them as needed.
- Azure Prompt Flow: You will experience the visual interface of Azure's tool, streamlining LLM-based AI development. You'll design executable flows, integrating LLMs, prompts, and Python tools, ensuring a holistic understanding of the art of prompting.
- And more!
With these tools in your toolkit, you will be well-prepared to craft powerful and effective prompts. The hands-on exercises will help solidify your understanding. Throughout the process, you'll be actively engaged and by the end, not only will you appreciate the power of prompt engineering, but you'll also possess the skills to implement it effectively.
Table of Contents
- 1:Preface
- 1.1:What are you going to learn?
- 1.2:To whom is this guide for?
- 1.3:Join the community
- 1.4:About the author
- 2:From NLP to Large Language Models
- 2.1:What is Natural Language Processing?
- 2.2:Language models
- 2.3:Statistical models (n-grams)
- 2.4:Knowledge-based models
- 2.5:Contextual language models
- 2.6:Neural network-based models
- 2.6.1:Feedforward neural networks
- 2.6.2:Recurrent neural networks (RNNs)
- 2.6.3:Long short-term memory (LSTM)
- 2.6.4:Gated recurrent units (GRUs)
- 2.7:Transformer models
- 2.7.1:Bidirectional encoder representations from transformers (BERT)
- 2.7.2:Generative pre-trained transformer (GPT)
- 2.8:What’s next?
- 3:Introduction to prompt engineering
- 4:OpenAI GPT and Prompting: An Introduction
- 4.1:Generative Pre-trained Transformers (GPT) models
- 4.2:What is GPT and how it is different from ChatGPT?
- 4.3:The GPT models series: a closer look
- 4.3.1:GPT-3.5
- 4.3.2:GPT-4
- 4.3.3:Other models
- 4.4:API usage vs. web interface
- 4.5:Tokens
- 4.6:Costs, tokens and initial prompts: how to calculate the cost of using a model
- 4.7:Prompting: how does it work?
- 4.8:Probability and sampling: at the heart of GPT
- 4.9:Understanding the API parameters
- 4.9.1:Temperature
- 4.9.2:Top-p
- 4.9.3:Top-k
- 4.9.4:Sequence length (max_tokens)
- 4.9.5:Presence penalty (presence_penalty)
- 4.9.6:Frequency penalty (frequency_penalty)
- 4.9.7:Number of responses (n)
- 4.9.8:Best of (best_of)
- 4.10:OpenAI official examples
- 4.11:Using the API without coding
- 4.12:Completion (deprecated)
- 4.13:Chat
- 4.14:Insert (deprecated)
- 4.15:Edit (deprecated)
- 5:Setting up the environment
- 5.1:Choosing the model
- 5.2:Choosing the programming language
- 5.3:Installing the prerequisites
- 5.4:Installing the OpenAI Python library
- 5.5:Getting an OpenAI API key
- 5.6:A hello world example
- 5.7:Interactive prompting
- 5.8:Interactive prompting with mutliline prompt
- 6:Few-shot Learning and Chain of Thought
- 6.1:What is few-shot learning?
- 6.2:Zero-shot vs few-shot learning
- 6.3:Approaches to few-shot learning
- 6.3.1:Prior knowledge about similarity
- 6.3.2:Prior knowledge about learning
- 6.3.3:Prior knowledge of data
- 6.4:Examples of few-shot learning
- 6.5:Limitations of few-shot learning
- 7:Chain of Thought (CoT)
- 8:Zero-shot CoT Prompting
- 9:Auto Chain of Thought Prompting (AutoCoT)
- 10:Self-consistency
- 11:Transfer Learning
- 11.1:What is transfer learning?
- 11.2:Inductive transfer
- 11.3:Transductive transfer
- 11.4:Inductive vs. transductive transfer
- 11.5:Transfer learning, fine-tuning, and prompt engineering
- 11.6:Fine-tuning with a prompt dataset: a practical example
- 11.7:Why is prompt engineering vital for transfer learning and fine-tuning?
- 12:Perplexity as a metric for prompt optimization
- 12.1:Do not surprise the model
- 12.2:How to calculate perplexity?
- 12.3:A practical example with Betterprompt
- 12.4:Hack the prompt
- 13:ReAct: Reason + Act
- 13.1:What is it?
- 13.2:ReAct using LanChain
- 14:General Knowledge Prompting
- 14.1:What is general knowledge prompting?
- 14.2:Example of general knowledge prompting
- 15:Introduction to Azure Prompt Flow
- 15.1:What is Azure Prompt Flow?
- 15.2:Prompt engineering agility
- 15.3:Considerations before using Azure Prompt Flow
- 15.4:Creating your fist prompt flow
- 15.5:Deploying the flow for real time inference
- 16:LangChain: The Prompt Engineer’s Guide
- 16.1:What is LangChain?
- 16.2:Installation
- 16.3:Getting started
- 16.4:Prompt templates and formatting
- 16.5:Partial prompting
- 16.6:Composing prompts using pipeline prompts
- 16.7:Chat prompt templates
- 16.8:The core building block of LangChain: LLMChain
- 16.9:Custom prompt templates
- 16.10:Few-shot prompt templates
- 16.11:Better few-shot learning with ExampleSelectors
- 16.11.1:NGram overlap example selector
- 16.11.2:Max marginal relevance example selector
- 16.11.3:Length based example selector
- 16.11.4:The custom example selector
- 16.11.5:Few shot learning with chat models
- 16.12:Using prompts from a file
- 16.13:Validating prompt templates
- 17:A Practical Guide to Testing and Scoring Prompts
- 17.1:What and how to evaluate a prompt
- 17.2:Testing and scoring prompts with promptfoo
- 17.3:promptfoo: using variables
- 17.4:promptfoo: testing with assertions
- 17.5:promptfoo integration with LangChaing
- 17.6:promptfoo and reusing assertions with templates (DRY)
- 17.7:promptfoo scenarios and streamlining the test
- 18:General guidelines and best practices
- 18.1:Introduction
- 18.2:Start with an action verb
- 18.3:Provide a clear context
- 18.4:Use role-playing
- 18.5:Use references
- 18.6:Use double quotes
- 18.7:Use single quotes when needed
- 18.8:Use text separators
- 18.9:Be specific
- 18.10:Give examples
- 18.11:Indicate the desired response length
- 18.12:Guide the model
- 18.13:Don’t hesitate to refine
- 18.14:Consider looking at your problem from a different angle
- 18.15:Consider opening another chat (ChatGPT)
- 18.16:Use the right words and phrases
- 18.17:Experiment and iterate
- 18.18:Stay mindful of LLMs limitations
- 19:Where and How Prompt Engineering is Used
- 19.1:Creative writing
- 19.2:Content generation, SEO, marketing and advertising
- 19.3:Customer Service
- 19.4:Data analysis, reporting, and visualization
- 19.5:Virtual assistants and smart devices
- 19.6:Game development
- 19.7:Healthcare and medical
- 19.8:Story generation and role-playing
- 19.9:Business intelligence and analytics
- 19.10:Image generation
- 20:Anatomy of a Prompt
- 20.1:Role or persona
- 20.2:Instructions
- 20.3:Input data
- 20.4:Context
- 20.5:Rules
- 20.6:Output
- 20.7:Examples
- 21:Types of Prompts
- 21.1:Direct instructions
- 21.2:Open-ended prompts
- 21.3:Socratic prompts
- 21.4:System prompts
- 21.5:Other types of prompts
- 21.6:Interactive prompts
- 22:Prompt databases, tools and resources
- 22.1:Prompt Engine
- 22.2:Prompt generator for ChatGPT
- 22.3:PromptAppGPT
- 22.4:Promptify
- 22.5:PromptBench
- 22.6:PromptFlow
- 22.7:promptfoo
- 22.8:PromptPerfect: prompt optimization tool
- 22.9:AIPRM for ChatGPT: prompt management and database
- 22.10:FlowGPT: a visual interface for ChatGPT and prompt database
- 22.11:Wnr.ai: no-code tool to create animated AI avatars
- 23:Afterword
- 23.1:What’s next?
- 23.2:Thank you
- 23.3:About the author
- 23.4:Join the community
- 23.5:Feedback
- 1:Preface
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.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 millionwriting, publishing and selling 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