Fakten aus Gesprächsverläufen extrahieren
Jetzt hebst du deinen Gesprächsverlauf auf das nächste Level! Du definierst pydantic-Klassen, um Fakten aus Gesprächsverläufen strukturiert zu extrahieren.
Damit legst du den Grundstein für die nächste und letzte Übung des Kurses, in der du die Extraktion tatsächlich durchführst.
Die benötigten pydantic-Klassen wurden bereits importiert, und ein llm ist schon definiert.
Diese Übung ist Teil des Kurses
<Kurs>Graph RAG mit LangChain und Neo4j</Kurs>Übungsanweisungen
- Definiere eine
pydantic-ConversationFact-Klasse, um Fakten aus einem Gespräch zu extrahieren; füge die Felderobject,subject,relationshipundsession_idhinzu, die den angegebenen Beschreibungen entsprechen. - Definiere eine
pydantic-ConversationFacts-Klasse, um Listen vonConversationFact-Objekten zu erstellen. - Binde das Format der strukturierten Ausgabe an das bereitgestellte
llm.
Interaktive praktische Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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.____(____)