Використання витягнутих фактів розмови
Час застосувати ваш LLM зі структурованими результатами! llm_with_output, який ви створили у попередній вправі, усе ще доступний, а шаблон підказки для цього LLM уже надано.
Ця вправа є частиною курсу
Graph RAG з LangChain і Neo4j
Інструкції до вправи
- Спрямуйте наданий шаблон чат-підказки до LLM зі структурованим результатом (
llm_with_output). - Запустіть ланцюжок на вказаних user і session 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": ____})