generated from langchain-ai/integration-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement serialization and deserialization of graph documents
- Loading branch information
1 parent
b3172d8
commit 4af76b9
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
30 changes: 30 additions & 0 deletions
30
libs/experimental/tests/unit_tests/graph/test_save_load_graph_document.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
from langchain_experimental.graph_transformers import LLMGraphTransformer | ||
from langchain_core.documents import Document | ||
from langchain_openai import ChatOpenAI | ||
|
||
llm = ChatOpenAI(temperature=0, model_name="gpt-4o-2024-08-06") | ||
llm_transformer = LLMGraphTransformer(llm=llm) | ||
|
||
def test_save_load_graph_document(): | ||
|
||
text = """ | ||
Marie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity. | ||
She was the first woman to win a Nobel Prize, the first person to win a Nobel Prize twice, and the only person to win a Nobel Prize in two scientific fields. | ||
Her husband, Pierre Curie, was a co-winner of her first Nobel Prize, making them the first-ever married couple to win the Nobel Prize and launching the Curie family legacy of five Nobel Prizes. | ||
She was, in 1906, the first woman to become a professor at the University of Paris. | ||
""" | ||
documents = [Document(page_content=text)] | ||
graph_documents = llm_transformer.convert_to_graph_documents(documents) | ||
|
||
intermediate_file_name = "graph_document.pkl" | ||
llm_transformer.save_graph_documents(graph_documents, intermediate_file_name) | ||
|
||
loaded_graph_documents = llm_transformer.load_graph_documents(intermediate_file_name) | ||
|
||
# deleting the file after testing | ||
os.remove(intermediate_file_name) | ||
|
||
# checking all the both graph documents are same or not | ||
assert graph_documents == loaded_graph_documents |