Satyam0077 commited on
Commit
f78d903
·
verified ·
1 Parent(s): 6158a38

Update pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +17 -30
pipeline.py CHANGED
@@ -4,54 +4,41 @@ from weather_node import fetch_weather
4
  from rag_node import rag_answer
5
  from llm_node import refine_answer
6
 
7
- # Graph state definition
8
  class AgentState(TypedDict):
9
  query: str
10
  result: str
11
 
12
- # Weather node
13
- def weather_node(state: AgentState) -> AgentState:
14
- city = state["query"].split()[-1]
15
- state["result"] = fetch_weather(city)
16
  return state
17
 
18
- # PDF node
19
- def rag_node_fn(state: AgentState) -> AgentState:
20
  state["result"] = rag_answer(state["query"])
21
  return state
22
 
23
- # Decision node
24
- def decision_node(state: AgentState) -> str:
25
  keywords = ["weather", "temperature", "forecast", "climate"]
26
- if any(word in state["query"].lower() for word in keywords):
27
- return "weather"
28
- return "rag"
29
 
30
- # LLM node
31
- def llm_node_fn(state: AgentState) -> AgentState:
32
- state["result"] = refine_answer(f"Summarize this: {state['result']}")
33
  return state
34
 
35
- # Build pipeline with LangGraph
36
  def build_pipeline():
37
- workflow = StateGraph(AgentState)
38
 
39
- # Add nodes
40
- workflow.add_node("weather", weather_node)
41
- workflow.add_node("rag", rag_node_fn)
42
- workflow.add_node("llm", llm_node_fn)
43
 
44
- # Start → Decision → Weather/PDF
45
- workflow.add_conditional_edges(
46
  START,
47
  decision_node,
48
- {"weather": "weather", "rag": "rag"},
49
  )
50
 
51
- # After weather or rag → go to llm → end
52
- workflow.add_edge("weather", "llm")
53
- workflow.add_edge("rag", "llm")
54
- workflow.add_edge("llm", END)
55
-
56
- return workflow.compile()
57
 
 
 
4
  from rag_node import rag_answer
5
  from llm_node import refine_answer
6
 
 
7
  class AgentState(TypedDict):
8
  query: str
9
  result: str
10
 
11
+ def weather_node_fn(state: AgentState):
12
+ state["result"] = fetch_weather(state["query"])
 
 
13
  return state
14
 
15
+ def rag_node_fn(state: AgentState):
 
16
  state["result"] = rag_answer(state["query"])
17
  return state
18
 
19
+ def decision_node(state: AgentState):
 
20
  keywords = ["weather", "temperature", "forecast", "climate"]
21
+ return "weather" if any(k in state["query"].lower() for k in keywords) else "rag"
 
 
22
 
23
+ def llm_node_fn(state: AgentState):
24
+ state["result"] = refine_answer(state["result"])
 
25
  return state
26
 
 
27
  def build_pipeline():
28
+ graph = StateGraph(AgentState)
29
 
30
+ graph.add_node("weather", weather_node_fn)
31
+ graph.add_node("rag", rag_node_fn)
32
+ graph.add_node("llm", llm_node_fn)
 
33
 
34
+ graph.add_conditional_edges(
 
35
  START,
36
  decision_node,
37
+ {"weather": "weather", "rag": "rag"}
38
  )
39
 
40
+ graph.add_edge("weather", "llm")
41
+ graph.add_edge("rag", "llm")
42
+ graph.add_edge("llm", END)
 
 
 
43
 
44
+ return graph.compile()