시작하기무료로 시작하기

대화 기록에서 사실 추출하기

이제 대화 기록 활용 수준을 한 단계 올려 볼까요? 대화 기록에서 사실을 구조화된 방식으로 추출하기 위한 pydantic 클래스를 정의해 보세요.

이는 본 강의의 다음이자 마지막 연습 문제에서 실제로 추출 작업을 수행하기 위한 밑바탕이 될 거예요.

필요한 pydantic 클래스는 이미 임포트되어 있고, llm도 미리 정의되어 있어요.

이 연습은 강의의 일부입니다

LangChain과 Neo4j로 배우는 Graph RAG

강의 보기

연습 안내

  • 대화에서 사실을 추출하기 위한 pydantic ConversationFact 클래스를 정의하세요. 제공된 설명에 맞게 object, subject, relationship, session_id 필드를 포함하세요.
  • ConversationFact 객체의 목록을 만들기 위한 pydantic ConversationFacts 클래스를 정의하세요.
  • 제공된 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.____(____) 
코드 편집 및 실행