開始使用免費開始

使用擷取出的對話事實

現在來套用你具備結構化輸出的 LLM!你在前一題建立的 llm_with_output 仍可使用,且此 LLM 的提示模板已經提供。

本練習屬於課程

使用 LangChain 與 Neo4j 的 Graph RAG

檢視課程

練習說明

  • 將提供的聊天提示模板串接到具結構化輸出的 LLM(llm_with_output)。
  • 在給定的使用者與工作階段 ID 上呼叫該 chain,並傳入 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": ____})
編輯並執行程式碼