Zacznij terazZacznij za darmo

Ekstrakcja faktów z historii konwersacji

Czas ulepszyć historię konwersacji! Zdefiniujesz klasy pydantic do ekstrakcji faktów z historii konwersacji w ustrukturyzowany sposób.

To przygotuje grunt pod kolejne i zarazem ostatnie ćwiczenie w kursie, w którym faktycznie przeprowadzisz tę ekstrakcję.

Niezbędne klasy pydantic zostały już zaimportowane, a obiekt llm jest już zdefiniowany.

To ćwiczenie jest częścią kursu

Graph RAG z LangChain i Neo4j

Zobacz kurs

Instrukcje do ćwiczenia

  • Zdefiniuj klasę pydantic o nazwie ConversationFact do ekstrakcji faktów z konwersacji; uwzględnij pola object, subject, relationship oraz session_id zgodnie z podanymi opisami.
  • Zdefiniuj klasę pydantic o nazwie ConversationFacts do tworzenia list obiektów ConversationFact.
  • Powiąż strukturyzowany format wyjściowy z dostarczonym obiektem llm.

Interaktywne ćwiczenie praktyczne

Spróbuj tego ćwiczenia, uzupełniając ten przykładowy kod.

# 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.____(____) 
Edytuj i uruchom kod