เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

สร้าง few-shot prompt template

เมื่อมี examples ในรูปแบบที่จัดโครงสร้างแล้ว ก็ถึงเวลาสร้าง few-shot prompt template! จะสร้าง template ที่แปลงคู่คำถาม-คำตอบให้อยู่ในรูปแบบต่อไปนี้:

Question: Example question
Example Answer

คลาสทั้งหมดของ LangChain ที่จำเป็นสำหรับแบบฝึกหัดนี้ได้โหลดไว้ให้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

ดูคอร์ส

คำแนะนำการฝึกหัด

  • กำหนด prompt สำหรับจัดรูปแบบคำตอบให้ครอบคลุม key question และ answer
  • สร้าง few-shot prompt โดยใช้ FewShotPromptTemplate พร้อมระบุ examples และ example_prompt
  • กำหนดรายการ input variables ให้สอดคล้องกับ suffix ที่กำหนดไว้

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Complete the prompt for formatting answers
example_prompt = PromptTemplate.from_template("Question: {____}\n{____}")

# Create the few-shot prompt
prompt_template = ____(
    examples=____,
    example_prompt=____,
    suffix="Question: {input}",
    input_variables=["____"],
)

prompt = prompt_template.invoke({"input": "What is Jack's favorite technology on DataCamp?"})
print(prompt.text)
แก้ไขและรันโค้ด