Видобування фактів з історій розмов
Переходимо на новий рівень роботи з історією розмов! Ви визначите класи 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.____(____)