MulaiMulai sekarang secara gratis

Creating graph documents

You've been provided with a document called famous_scientists containing a paragraph of text about famous scientists from the 20th century. In this exercise, you'll transform this unstructured text data into structured graph documents using LLMs!

Latihan ini adalah bagian dari kursus

Retrieval Augmented Generation (RAG) with LangChain

Lihat Kursus

Petunjuk latihan

  • Define an OpenAI chat LLM that will produce maximally deterministic responses.
  • Instantiate an LLM graph transformer for converting LangChain documents into graph documents.
  • Convert the text documents (docs) to graph documents using llm_transformer.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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}")
Edit dan Jalankan Kode