-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
experimental: LLMGraphTransformer - added relationship properties. #21856
base: master
Are you sure you want to change the base?
experimental: LLMGraphTransformer - added relationship properties. #21856
Conversation
…LLMGraphTransformer(llm=llm, relationship_properties=["Condition", "Time"],)
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
cc @tomasonjo |
LGTM... can you add node and relationship property description to docstring? |
@istvan-nebulinq can you please fix lint errors and I can add docstring later if needed |
Yes. Will do asap. |
@tomasonjo done. passed my local tests (now including lint). synced with main as well. |
@istvan-nebulinq thank you! Cc @baskaryan |
@istvan-nebulinq can you run
|
Executed the command in the root dir. Here is the output: |
Try executing in libs/experimental
V čet., 30. maj 2024, 12:56 je oseba istvan-nebulinq <
***@***.***> napisala:
… make format
Executed the command in the root dir. Here is the output:
vscode ➜ /workspaces/langchain (graphtransformer_fix) $ make format
poetry run ruff format docs templates cookbook
1403 files left unchanged
poetry run ruff check --select I --fix docs templates cookbook
All checks passed!
—
Reply to this email directly, view it on GitHub
<#21856 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYGGTIX3WOLVWNXTVUCUMDZE6AAHAVCNFSM6AAAAABH46WLAOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBQG43DSOJYGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Head branch was pushed to by a user without write access
it worked. I've pushed the changes in that one file. vscode ➜ /workspaces/langchain/libs/experimental (graphtransformer_fix) $ make format vscode ➜ /workspaces/langchain/libs/experimental (graphtransformer_fix) $ make format |
@istvan-nebulinq Sorry for the trouble, and then make sure to rerun the format again |
@tomasonjo it's all good. thanks for your patience while I get up to speed with the flow. |
So those type of tests that require API keys or connection to database are placed under integration tests |
cc @baskaryan |
yep. that or ideally you mock out the model call and keep it a unit test, since its not openai behavior that this test should be checking |
The generated relationships in the graph had no properties, but the Relationship class was properly defined with properties. This made it very difficult to transform conditional sentences into a graph. Adding properties to relationships can solve this issue elegantly.
The changes expand on the existing LLMGraphTransformer implementation but add the possibility to define allowed relationship properties like this: LLMGraphTransformer(llm=llm, relationship_properties=["Condition", "Time"],)
no issue found
n/a
@IstvanSpace
-Quick Test
from dotenv import load_dotenv
import os
from langchain_community.graphs import Neo4jGraph
from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.documents import Document
load_dotenv()
os.environ["NEO4J_URI"] = os.getenv("NEO4J_URI")
os.environ["NEO4J_USERNAME"] = os.getenv("NEO4J_USERNAME")
os.environ["NEO4J_PASSWORD"] = os.getenv("NEO4J_PASSWORD")
graph = Neo4jGraph()
llm = ChatOpenAI(temperature=0, model_name="gpt-4o")
llm_transformer = LLMGraphTransformer(llm=llm)
#text = "Harry potter likes pies, but only if it rains outside"
text = "Jack has a dog named Max. Jack only walks Max if it is sunny outside."
documents = [Document(page_content=text)]
llm_transformer_props = LLMGraphTransformer(
llm=llm,
relationship_properties=["Condition"],
)
graph_documents_props = llm_transformer_props.convert_to_graph_documents(documents)
print(f"Nodes:{graph_documents_props[0].nodes}")
print(f"Relationships:{graph_documents_props[0].relationships}")
graph.add_graph_documents(graph_documents_props)