forked from rahat15/AI-Interview-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlangraph_visual.py
More file actions
42 lines (34 loc) · 1.44 KB
/
Copy pathlangraph_visual.py
File metadata and controls
42 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from graphviz import Digraph
from langgraph.graph import StateGraph
# ---- Setup LangGraph ----
graph = StateGraph()
graph.add_node("Intro")
graph.add_node("Ask Question")
graph.add_node("Evaluate Answer")
graph.add_node("Follow-up Decision")
graph.add_node("End")
graph.add_edge("Intro", "Ask Question")
graph.add_edge("Ask Question", "Evaluate Answer")
graph.add_edge("Evaluate Answer", "Follow-up Decision")
graph.add_edge("Follow-up Decision", "Ask Question") # loop
graph.add_edge("Follow-up Decision", "End")
# ---- Simple Visualizer ----
def render_graph(active_node=None):
dot = Digraph(comment="Interview Flow", format="png")
nodes = ["Intro", "Ask Question", "Evaluate Answer", "Follow-up Decision", "End"]
for n in nodes:
if n == active_node:
dot.node(n, n, style="filled", fillcolor="lightgreen", shape="box")
else:
dot.node(n, n, shape="box")
dot.edge("Intro", "Ask Question")
dot.edge("Ask Question", "Evaluate Answer")
dot.edge("Evaluate Answer", "Follow-up Decision")
dot.edge("Follow-up Decision", "Ask Question", label="follow-up")
dot.edge("Follow-up Decision", "End", label="end")
file_path = dot.render("interview_flow")
print(f"Graph rendered at {file_path}")
# ---- Simulate running interview ----
for node in ["Intro", "Ask Question", "Evaluate Answer", "Follow-up Decision", "End"]:
print(f"\n▶️ Running node: {node}")
render_graph(active_node=node)