Incorporating external context

ChatGPT Prompt Engineering for Developers

Fouad Trad

Machine Learning Engineer

The need for external context

  • Pre-trained language models recognize information they are trained on
  • Need to provide more context
  • More accuracy and effectiveness

Icon representing a chatbot on a mobile phone.

ChatGPT Prompt Engineering for Developers

Lack of information in LLMs

  • Knowledge cut-off
system_prompt = "Act as a financial expert that knows about the latest trends."

user_prompt = "What are the top financial trends in 2023?"

print(get_response(system_prompt, user_prompt))
I apologize for any inconvenience, but as of my last knowledge update in 
September 2021, I don't have information about financial trends in 2023.
ChatGPT Prompt Engineering for Developers

Lack of information in LLMs

  • Requested non-public information
system_prompt = "Act as a study buddy that helps me with my studies to succeed 
in exams."

user_prompt = "What is the name of my favorite instructor?" print(get_response(system_prompt, user_prompt))
I don't have personal information about you, including the name of your 
favorite instructor.
ChatGPT Prompt Engineering for Developers

How to give extra information?

  • Sample previous conversations
  • System's prompt

Icon showing two message dialog boxes to reflect a conversational aspect.

ChatGPT Prompt Engineering for Developers

Sample conversations

  • Guide model to answer specific questions
response = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[{"role": "system",
             "content": "You are a customer service chatbot that responds to user queries in a gentle way"},

{"role": "user", "content": "What services do you offer?"},
{"role": "assistant", "content": "We provide services for web application development, mobile app development, and custom software solutions."},
{"role": "user", "content": "How many services do you have?"}])
print(response.choices[0].message.content)
We have 3 services including web application development, mobile app development, and custom software solutions.
  • Disadvantage: might need a lot of samples
ChatGPT Prompt Engineering for Developers

System prompt

  • Includes required context for chatbot answers
services = "ABC Tech Solutions, a leading IT company, offers a range of services: 
application development, mobile app development, and custom software solutions."

system_prompt = f"""You are a customer service chatbot that responds to user queries in a gentle way. Some information about our services are delimited by triple backticks. ```{services}```"""
user_prompt = "How many services do you offer?" print(get_response(system_prompt, user_prompt))
We have 3 services including web application development, mobile app development, 
and custom software solutions.
ChatGPT Prompt Engineering for Developers

Final note

  • Previous methods work well for small contexts
  • Larger contexts require more sophisticated techniques

Icon representing an alert.

ChatGPT Prompt Engineering for Developers

Let's practice!

ChatGPT Prompt Engineering for Developers

Preparing Video For Download...