Utilizzare i fatti estratti dalla conversazione
È il momento di applicare il tuo LLM con output strutturati! L'llm_with_output che hai creato nell'esercizio precedente è ancora disponibile e il prompt template per questo LLM è già stato fornito.
Questo esercizio fa parte del corso
Graph RAG con LangChain e Neo4j
Istruzioni dell'esercizio
- Collega (pipe) il chat prompt template fornito all'LLM con output strutturato (
llm_with_output). - Esegui la chain sull'ID utente e di sessione forniti, passandole i messaggi dalla cronologia (
history).
esercizio interattivo pratico
Prova questo esercizio completando questo codice di esempio.
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": ____})