시작하기무료로 시작하기

추출한 대화 사실 사용하기

이제 구조화된 출력을 사용하는 LLM을 적용해 볼까요? 이전 연습 문제에서 만든 llm_with_output은 여전히 사용할 수 있고, 이 LLM을 위한 프롬프트 템플릿도 이미 제공되어 있어요.

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

LangChain과 Neo4j로 배우는 Graph RAG

강의 보기

연습 안내

  • 제공된 채팅 프롬프트 템플릿을 구조화된 출력 LLM(llm_with_output)으로 파이프하세요.
  • 제공된 사용자 및 세션 ID로 체인을 호출하고, history의 메시지(messages)를 전달하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

chain = ChatPromptTemplate.from_messages([
    SystemMessagePromptTemplate.from_template("""
    	You are talking to {user}, the user of the application. 
        Any facts in the first person relate to {user}.
        The Session ID is {session_id}.
    	Extract the facts from the conversation and return them in the format of object, subject, predicate.
    """),
    # Pipe the chat prompt template into the LLM with structured output
    MessagesPlaceholder(variable_name="history")
]) | ____

# Invoke the chain, passing it the messages from the history
chain.invoke({"user": USER, "session_id": SESSION_ID, "history": ____})
코드 편집 및 실행