Skip to content
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

Add check for prompt based approach in llm graph transformer #26519

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions libs/experimental/langchain_experimental/graph_transformers/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,20 @@ def process_response(
if isinstance(parsed_json, dict):
parsed_json = [parsed_json]
for rel in parsed_json:
# Check if mandatory properties are there
if (
not rel.get("head")
or not rel.get("tail")
or not rel.get("relation")
):
continue
# Nodes need to be deduplicated using a set
nodes_set.add((rel["head"], rel["head_type"]))
nodes_set.add((rel["tail"], rel["tail_type"]))
# Use default Node label for nodes if missing
nodes_set.add((rel["head"], rel.get("head_type", "Node")))
nodes_set.add((rel["tail"], rel.get("tail_type", "Node")))

source_node = Node(id=rel["head"], type=rel["head_type"])
target_node = Node(id=rel["tail"], type=rel["tail_type"])
source_node = Node(id=rel["head"], type=rel.get("head_type", "Node"))
target_node = Node(id=rel["tail"], type=rel.get("tail_type", "Node"))
relationships.append(
Relationship(
source=source_node, target=target_node, type=rel["relation"]
Expand Down
Loading