Externen Kontext einbinden

Prompt-Engineering mit der OpenAI-API

Fouad Trad

Machine Learning Engineer

Der Bedarf an externem Kontext

  • Vortrainierte Sprachmodelle erkennen Informationen, auf die sie trainiert wurden.
  • Mehr Kontext erforderlich
  • Mehr Genauigkeit und Effektivität

Symbol für einen Chatbot auf einem Handy.

Prompt-Engineering mit der OpenAI-API

Mangel an Informationen in LLMs

  • Grenzen des Wissens
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.
Prompt-Engineering mit der OpenAI-API

Mangel an Informationen in LLMs

  • Erfragen nicht öffentlicher Informationen
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.
Prompt-Engineering mit der OpenAI-API

Wie kann man zusätzliche Informationen bereitstellen?

  • Beispiele früherer Unterhaltungen
  • System Prompt

Symbol mit zwei Nachrichtenfeldern, um den Gesprächscharakter zu zeigen.

Prompt-Engineering mit der OpenAI-API

Beispielgespräche

  • Ein Modell zur Beantwortung spezifischer Fragen befähigen
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.
  • Nachteil: Man braucht unter Umständen viele Beispiele.
Prompt-Engineering mit der OpenAI-API

System Prompt

  • Enthält den nötigen Kontext für Chatbot-Antworten
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.
Prompt-Engineering mit der OpenAI-API

Abschließende Bemerkung

  • Die bisherigen Methoden funktionieren gut für kleine Kontexte.
  • Größere Zusammenhänge erfordern ausgefeiltere Techniken.

Symbol für eine Warnung.

Prompt-Engineering mit der OpenAI-API

Lass uns üben!

Prompt-Engineering mit der OpenAI-API

Preparing Video For Download...