Chapter 4
Chapter 4
for chatbot
development
C H AT G P T P R O M P T E N G I N E E R I N G F O R D E V E L O P E R S
Fouad Trad
Machine Learning Engineer
The need for prompt engineering for chatbots
Difficult to predict user questions
Challenge to guarantee effective responses
response = client.chat.completions.create(
model="gpt-3.5-turbo",
```python
messages=[{"role": "system",
"content": "You are an expert data scientist that explains complex concepts in simple terms"},
{"role": "user",
"content": "What is prompt engineering?"}]
)
print(response.choices[0].message.content)
Imagine you're giving instructions to a computer program, like teaching a robot to make a sandwich.
Prompt engineering is all about crafting those instructions, or "prompts," in a way that helps the
computer understand and perform the task better.
print(get_response(system_prompt, user_prompt))
I'm a financial chatbot that answers financial questions. How can I help you?
print(get_response(system_prompt, user_prompt))
In summary, cryptocurrencies have the potential to offer various benefits, but their adoption and impact
on the financial landscape are still evolving [...]
"""
"""
print(get_response(system_prompt, user_prompt))
Fouad Trad
Machine Learning Engineer
Role-playing prompts
Tell chatbot to play a specific role
Chatbot -> actor in a play
Offers assistance
Features
Security
print(get_response(system_response, user_response))
- Evaluate Your Financial Position: Begin by assessing your current financial situation [...]
- Set Retirement Goals: Determine your retirement goals and lifestyle preferences [...]
- Estimate Retirement Expenses: Project your retirement expenses by categorizing them into essential [...]
[...]
print(get_response(system_response, user_response))
As the technological landscape continues to evolve at an unprecedented pace, one of the most
significant transformations we're witnessing is the integration of Artificial Intelligence
(AI) into various industries [...].
While AI's potential to streamline processes [...]. Let's delve into the multifaceted impact
of AI on employment...
print(get_response(system_response, user_response))
Fouad Trad
Machine Learning Engineer
The need for external context
Pre-trained language models recognize
information they are trained on
system_prompt = "Act as a financial expert that knows about the latest trends."
print(get_response(system_prompt, user_prompt))
print(get_response(system_prompt, user_prompt))
I don't have personal information about you, including the name of your
favorite instructor.
System's prompt
We have 3 services including web application development, mobile app development, and custom software solutions.
Fouad Trad
Machine Learning Engineer
Chapter 1
CHAPTER 1
Key principles of prompt engineering
Delimited prompts
Conditional prompts
Structured outputs
CHAPTER 3
Text summarization and expansion
Text transformation
Text analysis
CHAPTER 3 CHAPTER 4
Text summarization and expansion System prompt engineering for chatbots