diff --git a/brickllm/compiled_graphs.py b/brickllm/compiled_graphs.py index cd72b58..280f8e4 100644 --- a/brickllm/compiled_graphs.py +++ b/brickllm/compiled_graphs.py @@ -1,3 +1,3 @@ from .graphs import BrickSchemaGraph -brickschema_graph = BrickSchemaGraph().compile() \ No newline at end of file +brickschema_graph = BrickSchemaGraph()._compiled_graph() \ No newline at end of file diff --git a/brickllm/graphs/brickschema_graph.py b/brickllm/graphs/brickschema_graph.py index 9bef294..a9f9b92 100644 --- a/brickllm/graphs/brickschema_graph.py +++ b/brickllm/graphs/brickschema_graph.py @@ -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. diff --git a/examples/brickschema_ttl.py b/examples/brickschema_ttl.py index 97ec173..e0948be 100644 --- a/examples/brickschema_ttl.py +++ b/examples/brickschema_ttl.py @@ -2,7 +2,6 @@ # Create an instance of BrickSchemaGraph brick_graph = BrickSchemaGraph() -brick_graph.compile() # Specify the user prompt building_description = """