langchain/libs/experimental/langchain_experimental
Istvan/Nebulinq 513e491ce9
experimental: LLMGraphTransformer - added relationship properties. (#21856)
- **Description:** 
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"],)
- **Issue:** 
    no issue found
 - **Dependencies:**
    n/a
- **Twitter handle:** 
    @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)

---------

Co-authored-by: Istvan Lorincz <istvan.lorincz@pm.me>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
2024-06-14 14:41:04 -04:00
..
agents experimental[patch]/docs[patch]: Update links to security docs (#22864) 2024-06-13 20:29:34 +00:00
autonomous_agents experimental[patch]: return from HuggingGPT task executor task.run() exception (#20219) 2024-04-25 20:16:39 +00:00
chat_models infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
comprehend_moderation langchain: callbacks imports fix (#20348) 2024-04-12 20:13:14 +00:00
cpal Fix: lint errors and update Field alias in models.py and AutoSelectionScorer initialization (#22846) 2024-06-13 18:18:00 -07:00
data_anonymizer
fallacy_removal experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
generative_agents patch: deprecate (a)get_relevant_documents (#20477) 2024-04-22 11:14:53 -04:00
graph_transformers experimental: LLMGraphTransformer - added relationship properties. (#21856) 2024-06-14 14:41:04 -04:00
llm_bash infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
llm_symbolic_math experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
llms [experimental][llms][OllamaFunctions] tool calling related fixes (#22339) 2024-06-12 16:34:43 -04:00
open_clip
openai_assistant
pal_chain community[major], experimental[patch]: Remove Python REPL from community (#22904) 2024-06-14 17:53:29 +00:00
plan_and_execute experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
prompt_injection_identifier experimental[minor]: upgrade the prompt injection model (#20783) 2024-04-23 10:23:39 -04:00
prompts experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
pydantic_v1
recommenders infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
retrievers langchain: callbacks imports fix (#20348) 2024-04-12 20:13:14 +00:00
rl_chain infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
smart_llm experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
sql experimental[patch], docs: refine notebook for MyScale SelfQueryRetriever (#22016) 2024-05-22 21:49:01 +00:00
synthetic_data experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
tabular_synthetic_data experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
tools langchain: callbacks imports fix (#20348) 2024-04-12 20:13:14 +00:00
tot experimental[patch]: prompts import fix (#20534) 2024-04-18 16:09:11 -04:00
utilities experimental: clean python repl input(experimental:Added code for PythonREPL) (#20930) 2024-05-01 05:19:09 +00:00
video_captioning langchain: callbacks imports fix (#20348) 2024-04-12 20:13:14 +00:00
__init__.py
py.typed
text_splitter.py experimental[patch]: Makes regex customizable in text_splitter.py (SemanticChunker class) (#20485) 2024-04-25 00:32:40 +00:00