Menggunakan fakta percakapan yang diekstrak
Sekarang saatnya menerapkan LLM Anda dengan keluaran terstruktur! llm_with_output yang Anda buat pada latihan sebelumnya masih tersedia, dan templat prompt untuk LLM ini sudah disediakan.
Latihan ini merupakan bagian dari kursus
Graph RAG dengan LangChain dan Neo4j
Instruksi latihan
- Lakukan pipe templat prompt chat yang disediakan ke LLM dengan keluaran terstruktur (
llm_with_output). - Panggil rantai pada user dan ID sesi yang diberikan, dengan meneruskan pesan-pesan dari riwayat (
history).
Latihan interaktif langsung praktik
Cobalah latihan ini dengan melengkapi kode contoh ini.
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": ____})