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

การดึงข้อเท็จจริงจากประวัติการสนทนา

ได้เวลายกระดับประวัติการสนทนากันแล้ว! ในแบบฝึกหัดนี้จะได้กำหนดคลาส pydantic สำหรับดึงข้อเท็จจริงจากประวัติการสนทนาในรูปแบบที่มีโครงสร้างชัดเจน

ขั้นตอนนี้เป็นการวางรากฐานสำหรับแบบฝึกหัดสุดท้ายของคอร์ส ซึ่งจะได้ทำการดึงข้อมูลจริง

คลาส pydantic ที่จำเป็นได้นำเข้ามาแล้ว และกำหนด llm ไว้ให้เรียบร้อยแล้ว

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

Graph RAG ด้วย LangChain และ Neo4j

ดูคอร์ส

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

  • กำหนดคลาส pydantic ชื่อ ConversationFact สำหรับดึงข้อเท็จจริงจากการสนทนา โดยให้มีฟิลด์ object, subject, relationship และ session_id ตรงตามคำอธิบายที่กำหนดไว้
  • กำหนดคลาส pydantic ชื่อ ConversationFacts สำหรับสร้างรายการของออบเจกต์ ConversationFact
  • ผูกรูปแบบผลลัพธ์แบบมีโครงสร้างเข้ากับ llm ที่กำหนดไว้

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

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

# Define the ConversationFact with the correct fields
class ____(____):
    """
    A class that holds the facts from a conversation in a format of object, subject, predicate.

    For example, if the conversation includes the fact that the user likes ice creamthe facts would be:
    - object: "Adam"
    - subject: "ice cream"
    - relationship: "LIKES"
    The class also includes a session ID to identify the conversation.
    """
    ____: str = Field(description="The session ID of the conversation.")
    ____: str = Field(description="The object of the fact. For example, 'Adam' ")
    ____: str = Field(description="The subject of the fact. For example, 'Ice cream'")
    ____: str = Field(description="The relationship between the object and the subject.  This should be a single word verb in upper case. For example, 'LIKES' or 'OWNS'")

# Define a ConversationFacts class for creating lists of ConversationFact objects
class ____(____):
    """A class that holds a list of ConversationFact objects."""
    facts: list[____] = Field(description="A list of ConversationFact objects.")

# Bind the output to the llm provided
llm_with_output = llm.____(____) 
แก้ไขและรันโค้ด