Multi-step prompting

Prompt Engineering กับ OpenAI API

Fouad Trad

Machine Learning Engineer

Multi-step prompting

  • แบ่งเป้าหมายออกเป็นชุดขั้นตอน
  • โมเดลดำเนินการทีละขั้นเพื่อให้ผลลัพธ์สุดท้าย
  • Multi-step prompt ใช้สำหรับ:
    • งานตามลำดับ
    • งานเชิงการคิด

ไดอะแกรมแสดงว่า multi-step prompt คือ prompt ที่กำหนดชุดขั้นตอนตามลำดับให้โมเดลดำเนินการ

Prompt Engineering กับ OpenAI API

Multi-step prompt เปรียบเหมือนแผนที่สมบัติ

ภาพแผนที่สมบัติพร้อมเบาะแสสำหรับค้นหาสมบัติ

Prompt Engineering กับ OpenAI API

Single-step prompt: เขียนบล็อก

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 กับ OpenAI API

Multi-step prompt: เขียนบล็อกโพสต์

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 กับ OpenAI API

เขียนบล็อกโพสต์ท่องเที่ยว

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 กับ OpenAI API

วิเคราะห์ความถูกต้องของโซลูชัน

  • การตรวจสอบความถูกต้องของโซลูชันต้องใช้หลายขั้นตอน
  • ตัวอย่าง:
    • โค้ด Python สำหรับฟังก์ชันคำนวณ

ภาพเครื่องคิดเลข

Prompt Engineering กับ OpenAI API

วิเคราะห์ความถูกต้องของโซลูชัน

โซลูชันตัวอย่างที่ต้องการตรวจสอบ

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 กับ OpenAI API

Multi-step prompting เพื่อวิเคราะห์ความถูกต้องของโซลูชัน

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 กับ OpenAI API

Multi-step prompt เทียบกับ few-shot prompt

ขั้นตอน (Steps)

  • บอกโมเดลอย่างชัดเจนว่าต้องทำอะไร

ไดอะแกรมแสดงว่า multi-step prompt แบ่งคำสั่งออกเป็นชุดขั้นตอนในอินพุต เพื่อให้โมเดลดำเนินการทีละขั้น

Prompt Engineering กับ OpenAI API

Multi-step prompt เทียบกับ few-shot prompt

ขั้นตอน (Steps)

  • บอกโมเดลอย่างชัดเจนว่าต้องทำอะไร

ไดอะแกรมแสดงว่า multi-step prompt แบ่งคำสั่งออกเป็นชุดขั้นตอนในอินพุต เพื่อให้โมเดลดำเนินการทีละขั้น

ตัวอย่าง (Shots)

  • คำถามและคำตอบที่โมเดลใช้เรียนรู้

ภาพแสดงการทำงานของ few-shot prompt ซึ่งอินพุตประกอบด้วยตัวอย่างคำถาม-คำตอบ พร้อมคำถามที่ต้องการให้โมเดลตอบ

Prompt Engineering กับ OpenAI API

มาฝึกกันเถอะ!

Prompt Engineering กับ OpenAI API

Preparing Video For Download...