Prompt Engineering Tutorial
Prompt Engineering Tutorial
Audience
This tutorial is designed for a wide range of individuals who want to dive
into the world of prompt engineering and leverage its potential in various
applications. Our target audience includes:
Prerequisites
While this tutorial is designed to be accessible to learners at various levels,
a foundational understanding of natural language processing and machine
learning concepts will be beneficial.
1
Prompt Engineering
All the content and graphics published in this e-book are the property of
Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse,
retain, copy, distribute or republish any contents or a part of contents of
this e-book in any manner without written consent of the publisher.
We strive to update the contents of our website and tutorials as timely and
as precisely as possible, however, the contents may contain inaccuracies or
errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the
accuracy, timeliness or completeness of our website or its contents
including this tutorial. If you discover any errors on our website or in this
tutorial, please notify us at contact@tutorialspoint.com.
2
Prompt Engineering
Table of Contents
About the Tutorial ........................................................................................................... 1
Audience ......................................................................................................................... 1
Prerequisites ................................................................................................................... 1
What You Will Learn in This Tutorial ............................................................................... 1
Disclaimer & Copyright ................................................................................................... 2
Table of Contents ............................................................................................................ 3
1. PROMPT ENGINEERING – INTRODUCTION ..................................................................................... 6
What are Prompts? ......................................................................................................... 6
Types of Prompts............................................................................................................. 6
How Does Prompt Engineering Work? ............................................................................ 7
Evaluating and Validating Prompts ................................................................................ 7
Ethical Considerations in Prompt Engineering ................................................................ 8
Benefits of Prompt Engineering ...................................................................................... 8
Future Directions and Open Challenges .......................................................................... 8
2. PROMPT ENGINEERING – ROLE OF PROMPTS IN AI MODELS ............................................................ 9
Importance of Effective Prompts .................................................................................... 9
Techniques for Prompt Engineering .............................................................................. 10
3. PROMPT ENGINEERING – WHAT IS GENERATIVE AI? .................................................................... 12
Generative Language Models ....................................................................................... 12
4. PROMPT ENGINEERING – NLP AND ML FOUNDATIONS ................................................................ 15
5. PROMPT ENGINEERING – COMMON NLP TASKS.......................................................................... 18
6. PROMPT ENGINEERING – OPTIMIZING PROMPT-BASED MODELS .................................................... 21
7. PROMPT ENGINEERING – TUNING AND OPTIMIZATION TECHNIQUES ............................................... 24
8. PROMPT ENGINEERING – PRE-TRAINING AND TRANSFER LEARNING................................................. 27
9. PROMPT ENGINEERING – DESIGNING EFFECTIVE PROMPTS ............................................................ 30
10. PROMPT ENGINEERING – PROMPT GENERATION STRATEGIES......................................................... 33
11. PROMPT ENGINEERING – MONITORING PROMPT EFFECTIVENESS ................................................... 36
12. PROMPT ENGINEERING – PROMPTS FOR SPECIFIC DOMAINS .......................................................... 39
3
Prompt Engineering
4
Prompt Engineering
5
1. Prompt Engineering – Introduction
Prompt Engineering
Prompt engineering is the process of crafting text prompts that help large
language models (LLMs) generate more accurate, consistent, and creative
outputs. By carefully choosing the words and phrases in a prompt, prompt
engineers can influence the way that an LLM interprets a task and the
results that it produces.
By providing clear and explicit prompts, developers can guide the model's
behavior and influence the generated output.
Types of Prompts
There can be wide variety of prompts which you will get to know during the
course of this tutorial. This being an introductory chapter, let's start with a
small set to highlight the different types of prompts that one can use:
Natural Language Prompts: These prompts emulate human-like
instructions, providing guidance in the form of natural language cues.
They allow developers to interact with the model more intuitively, using
instructions that resemble how a person would communicate.
6
Prompt Engineering
Be specific. The more specific you are in your prompt, the more
likely the LLM is to generate a relevant and informative response.
For example, instead of asking the LLM to "write a poem," you could
ask it to "write a poem about a lost love."
7
Prompt Engineering
8
2. Prompt Engineering – Role of Prompt
Prompts in AI
Engineering
Models
9
Prompt Engineering
10
Prompt Engineering
Conclusion
Prompt engineering plays a vital role in shaping the behavior and output of
AI models. Effective prompts empower developers to guide the model's
behavior, control biases, and generate contextually appropriate responses.
11
3. Prompt Engineering – What is Generative
Prompt Engineering AI?
In this chapter, we will delve into the world of generative AI and its role in
prompt engineering. Generative AI refers to a class of artificial intelligence
techniques that focus on creating data, such as images, text, or audio,
rather than processing existing data.
Generative language models can be used for a wide range of tasks, including
text generation, translation, summarization, and more. They serve as a
foundation for prompt engineering by providing contextually aware
responses to custom prompts.
12
Prompt Engineering
Language Translation
Multilingual Prompting: Generative language models can be fine-
tuned for multilingual translation tasks, enabling prompt engineers
to build prompt-based translation systems.
Multimodal Prompting
Integrating Different Modalities: Generative AI models can be extended
to multimodal prompts, where users can combine text, images, audio, and
other forms of input to elicit responses from the model.
Ethical Considerations
Responsible Use of Generative AI: As with any AI technology,
prompt engineers must consider ethical implications, potential
biases, and the responsible use of generative AI models.
Future Directions
Continual Advancements: Generative AI is an active area of
research, and prompt engineers can expect continuous
advancements in model architectures and training techniques.
13
Prompt Engineering
Conclusion
In this chapter, we explored the role of generative AI in prompt engineering
and how generative language models serve as a powerful foundation for
contextually aware responses. By fine-tuning generative language models and
customizing model responses through tailored prompts, prompt engineers can
create interactive and dynamic language models for various applications.
14
4. Prompt Engineering – NLP and
Prompt ML
Engineering
Foundations
In this chapter, we will delve into the essential foundations of Natural Language
Processing (NLP) and Machine Learning (ML) as they relate to Prompt
Engineering. Understanding these foundational concepts is crucial for designing
effective prompts that elicit accurate and meaningful responses from language
models like ChatGPT.
What is NLP?
NLP is a subfield of artificial intelligence that focuses on enabling computers to
understand, interpret, and generate human language. It encompasses various
techniques and algorithms for processing, analyzing, and manipulating natural
language data.
Text preprocessing involves preparing raw text data for NLP tasks. Techniques
like tokenization, stemming, lemmatization, and removing stop words are
applied to clean and normalize text before feeding it into language models.
15
Prompt Engineering
Ethical Considerations
Bias in Data and Model: Be aware of potential biases in both training
data and language models. Ethical considerations play a vital role in
responsible Prompt Engineering to avoid propagating biased
information.
Conclusion
In this chapter, we explored the fundamental concepts of Natural Language
Processing (NLP) and Machine Learning (ML) and their significance in Prompt
Engineering. Understanding NLP techniques like text preprocessing, transfer
learning, and fine-tuning enables us to design effective prompts for language
models like ChatGPT.
16
Prompt Engineering
17
5. Prompt Engineering – Common NLP
Prompt Tasks
Engineering
In this chapter, we will explore some of the most common Natural Language
Processing (NLP) tasks and how Prompt Engineering plays a crucial role in
designing prompts for these tasks.
Text Classification
Understanding Text Classification: Text classification involves
categorizing text data into predefined classes or categories. It is used
for sentiment analysis, spam detection, topic categorization, and more.
Language Translation
Understanding Language Translation: Language translation is the
task of converting text from one language to another. It is a vital
application in multilingual communication.
Question Answering
Understanding Question Answering: Question Answering involves
providing answers to questions posed in natural language.
18
Prompt Engineering
Text Generation
Understanding Text Generation: Text generation involves creating
coherent and contextually relevant text based on a given input or prompt.
Sentiment Analysis
Understanding Sentiment Analysis: Sentiment Analysis involves
determining the sentiment or emotion expressed in a piece of text.
Text Summarization
Understanding Text Summarization: Text Summarization involves
condensing a longer piece of text into a shorter, coherent summary.
19
Prompt Engineering
Conclusion
In this chapter, we explored common Natural Language Processing (NLP) tasks
and their significance in Prompt Engineering. By designing effective prompts for
text classification, language translation, named entity recognition, question
answering, sentiment analysis, text generation, and text summarization, you
can leverage the full potential of language models like ChatGPT.
20
6. Prompt Engineering – Optimizing
Prompt Engineering
Prompt-based Models
In this chapter, we will delve into the strategies and techniques to optimize
prompt-based models for improved performance and efficiency. Prompt
engineering plays a significant role in fine-tuning language models, and by
employing optimization methods, prompt engineers can enhance model
responsiveness, reduce bias, and tailor responses to specific use-cases.
Data Augmentation
Importance of Data Augmentation: Data augmentation involves
generating additional training data from existing samples to increase
model diversity and robustness. By augmenting prompts with slight
variations, prompt engineers can improve the model's ability to
handle different phrasing or user inputs.
Active Learning
Active Learning for Prompt Engineering: Active learning
involves iteratively selecting the most informative data points for
model fine-tuning. Applying active learning techniques in prompt
engineering can lead to a more efficient selection of prompts for fine-
tuning, reducing the need for large-scale data collection.
Ensemble Techniques
Importance of Ensembles: Ensemble techniques combine the
predictions of multiple models to produce a more robust and
accurate final prediction. In prompt engineering, ensembles of fine-
tuned models can enhance the overall performance and reliability of
prompt-based language models.
21
Prompt Engineering
Continual Learning
Continual Learning for Prompt Engineering: Continual learning
enables the model to adapt and learn from new data without
forgetting previous knowledge. This is particularly useful in prompt
engineering when language models need to be updated with new
prompts and data.
Hyperparameter Optimization
Importance of Hyperparameter Optimization: Hyperparameter
optimization involves tuning the hyperparameters of the prompt-
based model to achieve the best performance. Proper
hyperparameter tuning can significantly impact the model's
effectiveness and responsiveness.
Bias Mitigation
Bias Detection and Analysis: Detecting and analyzing biases in
prompt engineering is crucial for creating fair and inclusive language
models. Identify potential biases in prompts and responses to ensure
that the model's behavior is unbiased.
22
Prompt Engineering
Conclusion
In this chapter, we explored the various techniques and strategies to
optimize prompt-based models for enhanced performance. Data
augmentation, active learning, ensemble techniques, and continual learning
contribute to creating more robust and adaptable prompt-based language
models. Hyperparameter optimization ensures optimal model settings,
while bias mitigation fosters fairness and inclusivity in responses.
By regularly evaluating and monitoring prompt-based models, prompt
engineers can continuously improve their performance and responsiveness,
making them more valuable and effective tools for various applications.
23
7. Prompt Engineering – Tuning and
Prompt Engineering
Optimization Techniques
In this chapter, we will explore tuning and optimization techniques for prompt
engineering. Fine-tuning prompts and optimizing interactions with language
models are crucial steps to achieve the desired behavior and enhance the
performance of AI models like ChatGPT.
Fine-Tuning Prompts
Incremental Fine-Tuning: Gradually fine-tune our prompts by
making small adjustments and analyzing model responses to
iteratively improve performance.
24
Prompt Engineering
Reinforcement Learning
Reward Models: Incorporate reward models to fine-tune prompts
using reinforcement learning, encouraging the generation of desired
responses.
25
Prompt Engineering
Conclusion
In this chapter, we explored tuning and optimization techniques for prompt
engineering. By fine-tuning prompts, adjusting context, sampling strategies,
and controlling response length, we can optimize interactions with language
models to generate more accurate and contextually relevant outputs. Applying
reinforcement learning and continuous monitoring ensures the model's
responses align with our desired behavior.
26
8. Prompt Engineering – Pre-training and
Prompt Engineering
Transfer Learning
In this chapter, we will delve into the details of pre-training language models,
the benefits of transfer learning, and how prompt engineers can utilize these
techniques to optimize model performance.
27
Prompt Engineering
Conclusion
In this chapter, we explored pre-training and transfer learning techniques in
Prompt Engineering. Pre-training language models on vast corpora and
28
Prompt Engineering
29
9. Prompt Engineering – Designing
Prompt Effective
Engineering
Prompts
In this chapter, we will delve into the art of designing effective prompts for
language models like ChatGPT. Crafting well-defined and contextually
appropriate prompts is essential for eliciting accurate and meaningful
responses.
Specifying Input and Output Format: Define the input format the
model should expect and the desired output format for its responses.
This clarity helps the model understand the task better.
30
Prompt Engineering
Conclusion
In this chapter, we explored the art of designing effective prompts for
language models like ChatGPT. Clear, contextually appropriate, and well-
defined prompts play a vital role in achieving accurate and meaningful
responses. As you master the craft of prompt design, you can expect to
unlock the full potential of language models, providing more engaging and
interactive experiences for users.
31
Prompt Engineering
Remember to tailor your prompts to suit the specific tasks, provide relevant
context, and experiment with different techniques to discover the most
effective approach. With careful consideration and practice, you can elevate
your Prompt Engineering skills and optimize your interactions with language
models.
32
10. Prompt Engineering – PromptPrompt
Generation
Engineering
Strategies
Predefined Prompts
Fixed Prompts: One of the simplest prompt generation strategies
involves using fixed prompts that are predefined and remain
constant for all user interactions. These fixed prompts are suitable
for tasks with a straightforward and consistent structure, such as
language translation or text completion tasks. However, fixed
prompts may lack flexibility for more complex or interactive tasks.
Contextual Prompts
Contextual Sampling: Contextual prompts involve dynamically
sampling user interactions or real-world data to generate prompts.
By leveraging context from user conversations or domain-specific
data, prompt engineers can create prompts that align closely with
the user's input. Contextual prompts are particularly useful for chat-
based applications and tasks that require an understanding of user
intent over multiple turns.
33
Prompt Engineering
Adaptive Prompts
Reinforcement Learning: Adaptive prompts leverage reinforcement
learning techniques to iteratively refine prompts based on user feedback
or task performance. Prompt engineers can create a reward system to
incentivize the model to produce more accurate responses. By using
reinforcement learning, adaptive prompts can be dynamically adjusted
to achieve optimal model behavior over time.
Interactive Prompts
Prompt Steering: Interactive prompts enable users to steer the
model's responses actively. Prompt engineers can provide users with
options or suggestions to guide the model's output. Prompt steering
empowers users to influence the response while maintaining the
model's underlying capabilities.
Transfer Learning
Pretrained Language Models: Leveraging pretrained language
models can significantly expedite the prompt generation process.
Prompt engineers can fine-tune existing language models on
domain-specific data or user interactions to create prompt-tailored
models. This approach capitalizes on the model's prelearned
linguistic knowledge while adapting it to specific tasks.
34
Prompt Engineering
Domain-Specific Prompts
Task-Based Prompts: Task-based prompts are specifically
designed for a particular task or domain. Prompt engineers can
customize prompts to provide task-specific cues and context, leading
to improved performance for specific applications.
Conclusion
In this chapter, we explored various prompt generation strategies in Prompt
Engineering. From predefined and template-based prompts to adaptive,
interactive, and domain-specific prompts, each strategy serves different
purposes and use cases.
35
11. Prompt Engineering – Monitoring Prompt
Prompt Engineering
Effectiveness
Human Evaluation
Expert Evaluation: Engaging domain experts or evaluators familiar
with the specific task can provide valuable qualitative feedback on
the model's outputs. These experts can assess the relevance,
accuracy, and contextuality of the model's responses and identify
any potential issues or biases.
User Studies: User studies involve real users interacting with the
model, and their feedback is collected. This approach provides
valuable insights into user satisfaction, areas for improvement, and
the overall user experience with the model-generated responses.
Automated Evaluation
Automatic Metrics: Automated evaluation metrics complement
human evaluation and offer quantitative assessment of prompt
36
Prompt Engineering
37
Prompt Engineering
Conclusion
In this chapter, we explored the significance of monitoring prompt effectiveness
in Prompt Engineering. Defining evaluation metrics, conducting human and
automated evaluations, considering context and continuity, and adapting to
user feedback are crucial aspects of prompt assessment.
38
12. Prompt Engineering – Prompts forEngineering
Prompt Specific
Domains
Task Requirements: Identify the tasks and goals within the domain
to determine the prompts' scope and specificity needed for optimal
performance.
39
Prompt Engineering
Domain Adaptation
Fine-Tuning on Domain Data: Fine-tune the language model on domain-
specific data to adapt it to the target domain's requirements. This step
enhances the model's performance and domain-specific knowledge.
User Feedback: Collect user feedback from domain experts and end-
users to iteratively improve prompt design and model performance.
40
Prompt Engineering
Ethical Considerations
Confidentiality and Privacy: In domain-specific prompt
engineering, adhere to ethical guidelines and data protection
principles to safeguard sensitive information.
Conclusion
In this chapter, we explored prompt engineering for specific domains,
emphasizing the significance of domain knowledge, task specificity, and
data curation. Customizing prompts for healthcare, finance, legal, and other
domains allows language models to generate contextually accurate and
valuable responses for targeted applications.
41
Prompt Engineering
42
13. Prompt Engineering – ACT LIKE
Prompt Prompt
Engineering
In the recent years, NLP models like ChatGPT have gained significant attention
for their ability to generate human-like responses. One important aspect of
leveraging these models effectively is understanding and utilizing prompts.
Among the various prompt styles, the "ACT LIKE" prompt has emerged as
a powerful technique to guide the model's behavior. This article explores
the concept of ACT LIKE prompts, provides examples, and highlights their
applications in different scenarios.
Simulating an Expert:
43
Prompt Engineering
Example
Take a look at the following example:
import openai
44
Prompt Engineering
Note that the system may produce a different response on your system,
when you use the same code with your OpenAI key.
Conclusion
ACT LIKE prompts serve as a powerful tool for engaging with ChatGPT
models, allowing users to assume different roles, characters, or expertise.
By leveraging this prompt style, individuals can create rich and immersive
conversations, enhance storytelling, foster learning experiences, and create
interactive entertainment.
Understanding the potential of ACT LIKE prompts opens up a wide range of
possibilities for exploring the capabilities of natural language processing
models and making interactions more dynamic and engaging.
45
14. Prompt Engineering – INCLUDE
Prompt Prompt
Engineering
In this example, the user asks a question about photosynthesis, and the
response from ChatGPT includes the content specified within the INCLUDE
directive, namely "Chlorophyll, Carbon dioxide, and Water." By using the
INCLUDE directive, we can ensure that specific details are included in the
response, providing a more comprehensive answer.
Limit the Length: While the INCLUDE directive can be useful for
including additional information, be mindful of the response length.
Including too much content may result in excessively long or verbose
responses. Strike a balance and include only the most relevant details.
46
Prompt Engineering
In this example, the user asks "How does photosynthesis work?" and he
specifically mentions that the response should INCLUDE the words
"Chlorophyll", "Carbon dioxide, and "Water".
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=50,
temperature=0.8,
n=1,
stop=None
)
return response
47
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
Here, we got the following output:
Conclusion
In this chapter, we explored the power of the INCLUDE directive in prompt
engineering. By using the INCLUDE directive, we can guide ChatGPT to
incorporate specific details, facts, or phrases into its generated responses.
We discussed the syntax of the INCLUDE directive and provided best practices
for its usage, including being specific, limiting the length of included content,
using contextual prompts, and iterating to refine our prompts.
48
15. Prompt Engineering – COLUMN Prompt
Prompt Engineering
49
Prompt Engineering
The chat_prompt variable contains the user's prompt and the ChatGPT
response, including the comparison table formatted using the COLUMN
directive.
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
50
Prompt Engineering
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
Upon running the script, we will receive the generated response from
ChatGPT, including the structured output in the form of a comparison table.
Conclusion
In this chapter, we explored the power of the COLUMN directive in prompt
engineering for ChatGPT. By using the COLUMN directive, we can structure
and format the responses generated by ChatGPT, presenting information in
a table-like format or in a specific organized manner.
51
16. Prompt Engineering – FIND Prompt
Prompt Engineering
In this example, the user asks for a summary of the novel "Pride and
Prejudice," and the response from ChatGPT includes the content specified
within the FIND directive, which is the information related to "themes" in
this case.
52
Prompt Engineering
The chat_prompt variable contains the user's prompt and the ChatGPT
response, including the FIND directive to search for information related to
"themes."
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
53
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, including the extracted details based on the specified search
pattern.
Conclusion
In this chapter, we explored the power of the FIND directive in prompt
engineering for ChatGPT. By using the FIND directive, we can extract
specific information or perform searches within the generated responses.
We discussed the syntax of the FIND directive and provided best practices
for its usage, including being specific, using contextual prompts, iterating
and refining, and combining with other prompt engineering techniques.
54
17. Prompt Engineering – TRANSLATE Prompt
Prompt Engineering
In this example, the user asks for the translation of the English phrase
"Hello, how are you?" to French. The response from ChatGPT includes the
translation specified within the TRANSLATE directive, which is the French
phrase "Bonjour, comment ça va ?".
55
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
56
Prompt Engineering
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes the translation of the text specified within the
TRANSLATE directive.
Conclusion
In this chapter, we explored the TRANSLATE directive in prompt engineering
for ChatGPT. By using the TRANSLATE directive, we can leverage ChatGPT
for language translation tasks.
We discussed the syntax of the TRANSLATE directive and provided best
practices for its usage, including specifying source and target languages,
accounting for language nuances, and iterating to refine translations.
57
18. Prompt Engineering – DEFINE
PromptPrompt
Engineering
58
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
59
Prompt Engineering
The chat_prompt variable contains the user's prompt and the ChatGPT
response, including the DEFINE directive to obtain the definition of "AI."
Output
When you run the script, you will receive the generated response from
ChatGPT, including the definition of the term specified within the DEFINE
directive.
Conclusion
In this chapter, we explored the DEFINE directive in prompt engineering for
ChatGPT. By utilizing the DEFINE directive, you can obtain definitions or
explanations of specific terms or concepts from ChatGPT.
We discussed the syntax of the DEFINE directive and provided best practices
for its usage, including specifying the term or concept, providing additional
context, refining prompts, and handling ambiguity.
60
19. Prompt Engineering – CONVERT Prompt
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
62
Prompt Engineering
Output
When we run the script, we will receive the generated response from ChatGPT,
including the converted value specified within the CONVERT directive.
16.09 km
Conclusion
In this chapter, we explored the CONVERT directive in prompt engineering
for ChatGPT. By utilizing the CONVERT directive, we can leverage ChatGPT
as a computational tool to perform conversions or calculations.
63
20. Prompt Engineering – CALCULATE Prompt
Prompt Engineering
In this example, the user requests the result of the addition operation 5 +
8. The response from ChatGPT includes the computed result, which is 13.
64
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
The chat_prompt variable contains the user's prompt and the ChatGPT
response, including the CALCULATE directive to perform the addition
operation 5 + 8.
65
Prompt Engineering
Output
When we run the script, we will receive the generated response from
ChatGPT, including the computed result specified within the CALCULATE
directive.
Conclusion
In this chapter, we explored the CALCULATE directive in prompt engineering
for ChatGPT. By utilizing the CALCULATE directive, we can transform
ChatGPT into a calculator or computational tool.
66
21. Prompt Engineering – GENERATING IDEAS
Prompt Engineering
Prompt
ChatGPT: Sure! Here are a few ideas for your marketing campaign:
1. Utilize social media influencers to promote your product.
2. Create engaging and interactive content that encourages
user participation.
3. Offer exclusive discounts or promotions to attract new customers.
4. Collaborate with complementary brands for cross-promotion
opportunities.
In this example, the user requests ideas for a marketing campaign. The
response from ChatGPT includes a list of suggestions or ideas generated
based on the given prompt.
67
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
68
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, including the ideas or suggestions specified within the GENERATE
directive.
Conclusion
In this chapter, we explored the GENERATE directive in prompt engineering
for ChatGPT. By utilizing the GENERATE directive, we can leverage ChatGPT
to generate fresh ideas, suggestions, or creative solutions.
69
22. Prompt Engineering – CREATEPrompt
A LIST Prompt
Engineering
In this example, the user requests a list of must-read books. The response
from ChatGPT includes a curated list of books based on the given prompt.
70
Prompt Engineering
The chat_prompt variable contains the user's prompt and the ChatGPT
response, including the CREATE A LIST directive to create a list of must-
watch movies.
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
71
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, including the curated list of movies specified within the CREATE A
LIST directive.
Conclusion
In this chapter, we explored the CREATE A LIST directive in prompt
engineering for ChatGPT. By utilizing the CREATE A LIST directive, we can
leverage ChatGPT to generate curated lists of items, recommendations, or
suggestions.
72
23. Prompt Engineering – DETERMINE CAUSE
Prompt Engineering
Prompt
In this example, the user asks for potential causes of climate change. The
response from ChatGPT includes a list of possible causes generated based
on the given prompt.
73
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
74
Prompt Engineering
Output
When we run the script, we will receive the generated response from
ChatGPT, including the potential causes specified within the DETERMINE
CAUSE directive.
Here, the user wants to determine the factors that cause obesity. The user
asks the question: "What could be the causes of obesity?" And, ChatGPT
responds with the following output:
Conclusion
In this chapter, we explored the DETERMINE CAUSE directive in prompt
engineering for ChatGPT. By leveraging the DETERMINE CAUSE directive,
we can prompt ChatGPT to provide insights and explanations regarding the
underlying causes of various occurrences.
75
24. Prompt Engineering – ASSESS IMPACT
Prompt Engineering
Prompt
To use the ASSESS IMPACT prompt, simply specify the event or action that
we want to assess, and then specify the impact that we want to assess. For
example, we could use the following prompt to assess the impact of climate
change on the global economy:
76
Prompt Engineering
In this example, the user asks about the potential impact of increasing
minimum wages. The response from ChatGPT includes a list of potential
impacts generated based on the given prompt.
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
77
Prompt Engineering
Output
When we run the script, we will receive the generated response from
ChatGPT, including the potential impacts specified within the ASSESS
IMPACT directive.
In our example, the user gives the prompt: "What could be the impact of
adopting renewable energy sources?" and ChatGPT responds with the
following output:
Conclusion
In this chapter, we explored the ASSESS IMPACT directive in prompt
engineering for ChatGPT. We discussed the syntax of the ASSESS IMPACT
directive and provided best practices for its usage.
78
25. Prompt Engineering – RECOMMEND
Prompt Engineering
SOLUTIONS Prompt
In this example, the user requests solutions for reducing plastic waste. The
response from ChatGPT includes a list of potential solutions generated
based on the given prompt.
79
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
80
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, including the potential solutions specified within the RECOMMEND
SOLUTIONS directive.
In our example, the user gives the prompt "Can you recommend solutions
for reducing carbon emissions?" and ChatGPT responds with the following
recommendations:
Conclusion
In this chapter, we explored the RECOMMEND SOLUTIONS directive in prompt
engineering for ChatGPT. By leveraging the RECOMMEND SOLUTIONS directive,
we can prompt ChatGPT to generate tailored recommendations, solutions, or
suggestions for various problems or challenges.
81
26. Prompt Engineering – EXPLAIN CONCEPT
Prompt Engineering
Prompt
In this example, the user asks for an explanation of the concept of artificial
intelligence. The response from ChatGPT includes a detailed explanation
generated based on the given prompt.
82
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
83
Prompt Engineering
The chat_prompt variable contains the user's prompt and the ChatGPT
response, including the EXPLAIN CONCEPT directive to explain the concept
of blockchain.
Output
When we run the script, we will receive the generated response from
ChatGPT, including the detailed explanation specified within the EXPLAIN
CONCEPT directive.
In our example, the user gives the prompt: "Can you explain the concept
of blockchain?" and ChatGPT explains the concept with the following output:
Conclusion
In this chapter, we explored the EXPLAIN CONCEPT directive in prompt
engineering for ChatGPT. By utilizing the EXPLAIN CONCEPT directive, we
can prompt ChatGPT to deliver clear and detailed explanations of various
concepts, topics, or ideas.
84
27. Prompt Engineering – OUTLINE STEPS
Prompt Engineering
Prompt
Using the OUTLINE STEPS directive, we can leverage the capabilities of ChatGPT
to generate structured outlines or step-by-step procedures for various tasks or
processes. This technique enables us to tap into ChatGPT's knowledge and
organization abilities to provide clear and concise instructions.
In this example, the user asks for an outline of the steps to bake a cake.
The response from ChatGPT includes a structured outline with step-by-step
instructions generated based on the given prompt.
85
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
86
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, including the structured outline with step-by-step instructions
specified within the OUTLINE STEPS directive.
Here the user prompt is "Can you outline the steps to assemble a piece of
furniture?" and ChatGPT will respond with an output which would be similar
to the following one:
Conclusion
In this chapter, we explored the OUTLINE STEPS directive in prompt
engineering for ChatGPT. Using the OUTLINE STEPS directive, we can
prompt ChatGPT to generate structured outlines or step-by-step procedures
for various tasks or processes.
87
28. Prompt Engineering – DESCRIBE
PromptBENEFITS
Engineering
Prompt
In this example, the user asks for a description of the benefits of regular
exercise. The response from ChatGPT includes a detailed description of the
benefits generated based on the given prompt.
88
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
89
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, including the detailed description of the benefits specified within
the DESCRIBE BENEFITS directive.
In this example, the user prompt is "Can you describe the benefits of eating
a balanced diet?" and ChatGPT would respond with an output like the one
shown below:
Conclusion
In this chapter, we explored the DESCRIBE BENEFITS directive in prompt
engineering for ChatGPT. Using the DESCRIBE BENEFITS directive, we can
prompt ChatGPT to provide detailed descriptions of the advantages, benefits,
or positive outcomes associated with a particular choice, action, or decision.
90
29. Prompt Engineering – EXPLAINPrompt
DRAWBACKS
Engineering
Prompt
In this example, the user asks for an explanation of the drawbacks of using
social media excessively. The response from ChatGPT includes a detailed
explanation of the drawbacks generated based on the given prompt.
91
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
92
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, including the detailed description of the benefits specified within
the DESCRIBE BENEFITS directive.
In our example, the user prompt is "Can you explain the drawbacks of using
online shopping?" and ChatGPT would respond with an output like the one
shown below:
Conclusion
In this chapter, we explored the EXPLAIN DRAWBACKS directive in prompt
engineering for ChatGPT. Using the EXPLAIN DRAWBACKS directive, we can prompt
ChatGPT to provide detailed explanations of the disadvantages, limitations, or
negative aspects associated with a particular choice, action, or decision.
93
30. Prompt Engineering – SHORTEN Prompt
Prompt Engineering
In this example, the user asks for a brief explanation of the concept of
artificial intelligence. The response from ChatGPT includes a concise and
shortened explanation generated based on the given prompt.
94
Prompt Engineering
specific details you are seeking. This helps ChatGPT generate more
focused and accurate responses.
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
95
Prompt Engineering
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes a shortened explanation of the theory of relativity.
In our example, the user prompt is "Can you explain the theory of relativity
in a few words?" and ChatGPT would respond with an output like the one
shown here:
Conclusion
In this chapter, we explored the SHORTEN directive in prompt engineering
for ChatGPT. Using the SHORTEN directive, we can prompt ChatGPT to
generate shorter and more concise responses.
96
31. Prompt Engineering – DESIGN
Prompt SCRIPT
Engineering
Prompt
In this example, the user asks for a script to sort an array in ascending
order. The response from ChatGPT includes a custom Python script
generated based on the given prompt.
97
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=100,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
98
Prompt Engineering
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes a custom Python script to calculate the factorial of
a number.
In our example, the user prompt is "Can you design a script to calculate the
factorial of a number?" and ChatGPT would respond with an output like the
one shown below:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
Conclusion
In this chapter, we explored the DESIGN SCRIPT directive in prompt
engineering for ChatGPT. Using the DESIGN SCRIPT directive, we can
prompt ChatGPT to generate custom scripts or code snippets to accomplish
specific tasks or solve problems.
99
32. Prompt Engineering – CREATIVE SURVEY
Prompt Engineering
Prompt
In this example, the user asks for a creative survey response for the
question, "What is your favorite book?" The response from ChatGPT
includes an imaginative and unique survey response generated based on
the given prompt.
Vary the Tone and Style: Experiment with different tones and
styles in the survey responses. Prompt ChatGPT to generate
100
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
101
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes a creative and imaginative survey response for the
given question.
We got the following response for the user prompt given in our example:
Conclusion
In this chapter, we explored the CREATIVE SURVEY directive in prompt
engineering for ChatGPT. By utilizing the CREATIVE SURVEY directive, we can
prompt ChatGPT to generate imaginative and creative survey responses.
102
33. Prompt Engineering – ANALYZE WORKFLOW
Prompt Engineering
Prompt
In this example, the user asks ChatGPT to analyze their content creation
workflow and suggest improvements. The response from ChatGPT includes
an analysis of the workflow, along with valuable insights and suggestions
for optimizing it.
such as the steps involved, roles of individuals, and any pain points
or challenges faced.
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
104
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes an analysis of the workflow and valuable
suggestions for improvement.
Conclusion
In this chapter, we explored the ANALYZE WORKFLOW directive in prompt
engineering for ChatGPT. By utilizing the ANALYZE WORKFLOW directive,
we can prompt ChatGPT to analyze and provide insights on a given workflow
or process.
105
34. Prompt Engineering – DESIGN Prompt
ONBOARDING
Engineering
PROCESS Prompt
User: Can you design an onboarding process for our new customers?
In this example, the user asks for a designed onboarding process for new
customers. The response from ChatGPT includes a comprehensive outline
of the onboarding process, including key steps and recommendations.
106
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
107
Prompt Engineering
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes a comprehensive outline of the onboarding process
for new employees.
In our example, the user prompt is "Can you design an onboarding process
for our new employees?" and ChatGPT responds with the following output:
108
Prompt Engineering
Conclusion
In this chapter, we explored the DESIGN ONBOARDING PROCESS directive
in prompt engineering for ChatGPT. By utilizing the DESIGN ONBOARDING
PROCESS directive, we can prompt ChatGPT to design effective and
engaging onboarding processes for new users or employees.
109
35. Prompt Engineering – DEVELOP TRAINING
Prompt Engineering
PROGRAM Prompt
In this example, the user asks for the development of training materials for
customer service representatives. The response from ChatGPT includes an
outline of the training materials, including key topics and areas to cover.
110
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
111
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes an outline of the training materials for new
software developers.
In our example, the user prompt is "Develop a training material for
graphic designers?" and ChatGPT responds with the following output:
112
Prompt Engineering
Conclusion
In this chapter, we explored the DEVELOP TRAINING directive in prompt
engineering for ChatGPT. By utilizing the DEVELOP TRAINING directive, we can
prompt ChatGPT to generate training materials or resources for various topics.
113
36. Prompt Engineering – DESIGN FEEDBACK
Prompt Engineering
PROCESS Prompt
In this example, the user asks for the design of a feedback process for their
software development team. The response from ChatGPT includes an outline of
the feedback process, including key components and suggestions.
114
Prompt Engineering
Identify the Feedback Goals: Clearly define the goals and objectives
of the feedback process. Determine what outcomes you want to achieve
through the feedback mechanism, such as improving collaboration,
identifying areas for growth, or recognizing achievements.
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
115
Prompt Engineering
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes an outline of the feedback process for the
marketing team.
In our example, the user prompt is "Design a feedback process for
school teachers" and ChatGPT responds with the following output:
116
Prompt Engineering
Conclusion
In this chapter, we explored the DESIGN FEEDBACK PROCESS directive in
prompt engineering for ChatGPT. Using the DESIGN FEEDBACK PROCESS
directive, we can prompt ChatGPT to design effective and structured
feedback processes for various contexts.
117
37. Prompt Engineering – DEVELOP RETENTION
Prompt Engineering
STRATEGY Prompt
In this example, the user asks for the development of a retention strategy for
their customer base. The response from ChatGPT includes an outline of the
retention strategy, including key components and recommendations.
118
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
119
Prompt Engineering
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from ChatGPT,
which includes an outline of the retention strategy for the remote workforce.
In our example, the user prompt is "Can you develop a retention strategy for
our remote workforce?" and ChatGPT responds with the following output:
Conclusion
120
Prompt Engineering
121
38. Prompt Engineering – ANALYZE SEO
Prompt Prompt
Engineering
In this example, the user asks for an analysis of their website's SEO. The
response from ChatGPT includes an evaluation of different SEO aspects,
such as domain authority, meta-tags, page load speed, and content
optimization.
122
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
123
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes an evaluation of the website's SEO.
Here, the user prompt is "Analyze the SEO of our website" and ChatGPT
responds with the following output:
Conclusion
In this chapter, we explored the ANALYZE SEO directive in prompt
engineering for ChatGPT. By utilizing the ANALYZE SEO directive, we can
prompt ChatGPT to analyze and provide insights on SEO strategies for
websites.
124
39. Prompt Engineering – DEVELOP SALES
Prompt Engineering
STRATEGY Prompt
User: Can you develop a sales strategy for our new product?
In this example, the user asks for the development of a sales strategy for
their new product. The response from ChatGPT includes an outline of the
sales strategy, including key components and recommendations.
125
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
126
Prompt Engineering
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we will receive the generated response from
ChatGPT, which includes an outline of the sales strategy for the new service.
In our example, the user prompt is "Develop a sales strategy for a new
laptop brand" and ChatGPT responds with the following sales strategy:
Conclusion
127
Prompt Engineering
128
40. Prompt Engineering – CREATE PROJECT
Prompt Engineering
PLAN Prompt
User: Can you create a project plan for our website redesign?
In this example, the user asks for the creation of a project plan for their
website redesign. The response from ChatGPT includes a suggested project
plan, highlighting key tasks and milestones.
129
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
130
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When you run the script, you will receive the generated response from ChatGPT,
which includes a suggested project plan for the marketing campaign.
Here, the user prompt is "Create a project plan for our marketing
campaign?" and ChatGPT responds with the following output:
1. Set Goals: Define clear, measurable objectives and timeline for the
campaign.
2. Research: Analyze the target audience, competitors, and current market
trends.
3. Develop Content: Create relevant and engaging content for the
campaign.
4. Design Creative Assets: Design visuals and other creative elements.
5. Prepare a Budget: Estimate the costs associated with the campaign.
6. Set Up Tracking: Establish tracking and reporting metrics to measure
success.
7. Launch Campaign: Distribute content and track results.
8. Analyze Results: Review results to identify successes and areas for
improvement.
9. Refine Campaign: Adjust the campaign as needed to improve performance.
Conclusion
In this chapter, we explored the CREATE PROJECT PLAN directive in prompt
engineering for ChatGPT. By utilizing the CREATE PROJECT PLAN directive,
we can prompt ChatGPT to generate well-structured project plans for
various tasks and initiatives.
131
41. Prompt Engineering – ANALYZE CUSTOMER
Prompt Engineering
BEHAVIOR Prompt
132
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
133
Prompt Engineering
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
The chat_prompt variable contains our prompt and the ChatGPT response,
including the ANALYZE CUSTOMER BEHAVIOR directive to analyze customer
behavior to improve our product offerings.
Output
When we run the script, we receive the generated response from ChatGPT,
which includes an analysis of our customers' behavior and suggestions for
improvement.
In this case, the user prompt is "Analyze customers' behavior for our
new video course on Java" and ChatGPT responds with the following
recommendations:
134
Prompt Engineering
Conclusion
In this chapter, we explored the ANALYZE CUSTOMER BEHAVIOR directive
in prompt engineering for ChatGPT. Using the ANALYZE CUSTOMER
BEHAVIOR directive, we can prompt ChatGPT to analyze and gain insights
into customer behavior, allowing us to improve our marketing strategies
and make informed decisions.
135
42. Prompt Engineering – CREATE CONTENT
Prompt Engineering
STRATEGY Prompt
The basic syntax for the CREATE CONTENT STRATEGY directive is as follows:
In this example, the user wants to create a content strategy for a social media
campaign. The response from ChatGPT includes a suggested content strategy,
highlighting key steps such as defining campaign goals, conducting market
research, creating a content calendar, and developing engaging content.
136
Prompt Engineering
that help us understand the desired outcomes and tailor the content
strategy to meet the needs and preferences of our audience.
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
137
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we receive the generated response from ChatGPT,
which includes a suggested content strategy for the blog.
4. Create content:
-Write articles and other content
-Take photos and videos\n-Edit and format content
5. Publish content:
-Post content regularly on the blog
-Share content on social media
-Promote content through paid channels
Conclusion
In this chapter, we explored the CREATE CONTENT STRATEGY directive in
prompt engineering for ChatGPT. Using the CREATE CONTENT STRATEGY
directive, we can prompt ChatGPT to generate content strategies that align
with our objectives and resonate with our target audience.
139
43. Prompt Engineering – CREATE
Prompt EMAIL
Engineering
CAMPAIGN Prompt
140
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
141
Prompt Engineering
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
When we run the script, we receive a template from ChatGPT, which
includes a suggested email campaign for announcing the event.
Dear [Name],
We are excited to invite you to our upcoming event! This is an
event you won't want to miss out on.
At this event, you will have the opportunity to meet like-
minded individuals, network, and learn more about [topic]. We
hope you can join us!
Sincerely,
[Your Name]
142
Prompt Engineering
Conclusion
In this chapter, we explored the CREATE EMAIL CAMPAIGN directive in
prompt engineering for ChatGPT. Using the CREATE EMAIL CAMPAIGN
directive, we can prompt ChatGPT to generate email campaigns that
effectively promote our products, events, or offerings.
143
Prompt Engineering
144
44. Prompt Engineering – Prompts for
Prompt Engineering
Programmers
In this chapter, we will explore how programmers can leverage the power of
ChatGPT through prompt engineering. ChatGPT, with its natural language
processing capabilities, can be a valuable tool for programmers to enhance their
productivity, tackle coding challenges, and seek assistance.
Here is an example:
145
Prompt Engineering
Here is an example:
User: Can you help optimize this function for finding the
factorial of a number?
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n-1)
Here is an example:
146
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
Here, we got the following response from ChatGPT:
147
Prompt Engineering
Conclusion
In this chapter, we explored how programmers can utilize ChatGPT through
prompt engineering to enhance their coding experience. From interactive
coding assistance to exploring new concepts and seeking project planning
insights, ChatGPT can be a valuable tool in a programmer's toolkit.
148
45. Prompt Engineering – HR Based
Prompt Prompts
Engineering
In this chapter, we will explore how HR professionals can use the power of
ChatGPT through prompt engineering for HR-based tasks such as candidate
screening, employee onboarding and training, etc.
Here is an example:
Here is an example:
149
Prompt Engineering
User: We have a new employee starting next week. Can you help
draft a welcome message for their onboarding?
Best regards,
[Your Name]"
150
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
151
Prompt Engineering
response = generate_chat_response(chat_prompt)
print(response)
Output
In this case, we got the following output from ChatGPT:
Conclusion
In this chapter, we explored the application of prompt engineering in HR-
related tasks using ChatGPT. From candidate screening and behavioral
questions to employee onboarding and performance evaluations, HR
professionals can use HR-based prompts to streamline various aspects of
the employee lifecycle.
152
46. Prompt Engineering – Finance Based
Prompt Engineering
Prompts
Here is an example:
User: Can you provide insights into our company's revenue trends
for the past year?
Here is an example:
User: Can you calculate the current ratio for a company with
current assets of $500,000 and current liabilities of $250,000?
153
Prompt Engineering
Here is an example:
Here is an example:
154
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
155
Prompt Engineering
Output
ChatGPT would respond with an output like the one shown below:
Conclusion
In this chapter, we explored the application of prompt engineering in
finance, empowering finance professionals to optimize financial analysis,
investment decisions, risk management, and financial planning.
156
47. Prompt Engineering – Marketing Based
Prompt Engineering
Prompts
Here is an example:
Here is an example:
157
Prompt Engineering
Here is an example:
158
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
159
Prompt Engineering
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
We got the following response from ChatGPT:
Conclusion
Using marketing-based prompts, marketers can create impactful campaigns,
connect with customers on a personal level, and drive business growth.
ChatGPT can serve as a valuable tool for marketers in gaining valuable market
insights and implementing data-driven marketing strategies.
160
48. Prompt Engineering – Customer Care
Prompt Based
Engineering
Prompts
161
Prompt Engineering
Here is an example:
162
Prompt Engineering
import openai
def generate_chat_response(prompt):
163
Prompt Engineering
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
Here, we got the following output:
164
Prompt Engineering
Conclusion
Using customer care-based prompts, companies can build stronger
customer relationships, enhance customer satisfaction, and foster brand
loyalty. ChatGPT serves as a valuable tool for customer care teams who
want to optimize customer interactions and deliver memorable experiences.
165
49. Prompt Engineering – ChainPrompt
of Thought
Engineering
Prompts
166
Prompt Engineering
Nurturing the Chain: As the chain progresses, guide the model to explore
deeper and more detailed concepts. Encourage it to connect ideas logically
and creatively.
Take a look at the following example:
User: We need captivating copy for our social media posts. Can
you provide some copywriting prompts?
167
Prompt Engineering
import openai
168
Prompt Engineering
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
In this case, we got the following output:
169
Prompt Engineering
8. How can you create content that encourages user generated content?
9. What visual content can you create to capture people's attention?
10. What hashtags can you use to increase visibility and engagement?
Conclusion
In this chapter, we explored the concept of Chain of Thought Prompting and
its potential to stimulate continuous streams of ideas and coherent thought
processes. By implementing this technique with ChatGPT, businesses and
individuals can unlock deeper exploration, creative brainstorming, and
effective problem-solving.
As you incorporate Chain of Thought Prompting into your conversational
approach, you can discover new insights, build upon ideas, and fuel creative
exploration like never before.
170
50. Prompt Engineering – Ask Before Answer
Prompt Engineering
Prompts
In this chapter, we will explore the concept of Ask Before Answer Prompting
and how it can be used to encourage ChatGPT to seek clarifications or additional
information from users before providing responses. This technique can improve
the accuracy and relevance of ChatGPT's answers, making it a valuable tool for
obtaining more precise information and minimizing misunderstandings.
171
Prompt Engineering
Conclusion
In this chapter, we explored the concept of Ask Before Answer Prompting
and its potential to enhance the precision and relevance of ChatGPT's
responses.
173
51. Prompt Engineering – Fill-In-The-Blank
Prompt Engineering
Prompts
User: Complete the sentence: "The capital city of France is [BLANK]. "
174
Prompt Engineering
175
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
176
Prompt Engineering
Output
In this case, we got the following output:
Conclusion
By leaving certain parts of the prompt blank, businesses and individuals can
engage in co-creative activities with the model and obtain specific,
contextually relevant information. Fill-In-The-Blank Prompting enhances
user engagement and allows for personalized and tailored responses.
177
52. Prompt Engineering – Perspective Prompts
Prompt Engineering
In this chapter, we will delve into the concept of Perspective Prompting and
its application in guiding ChatGPT to respond from specific viewpoints or
perspectives.
178
Prompt Engineering
179
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
180
Prompt Engineering
Output
Here, we got the following output:
Conclusion
By adopting different perspectives, businesses and individuals can obtain
persona-driven responses that align with specific roles, opinions, or
backgrounds. Perspective Prompting enables enhanced personalization,
improved contextual understanding, and a more interactive and engaging
user experience.
181
53. Prompt Engineering – Constructive Critic
Prompt Engineering
Prompts
182
Prompt Engineering
183
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
184
Prompt Engineering
Output
Here, we received the following constructive criticism as the output:
Conclusion
Constructive Critic Prompting fosters a positive user experience,
encouraging engagement and continued growth. As you incorporate
Constructive Critic Prompting into your interactions with ChatGPT, you can
expect to receive thoughtful and actionable feedback that enhances your
projects.
185
54. Prompt Engineering – Comparative Prompts
Prompt Engineering
186
Prompt Engineering
187
Prompt Engineering
import openai
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
In this case, we got the following output:
Electric Cars:
Advantages:
- No emissions, making them more environmentally friendly
- Cheaper to run in the long run due to lower energy costs
- Quieter engines
Disadvantages:
- Initial cost is usually higher
188
Prompt Engineering
Conclusion
Comparative Prompting enables a comprehensive analysis of various
alternatives, enhancing decision-making processes. By providing a basis for
comparison, businesses and individuals can make well-informed decisions,
solve problems, and assess the viability of potential solutions.
189
55. Prompt Engineering – Reverse Prompts
Prompt Engineering
190
Prompt Engineering
import openai
191
Prompt Engineering
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
In this case, we got the following output:
Conclusion
In this chapter, we explored Reverse Prompting and its potential to engage
ChatGPT in a dynamic dialogue by instructing the model to ask questions.
By promoting creative exploration and self-reflection, Reverse Prompting
allows users to discover new insights and ideas. The interactive nature of
Reverse Prompting enhances user engagement, encouraging dynamic and
thought-provoking conversations with ChatGPT.
192
56. Prompt Engineering – Social Media Prompts
Prompt Engineering
193
Prompt Engineering
"📚 Tell us your current read and what you love about it!
#BookLoversUnite"
import openai
194
Prompt Engineering
def generate_chat_response(prompt):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
Here, we got the following output:
Conclusion
As you incorporate Social Media Prompts into your social media strategy,
you can expect to see increased user engagement, valuable insights, and a
stronger connection with your audience. Remember to stay current with
social media trends and adapt your prompts to suit the ever-changing
landscape of social media platforms.
195
Prompt Engineering
196
57. Prompt Engineering – Advanced Prompts
Prompt Engineering
Contextual Prompts
Leveraging Contextual Information: Contextual Prompts involve
providing ChatGPT with relevant background information or context
to guide its responses. By incorporating context, ChatGPT can deliver
more accurate and personalized answers.
Multi-Turn Conversations
Conversational Memory: With the gpt-3.5-turbo model, you can
simulate a multi-turn conversation by passing a list of messages as
input. Each message includes a role (either "system", "user", or
"assistant") and the content of the message. This way, ChatGPT can
maintain a conversational memory.
197
Prompt Engineering
Summary
In this chapter, we explored advanced Prompt Engineering techniques to
enhance the capabilities of ChatGPT. By incorporating context, multi-turn
conversations, and conditional logic, you can elevate your interactions with
ChatGPT to a more sophisticated level. These advanced strategies enable
more personalized and dynamic conversations, unlocking the full potential
of ChatGPT as a versatile language model.
198
58. Prompt Engineering – New Ideas
Prompt and Copy
Engineering
Generation
With the help of ChatGPT, businesses and individuals can stimulate their
creativity, brainstorm innovative concepts, and craft compelling copy for
various purposes. In this chapter, we will explore how prompt engineering
can be used to generate new ideas and creative copy.
User: We have a basic outline for a blog post. Can you help us
expand on it with additional prompts?
199
Prompt Engineering
User: We need captivating copy for our social media posts. Can
you provide some copywriting prompts?
200
Prompt Engineering
import openai
def generate_chat_response(prompt):
201
Prompt Engineering
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=500,
temperature=0.7,
n=1,
stop=None
)
return response
response = generate_chat_response(chat_prompt)
print(response)
Output
Here, we got the following output:
202
Prompt Engineering
Conclusion
In this chapter, we explored the application of prompt engineering for
generating new ideas and creative copy with the assistance of ChatGPT. By
using "idea generation" prompts, businesses can stimulate creativity and
discover novel concepts for various projects.
203
59. Prompt Engineering – Ethical Considerations
Prompt Engineering
204
Prompt Engineering
205
Prompt Engineering
Conclusion
In this chapter, we emphasized the importance of ethical considerations in
prompt engineering. Bias mitigation, privacy protection, transparency,
inclusivity, and user consent are all essential aspects of ethical prompt
engineering.
206
60. Prompt Engineering – Do's Prompt
andEngineering
Don'ts
207
Prompt Engineering
Conclusion
Understanding task requirements, using contextually relevant prompts, and
iterating for improvement are crucial aspects of successful prompt
engineering. Avoiding ambiguous prompts and considering ethical
considerations ensures responsible and reliable prompt design.
208
61. Prompt Engineering – UsefulPrompt
Libraries and
Engineering
Frameworks
Key Features
Pre-trained Models: Hugging Face Transformers provides access
to a wide range of pre-trained language models, such as GPT-3,
BERT, RoBERTa, and more, which can be fine-tuned for prompt
engineering tasks.
Key Features
GPT-3 Language Model: The API grants access to the GPT-3
language model, enabling prompt engineers to generate
contextually relevant responses based on custom prompts.
209
Prompt Engineering
AllenNLP
AllenNLP is a natural language processing library built on PyTorch, offering
a wide range of NLP functionalities for research and production applications.
Key Features
Pre-trained Models: AllenNLP provides pre-trained models for
various NLP tasks, which can be used as a starting point for prompt
engineering projects.
Key Features
Scalable Pipelines: TFX allows prompt engineers to create
scalable, reusable, and production-ready prompt engineering
pipelines for fine-tuning and evaluation.
210
Prompt Engineering
Sentence Transformers
Sentence Transformers is a library specifically designed for sentence and
text embeddings, offering useful tools for prompt engineering projects.
Key Features
Sentence Embeddings: Sentence Transformers provides pre-
trained models to generate high-quality embeddings for sentences
or phrases, making them suitable for prompt representations.
Conclusion
In this chapter, we explored various useful libraries and frameworks that
prompt engineers can use to streamline their prompt engineering projects.
211
62. Prompt Engineering – Case Prompt
Studies and
Engineering
Examples
212
Prompt Engineering
Conclusion
In this chapter, we explored case studies and examples of prompt
engineering projects in different domains. From customer support chatbots
to creative writing assistants and multilingual customer service, prompt
engineering has demonstrated its versatility and effectiveness in a variety
of applications. These case studies highlight the practical benefits of prompt
engineering and illustrate its potential to optimize language models for
diverse use-cases and domains.
213
63. Prompt Engineering – Emerging Trends
Prompt Engineering
Multimodal Prompting
Multimodal prompting involves incorporating multiple modes of input such
as text, images, audio, and video, to generate more contextually relevant
responses from language models.
214
Prompt Engineering
Explainable Prompting
Explainable prompting focuses on making prompt-based language models
more interpretable and transparent in their decision-making. Researchers
are working on techniques to provide explanations or justifications for
model responses, allowing prompt engineers to better understand model
behavior and identify potential biases or errors.
Conclusion
In this chapter, we explored the emerging trends in prompt engineering
that are shaping the future of language models and NLP applications.
Multimodal prompting, transfer learning, GPT variants, domain-specific
215
Prompt Engineering
216