การนำบริบทภายนอกมาใช้

Prompt Engineering กับ OpenAI API

Fouad Trad

Machine Learning Engineer

ทำไมต้องมีบริบทภายนอก

  • โมเดลภาษาที่ผ่านการฝึกมาแล้วจะรู้จักเฉพาะข้อมูลที่ใช้ฝึก
  • จำเป็นต้องเพิ่มบริบทเพิ่มเติม
  • เพิ่มความแม่นยำและประสิทธิผล

ไอคอนแสดงแชทบอทบนโทรศัพท์มือถือ

Prompt Engineering กับ OpenAI API

ข้อจำกัดด้านข้อมูลใน LLM

  • ข้อมูลมีวันตัดรับ (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.
Prompt Engineering กับ OpenAI API

ข้อจำกัดด้านข้อมูลใน LLM

  • ขอข้อมูลที่ไม่เป็นสาธารณะ
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 กับ OpenAI API

จะเพิ่มข้อมูลให้โมเดลได้อย่างไร?

  • ตัวอย่างบทสนทนาก่อนหน้า
  • System prompt

ไอคอนแสดงกล่องข้อความสนทนาสองกล่อง

Prompt Engineering กับ OpenAI API

ตัวอย่างบทสนทนา

  • ช่วยให้โมเดลตอบคำถามเฉพาะด้านได้
response = client.chat.completions.create(
  model="gpt-4o-mini",
  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.
  • ข้อเสีย: อาจต้องใช้ตัวอย่างจำนวนมาก
Prompt Engineering กับ OpenAI API

System prompt

  • ใส่บริบทที่จำเป็นสำหรับคำตอบของแชทบอท
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 กับ OpenAI API

หมายเหตุสุดท้าย

  • วิธีก่อนหน้าเหมาะกับบริบทขนาดเล็ก
  • บริบทขนาดใหญ่ต้องใช้เทคนิคที่ซับซ้อนกว่า

ไอคอนแสดงการแจ้งเตือน

Prompt Engineering กับ OpenAI API

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

Prompt Engineering กับ OpenAI API

Preparing Video For Download...