Sử dụng các thông tin hội thoại đã trích xuất
Giờ là lúc áp dụng LLM với đầu ra có cấu trúc! llm_with_output bạn đã tạo ở bài trước vẫn còn sẵn, và mẫu prompt cho LLM này đã được cung cấp.
Bài tập này là một phần của khóa học
Graph RAG với LangChain và Neo4j
Hướng dẫn bài tập
- Pipe mẫu chat prompt đã cho vào LLM với đầu ra có cấu trúc (
llm_with_output). - Gọi chain với user và session ID đã cung cấp, truyền vào các message từ history (
history).
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
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": ____})