mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
Add check for prompt based approach in llm graph transformer (#26519)
This commit is contained in:
parent
0bd98c99b3
commit
3bcd641bc1
@ -749,12 +749,20 @@ class LLMGraphTransformer:
|
||||
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"]
|
||||
|
Loading…
Reference in New Issue
Block a user