Spaces:
Sleeping
Sleeping
Create masterGraph.py
Browse files- src/graphs/masterGraph.py +34 -0
src/graphs/masterGraph.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langgraph.graph import StateGraph, START, END
|
| 2 |
+
from src.nodes.masterNode import MasterOrchestrator
|
| 3 |
+
from src.states.masterState import MasterState
|
| 4 |
+
from src.llms.groqllm import GroqLLM
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class MasterBuilder:
|
| 8 |
+
def __init__(self, llm, ):
|
| 9 |
+
self.llm = llm
|
| 10 |
+
|
| 11 |
+
def build_master_graph(self):
|
| 12 |
+
master_obj = MasterOrchestrator(self.llm)
|
| 13 |
+
master_graph = StateGraph(MasterState)
|
| 14 |
+
|
| 15 |
+
# Add nodes
|
| 16 |
+
master_graph.add_node("orchestrator", master_obj.orchestrator)
|
| 17 |
+
master_graph.add_node("worker_executor", master_obj.worker_executor)
|
| 18 |
+
master_graph.add_node("synthesizer", master_obj.synthesizer)
|
| 19 |
+
|
| 20 |
+
# Add edges
|
| 21 |
+
master_graph.add_edge(START, "orchestrator")
|
| 22 |
+
master_graph.add_conditional_edges("orchestrator", master_obj.assign_workers, ["worker_executor"])
|
| 23 |
+
master_graph.add_edge("worker_executor", "synthesizer")
|
| 24 |
+
master_graph.add_edge("synthesizer", END)
|
| 25 |
+
|
| 26 |
+
return master_graph.compile()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# Building the graph
|
| 31 |
+
llm = GroqLLM().get_llm()
|
| 32 |
+
graph_builder = MasterBuilder(llm)
|
| 33 |
+
master_graph = graph_builder.build_master_graph()
|
| 34 |
+
print("Graph created successfully")
|