Spaces:
Sleeping
Sleeping
Update graph_builder.py
Browse files- graph_builder.py +25 -0
graph_builder.py
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langgraph.graph import Graph
|
| 2 |
+
from llm_node import llm_node
|
| 3 |
+
from formatter_node import formatter_node
|
| 4 |
+
|
| 5 |
+
def build_graph():
|
| 6 |
+
graph = Graph()
|
| 7 |
+
|
| 8 |
+
def llm_step(state):
|
| 9 |
+
question = state["question"]
|
| 10 |
+
result = llm_node().run(question)
|
| 11 |
+
state["llm_output"] = result
|
| 12 |
+
return state
|
| 13 |
+
|
| 14 |
+
def formatter_step(state):
|
| 15 |
+
cleaned = formatter_node(state["llm_output"])
|
| 16 |
+
state["final_answer"] = cleaned
|
| 17 |
+
return state
|
| 18 |
+
|
| 19 |
+
graph.add_node("llm", llm_step)
|
| 20 |
+
graph.add_node("formatter", formatter_step)
|
| 21 |
+
graph.set_entry_point("llm")
|
| 22 |
+
graph.add_edge("llm", "formatter")
|
| 23 |
+
graph.set_finish_point("formatter")
|
| 24 |
+
|
| 25 |
+
return graph
|