การสร้าง graph documents
มีเอกสารชื่อ famous_scientists ที่มีข้อความเกี่ยวกับนักวิทยาศาสตร์ชื่อดังในศตวรรษที่ 20 ในแบบฝึกหัดนี้ จะได้แปลงข้อมูลข้อความที่ไม่มีโครงสร้างนี้ให้กลายเป็น graph documents แบบมีโครงสร้างโดยใช้ LLMs
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Retrieval Augmented Generation (RAG) ด้วย LangChain
คำแนะนำการฝึกหัด
- กำหนด OpenAI chat LLM ที่ให้ผลลัพธ์แบบแน่นอนสูงสุด
- สร้าง LLM graph transformer สำหรับแปลง LangChain documents ให้เป็น graph documents
- แปลง text documents (
docs) ให้เป็น graph documents โดยใช้llm_transformer
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Define the LLM
llm = ____(api_key="", model="gpt-4o-mini", ____)
# Instantiate the LLM graph transformer
llm_transformer = ____
# Convert the text documents to graph documents
graph_documents = ____
print(f"Derived Nodes:\n{graph_documents[0].nodes}\n")
print(f"Derived Edges:\n{graph_documents[0].relationships}")