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

การระบุตัวอย่าง Few-Shot

แม้ว่า structured output จะกำหนดรูปแบบที่ต้องการให้ข้อมูลถูกส่งคืนมา แต่ยังคงมีความยืดหยุ่นในการตีความว่าควรส่งคืนอะไรบ้าง

คลาส Field ช่วยให้สามารถระบุค่าตัวอย่างเพื่อบอก LLM ว่าการดึงข้อมูลที่ดีควรมีหน้าตาอย่างไร นี่คือตัวอย่างของ few-shot prompting สำหรับ structured output

ในแบบฝึกหัดนี้ จะขยายคลาส Character ให้มีฟิลด์ id สำหรับระบุตัวละครแต่ละตัวอย่างไม่ซ้ำกัน โดยต้องการให้โมเดลอ้างอิงตัวอย่าง 2 รายการ ได้แก่ "romeo-montague" และ "lady-capulet"

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

Graph RAG ด้วย LangChain และ Neo4j

ดูคอร์ส

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

  • ระบุคีย์เวิร์ดสำหรับกำหนดค่าตัวอย่างให้กับ property id

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

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

class Character(BaseModel):
	id: str = Field(
		description="A unique identifer consisting of the Character's given name and their family name in slug case.", 
		# Provide example values of an ID
		____=["romeo-montague", "lady-capulet"]
	)
	name: str = Field(description="The name of the character")

chain = prompt | llm.with_structured_output(Character)

chain.invoke({"text": """JULIET.
O Romeo, Romeo, wherefore art thou Romeo? Deny thy father and refuse thy name. Or if thou wilt not, be but sworn my love, And I’ll no longer be a Capulet."""})
แก้ไขและรันโค้ด