Skip to content

Commit

Permalink
feat: move graph compilation inside class
Browse files Browse the repository at this point in the history
  • Loading branch information
PeriniM committed Oct 2, 2024
1 parent ff42d5a commit e753523
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion brickllm/compiled_graphs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .graphs import BrickSchemaGraph

brickschema_graph = BrickSchemaGraph().compile()
brickschema_graph = BrickSchemaGraph()._compiled_graph()
15 changes: 10 additions & 5 deletions brickllm/graphs/brickschema_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ def __init__(self):
self.workflow.add_edge("get_relationships", "get_sensors")
self.workflow.add_edge("get_sensors", END)

# Initialize the compiled graph
self.graph = None
# Compile graph
try:
self.graph = self.workflow.compile()
except Exception as e:
raise ValueError(f"Failed to compile the graph: {e}")

# Hardcoding the thread_id for now
self.config = {"configurable": {"thread_id": "1"}}

def compile(self):
"""Compile the workflow and update the compiled graph."""
self.graph = self.workflow.compile()
def _compiled_graph(self):
"""Check if the graph is compiled and return the compiled graph."""
if self.graph is None:
raise ValueError("Graph is not compiled yet. Please compile the graph first.")
return self.graph

def display(self, filename="graph.png"):
"""Display the compiled graph as an image.
Expand Down
1 change: 0 additions & 1 deletion examples/brickschema_ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Create an instance of BrickSchemaGraph
brick_graph = BrickSchemaGraph()
brick_graph.compile()

# Specify the user prompt
building_description = """
Expand Down

0 comments on commit e753523

Please sign in to comment.