Multi-Step Prompting

Prompt-Engineering mit der OpenAI-API

Fouad Trad

Machine Learning Engineer

Multi-Step Prompting

  • Teilt ein Ziel in mehrere Schritte auf.
  • Das Modell geht jeden Schritt durch, um das Endergebnis zu liefern.
  • Multi-Step Prompts werden verwendet für:
    • Sequentielle Aufgaben
    • Kognitive Aufgaben

Diagramm, das zeigt, dass eine mehrstufige Prompt ein Prompt ist, die dem Modell eine Reihe von aufeinanderfolgenden Schritten vorgibt, die es ausführen soll.

Prompt-Engineering mit der OpenAI-API

Multi-Step Prompts als Schatzkarten

Bild, das eine Schatzkarte mit ein paar Hinweisen zum Finden des Schatzes zeigt.

Prompt-Engineering mit der OpenAI-API

Single-Step Prompt: Einen Blog schreiben

prompt = "Compose a travel blog"
print(get_response(prompt))
Title: Exploring the Enchanting Landscapes of Iceland

Introduction: Welcome to my travel blog! Today, I am thrilled to share my unforgettable journey through 
the mesmerizing landscapes of Iceland. 

Day 1: Reykjavik - The Charming Capital [...]
Day 2: Golden Circle - Nature's Wonders [...]
Day 3: South Coast - A Journey of Ice and Fire [...]
Day 4: Glacier Lagoon - A Frozen Wonderland [...]
Day 5: Blue Lagoon - A Relaxing Finale [...]
Prompt-Engineering mit der OpenAI-API

Multi-Step Prompt: Einen Blogbeitrag schreiben

prompt = """Compose a travel blog as follows:
Step 1: Introduce the destination.
Step 2: Share personal adventures during the trip.
Step 3: Summarize the journey.
"""
print(get_response(prompt))
Prompt-Engineering mit der OpenAI-API

Einen Reise-Blogbeitrag schreiben

Title: Exploring the Enchanting Streets of Barcelona

Step 1: Introduce the destination. Welcome to Barcelona, a vibrant city nestled along the stunning Mediterranean coast of Spain [...]
Step 2: Share personal adventures during the trip. Exploring the narrow, winding streets of the Gothic Quarter, I stumbled upon hidden gems at every turn. [...]
Step 3: Summarize the journey. As my journey through Barcelona came to an end, I couldn't help but feel grateful for the incredible experiences and memories I had made [...]
Prompt-Engineering mit der OpenAI-API

Lösungen auf Korrektheit analysieren

  • Die Überprüfung der Lösung erfordert mehrere Schritte.
  • Beispiel:
    • Python-Code für Berechnungsfunktionen

Bild eines Taschenrechners

Prompt-Engineering mit der OpenAI-API

Lösungen auf Korrektheit analysieren

Typische zu prüfende Lösung

calculator = """
def add(a, b):
    return a + b
def subtract(a, b):
    return a - b
def multiply(a, b):
    return a * b
def divide(a, b):
    return a / b
"""
Single-Step Prompt:
prompt = f"""Determine if the code delimited 
by triple backticks is correct or not.
Answer by yes or no.
```{calculator}```"""

print(get_response(prompt))
Yes
Prompt-Engineering mit der OpenAI-API

Multi-Step Prompting zur Analyse der Richtigkeit der Lösung

Multi-Step Prompt:
prompt = f"""Determine the correctness of the code delimited by triple backticks 
as follows: 
Step 1: Check the code correctness in each function. 
Step 2: Verify if the divide function handles the case when dividing by 0. 
Code: ```{calculator}```"""

print(get_response(prompt))
The code appears to be correct. It defines four functions: add, subtract, multiply, and 
divide. Each function performs the corresponding mathematical operation and returns the
result. However, it does not handle the case when dividing by 0, which can result in a 
ZeroDivisionError.
Prompt-Engineering mit der OpenAI-API

Multi-Step Prompt versus Few-Shot Prompt

Schritte

  • Sagen ganz klar, was es machen soll.

Diagramm, das zeigt, wie eine mehrstufige Prompt die Anweisung in eine Reihe von Schritten in der Eingabe aufteilt, damit das Modell sie nacheinander durchgehen kann.

Prompt-Engineering mit der OpenAI-API

Multi-Step Prompt versus Few-Shot Prompt

Schritte

  • Sagen ganz klar, was es machen soll.

Diagramm, das zeigt, wie eine mehrstufige Prompt die Anweisung in eine Reihe von Schritten in der Eingabe aufteilt, damit das Modell sie nacheinander durchgehen kann.

Shots

  • Lernen aus Fragen und Antworten

Bild, das zeigt, wie ein Few-Shot-Prompt funktioniert, bei dem die Eingabe für das Modell aus Beispielfragen und -antworten sowie der Frage besteht, die das Modell beantworten soll.

Prompt-Engineering mit der OpenAI-API

Lass uns üben!

Prompt-Engineering mit der OpenAI-API

Preparing Video For Download...