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

สร้าง retrieval prompt

หนึ่งในองค์ประกอบสำคัญของ RAG คือ retrieval prompt ในแบบฝึกหัดนี้ คุณจะสร้าง chat prompt template สำหรับ retrieval chain และทดสอบว่า LLM สามารถตอบโดยใช้เฉพาะ context ที่ให้ไว้ได้หรือไม่

มีการกำหนด llm ไว้ให้แล้ว

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

Retrieval Augmented Generation (RAG) ด้วย LangChain

ดูคอร์ส

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

  • แปลงสตริง prompt ให้เป็น chat prompt template ที่นำกลับมาใช้ซ้ำได้
  • สร้าง LCEL chain เพื่อเชื่อมต่อ prompt template กับ llm ที่กำหนดไว้
  • เรียกใช้ chain ด้วย inputs ที่กำหนด เพื่อตรวจสอบว่าโมเดลสามารถตอบโดยอิงจาก context ที่ให้ไว้เท่านั้นได้หรือไม่

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

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

prompt = """
Use the only the context provided to answer the following question. If you don't know the answer, reply that you are unsure.
Context: {context}
Question: {question}
"""

# Convert the string into a chat prompt template
prompt_template = ____

# Create an LCEL chain to test the prompt
chain = ____ | ____

# Invoke the chain on the inputs provided
print(chain.____({"context": "DataCamp's RAG course was created by Meri Nova and James Chapman!", "question": "Who created DataCamp's RAG course?"}))
แก้ไขและรันโค้ด