From a0eac981389d98b9b95685604de137a2a6a8a64d Mon Sep 17 00:00:00 2001 From: Gagan Singh Date: Tue, 22 Oct 2024 15:54:03 +0100 Subject: [PATCH 1/4] Changes to make OpenAI key work for dataStoreAgent --- backend/src/utils/semantic_layer_builder.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/utils/semantic_layer_builder.py b/backend/src/utils/semantic_layer_builder.py index c030e623..4a16ddb5 100644 --- a/backend/src/utils/semantic_layer_builder.py +++ b/backend/src/utils/semantic_layer_builder.py @@ -150,8 +150,14 @@ async def enrich_nodes_properties(llm, model, finalised_graph_structure): for new_node in enriched_node_properties["nodeProperties"]: label = new_node["label"] properties_to_add = new_node["properties"] - - for node in finalised_graph_structure["nodes"]: + # Determine if the structure has nested 'nodes' or not + if isinstance(finalised_graph_structure["nodes"], dict): + # Nodes are nested under a "nodes" key in a dictionary in the case of OpenAI + node_list = finalised_graph_structure["nodes"]["nodes"] + else: + # Nodes are directly in the list in the case of Mistral + node_list = finalised_graph_structure["nodes"] + for node in node_list: if node["label"] == label: if "properties" not in node: node["properties"] = [] From ee09a3ec267009563a26e4073f6095117e08d3ac Mon Sep 17 00:00:00 2001 From: Gagan Singh Date: Wed, 23 Oct 2024 13:51:43 +0100 Subject: [PATCH 2/4] Pushing the changes for the Rel error for mistral --- backend/src/utils/semantic_layer_builder.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/utils/semantic_layer_builder.py b/backend/src/utils/semantic_layer_builder.py index 4a16ddb5..7cd94089 100644 --- a/backend/src/utils/semantic_layer_builder.py +++ b/backend/src/utils/semantic_layer_builder.py @@ -123,8 +123,11 @@ async def enriched_rel_properties(llm, model, finalised_graph_structure): # Merge properties for new_rel in enriched_rel_properties["relProperties"]: - relationship_type = new_rel["relType"] - properties_to_add = new_rel["property"] + #FS-67 - This change was done as relType is unavailable here for mistral. + relationship_type = new_rel.get("relType", None) + if relationship_type is None: + continue # Skip if there's no relationship type specified + properties_to_add = new_rel.get("property", None) for rel in finalised_graph_structure["relationships"]: if rel["cypher_representation"] == relationship_type: @@ -150,7 +153,7 @@ async def enrich_nodes_properties(llm, model, finalised_graph_structure): for new_node in enriched_node_properties["nodeProperties"]: label = new_node["label"] properties_to_add = new_node["properties"] - # Determine if the structure has nested 'nodes' or not + # FS-67 - Determine if the structure has nested 'nodes' or not if isinstance(finalised_graph_structure["nodes"], dict): # Nodes are nested under a "nodes" key in a dictionary in the case of OpenAI node_list = finalised_graph_structure["nodes"]["nodes"] From 095c2bb0f4ffd1891cfb70dccab957a0717147a0 Mon Sep 17 00:00:00 2001 From: Gagan Singh Date: Wed, 23 Oct 2024 14:17:14 +0100 Subject: [PATCH 3/4] Added a comment about teh code being temporary. --- backend/src/utils/semantic_layer_builder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/utils/semantic_layer_builder.py b/backend/src/utils/semantic_layer_builder.py index 7cd94089..9a863530 100644 --- a/backend/src/utils/semantic_layer_builder.py +++ b/backend/src/utils/semantic_layer_builder.py @@ -154,6 +154,7 @@ async def enrich_nodes_properties(llm, model, finalised_graph_structure): label = new_node["label"] properties_to_add = new_node["properties"] # FS-67 - Determine if the structure has nested 'nodes' or not + # This is a temporary code as we will change it in future to have LLM return the same structure for both Mistral and OpenAI. if isinstance(finalised_graph_structure["nodes"], dict): # Nodes are nested under a "nodes" key in a dictionary in the case of OpenAI node_list = finalised_graph_structure["nodes"]["nodes"] From e46d2f1734ac1ebd1786782021cf7ab58b7d7d88 Mon Sep 17 00:00:00 2001 From: Gagan Singh Date: Wed, 23 Oct 2024 14:19:08 +0100 Subject: [PATCH 4/4] Fixing the lint error --- backend/src/utils/semantic_layer_builder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/utils/semantic_layer_builder.py b/backend/src/utils/semantic_layer_builder.py index 9a863530..5a9a6d9d 100644 --- a/backend/src/utils/semantic_layer_builder.py +++ b/backend/src/utils/semantic_layer_builder.py @@ -154,7 +154,8 @@ async def enrich_nodes_properties(llm, model, finalised_graph_structure): label = new_node["label"] properties_to_add = new_node["properties"] # FS-67 - Determine if the structure has nested 'nodes' or not - # This is a temporary code as we will change it in future to have LLM return the same structure for both Mistral and OpenAI. + # This is a temporary code as we will change it in future to have LLM return the same structure for both Mistral + # and OpenAI. if isinstance(finalised_graph_structure["nodes"], dict): # Nodes are nested under a "nodes" key in a dictionary in the case of OpenAI node_list = finalised_graph_structure["nodes"]["nodes"]