Extraindo fatos de históricos de conversa
Hora de elevar o nível do seu histórico de conversa! Você vai definir classes pydantic para extrair fatos de históricos de conversa de forma estruturada.
Isso vai preparar o terreno para o próximo e último exercício do curso, no qual você fará a extração de fato.
As classes necessárias do pydantic já foram importadas e um llm já foi definido.
Este exercicio faz parte do curso
Graph RAG com LangChain e Neo4j
Instruções do exercicio
- Defina uma classe
pydanticConversationFactpara extrair fatos de uma conversa; inclua os camposobject,subject,relationshipesession_idque correspondam às descrições fornecidas. - Defina uma classe
pydanticConversationFactspara criar listas de objetosConversationFact. - Vincule o formato de saída estruturada ao
llmfornecido.
exercicio interativo prático
Tente este exercicio 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.____(____)