Umer797 commited on
Commit
1aeb5f9
·
verified ·
1 Parent(s): 485fdc3

Update graph_builder.py

Browse files
Files changed (1) hide show
  1. graph_builder.py +19 -9
graph_builder.py CHANGED
@@ -1,29 +1,39 @@
1
  from langgraph.graph import StateGraph
 
2
  from llm_node import llm_node
3
  from formatter_node import formatter_node
4
 
5
  def build_graph():
6
  graph = StateGraph(dict)
7
 
8
- def llm_step(state):
 
 
9
  question = state.get("question")
10
  if not question:
11
- raise ValueError("Missing 'question' in state")
12
- llm_output = llm_node(question) # ✅ uses HuggingFaceHub now
13
- state["llm_output"] = llm_output
 
 
 
 
 
 
 
14
  return state
15
 
16
  def formatter_step(state):
17
- llm_output = state.get("llm_output")
18
- if not llm_output:
19
- raise ValueError("Missing 'llm_output' in state")
20
- final_answer = formatter_node(llm_output)
21
  state["final_answer"] = final_answer
22
  return state
23
 
 
24
  graph.add_node("llm", llm_step)
25
  graph.add_node("formatter", formatter_step)
26
- graph.set_entry_point("llm")
 
 
27
  graph.add_edge("llm", "formatter")
28
  graph.set_finish_point("formatter")
29
 
 
1
  from langgraph.graph import StateGraph
2
+ from langchain_community.tools import TavilySearchResults
3
  from llm_node import llm_node
4
  from formatter_node import formatter_node
5
 
6
  def build_graph():
7
  graph = StateGraph(dict)
8
 
9
+ search_tool = TavilySearchResults()
10
+
11
+ def search_step(state):
12
  question = state.get("question")
13
  if not question:
14
+ raise ValueError("Missing 'question'")
15
+ result = search_tool.run(question)
16
+ state["search_result"] = result
17
+ return state
18
+
19
+ def llm_step(state):
20
+ question = state.get("question")
21
+ search_result = state.get("search_result", "")
22
+ answer = llm_node(question, search_result)
23
+ state["llm_output"] = answer
24
  return state
25
 
26
  def formatter_step(state):
27
+ final_answer = formatter_node(state["llm_output"])
 
 
 
28
  state["final_answer"] = final_answer
29
  return state
30
 
31
+ graph.add_node("search", search_step)
32
  graph.add_node("llm", llm_step)
33
  graph.add_node("formatter", formatter_step)
34
+
35
+ graph.set_entry_point("search")
36
+ graph.add_edge("search", "llm")
37
  graph.add_edge("llm", "formatter")
38
  graph.set_finish_point("formatter")
39