การนำข้อเท็จจริงที่ดึงจากบทสนทนามาใช้งาน
ถึงเวลานำ LLM ที่มี structured outputs มาใช้งานแล้ว! llm_with_output ที่สร้างไว้ในแบบฝึกหัดก่อนหน้ายังคงพร้อมใช้งาน และ prompt template สำหรับ LLM นี้ได้เตรียมไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Graph RAG ด้วย LangChain และ Neo4j
คำแนะนำการฝึกหัด
- เชื่อมต่อ chat prompt template ที่กำหนดให้เข้ากับ LLM ที่มี structured output (
llm_with_output) ด้วย pipe - เรียกใช้ chain โดยส่ง user ID และ 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": ____})