始める無料で始める

抽出した会話ファクトの活用

では、構造化出力に対応した LLM を使ってみましょう。前の演習で作成した llm_with_output は引き続き利用できます。この LLM 用のプロンプトテンプレートもすでに用意されています。

この演習はコースの一部です

Graph RAG with LangChain and Neo4j

コースを見る

演習の手順

  • 提供されたチャットプロンプトテンプレートを、構造化出力対応の LLM(llm_with_output)へパイプします。
  • 指定されたユーザー ID とセッション ID でチェーンを起動し、history からメッセージを渡します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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": ____})
コードを編集して実行