Extracting facts from conversation histories
Now to level-up your conversation history! You'll define pydantic
classes for extracting facts from conversation histories in a structured way.
This will lay the brickwork for the next and final exercise of the course, where you'll actually perform the extraction.
The necessary pydantic
classes have already been imported, and an llm
has already been defined.
Este exercício faz parte do curso
Graph RAG with LangChain and Neo4j
Instruções do exercício
- Define a
pydantic
ConversationFact
class for extracting facts from a conversation; includeobject
,subject
,relationship
, andsession_id
fields that match the descriptions provided. - Define a
pydantic
ConversationFacts
class for creating lists ofConversationFact
objects. - Bind the structured output format to the
llm
provided.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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.____(____)