ÎncepețiÎncepe gratuit

Extragerea faptelor din istoricul conversațiilor

Acum este momentul să duci istoricul conversațiilor la nivelul următor! Vei defini clase pydantic pentru extragerea faptelor din istoricul conversațiilor într-un mod structurat.

Aceasta va constitui baza pentru ultimul exercițiu al cursului, în care vei realiza efectiv extragerea.

Clasele pydantic necesare au fost deja importate, iar un llm a fost deja definit.

Acest exercițiu face parte din cursul

Graph RAG cu LangChain și Neo4j

Vezi cursul

Instrucțiuni pentru exercițiu

  • Definește o clasă pydantic ConversationFact pentru extragerea faptelor dintr-o conversație; include câmpurile object, subject, relationship și session_id care corespund descrierilor furnizate.
  • Definește o clasă pydantic ConversationFacts pentru crearea de liste de obiecte ConversationFact.
  • Leagă formatul de ieșire structurată la llm-ul furnizat.

Exercițiu interactiv practic

Încearcă acest exercițiu completând acest cod de exemplu.

# 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.____(____) 
Editează și rulează codul