Prompting multi-étapes

Ingénierie des prompts avec l'API OpenAI

Fouad Trad

Machine Learning Engineer

Prompting multi-étapes

  • Décomposer un objectif final en une série d'étapes
  • Le modèle suit chaque étape pour arriver au résultat final
  • Les prompts multi-étapes sont utilisés pour :
    • Tâches séquentielles
    • Tâches cognitives

Diagram showing that a multi-step prompt is a prompt that gives the model a series of sequential steps to perform.

Ingénierie des prompts avec l'API OpenAI

Prompts multi-étapes sous forme de cartes au trésor

Image representing a treasure map along with some clues to find the treasure.

Ingénierie des prompts avec l'API OpenAI

Prompt en une seule étape : rédaction d'un blog

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 [...]
Ingénierie des prompts avec l'API OpenAI

Prompt multi-étapes : rédaction d'un article de blog

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))
Ingénierie des prompts avec l'API OpenAI

Rédaction d'un article de blog de voyage

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 [...]
Ingénierie des prompts avec l'API OpenAI

Analyse de l'exactitude de la solution

  • La vérification de l'exactitude de la solution nécessite plusieurs étapes
  • Exemple :
    • Code Python pour les fonctions de calcul

Image of a calculator

Ingénierie des prompts avec l'API OpenAI

Analyse de l'exactitude de la solution

Solution type pour vérifier

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
"""
Prompt en une seule étape :
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
Ingénierie des prompts avec l'API OpenAI

Prompting multi-étapes pour vérifier l'exactitude

Prompt multi-étapes :
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.
Ingénierie des prompts avec l'API OpenAI

Prompt multi-étapes vs few-shot prompt

Étapes

  • Dire explicitement ce qu'il doit faire

Diagram showing how a multi-step prompt breaks down the instruction into a series of steps in the input for the model to go over them one by one.

Ingénierie des prompts avec l'API OpenAI

Prompt multi-étapes vs few-shot prompt

Étapes

  • Dire explicitement ce qu'il doit faire

Diagram showing how a multi-step prompt breaks down the instruction into a series of steps in the input for the model to go over them one by one.

Shots

  • Modèle questions et réponses apprend de

Image showing how a few-shot prompt works, where the input to the model is a set of example questions and answers along with the question we want the model to answer.

Ingénierie des prompts avec l'API OpenAI

Passons à la pratique !

Ingénierie des prompts avec l'API OpenAI

Preparing Video For Download...