naman1102 commited on
Commit
477c627
·
1 Parent(s): 43b41d6

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +15 -15
tools.py CHANGED
@@ -35,8 +35,8 @@ class SearchState(BaseModel):
35
 
36
  def create_calculator_tool() -> Graph:
37
  """Creates a calculator tool using LangGraph that can perform basic arithmetic operations."""
38
- print("Creating calculator tool")
39
- def calculator_function(state: CalculatorState) -> CalculatorState:
40
  if len(state.input.numbers) < 2:
41
  raise ValueError("At least two numbers are required for calculation")
42
 
@@ -56,12 +56,12 @@ def create_calculator_tool() -> Graph:
56
  else:
57
  raise ValueError(f"Unsupported operation: {state.input.operation}")
58
 
59
- state.output = CalculatorOutput(
60
- result=result,
61
- operation=state.input.operation
62
- )
63
-
64
- return state
65
 
66
  # Create the graph with state schema
67
  workflow = StateGraph(state_schema=CalculatorState)
@@ -78,7 +78,7 @@ def create_calculator_tool() -> Graph:
78
  def create_search_tool() -> Graph:
79
  """Creates a search tool using DuckDuckGo that can search for information online."""
80
 
81
- def search_function(state: SearchState) -> SearchState:
82
  # Initialize DuckDuckGo search
83
  with DDGS() as ddgs:
84
  # Perform the search
@@ -97,12 +97,12 @@ def create_search_tool() -> Graph:
97
  for result in search_results
98
  ]
99
 
100
- state.output = SearchOutput(
101
- results=results,
102
- query=state.input.query
103
- )
104
-
105
- return state
106
 
107
  # Create the graph with state schema
108
  workflow = StateGraph(state_schema=SearchState)
 
35
 
36
  def create_calculator_tool() -> Graph:
37
  """Creates a calculator tool using LangGraph that can perform basic arithmetic operations."""
38
+
39
+ def calculator_function(state: CalculatorState) -> dict:
40
  if len(state.input.numbers) < 2:
41
  raise ValueError("At least two numbers are required for calculation")
42
 
 
56
  else:
57
  raise ValueError(f"Unsupported operation: {state.input.operation}")
58
 
59
+ return {
60
+ "output": CalculatorOutput(
61
+ result=result,
62
+ operation=state.input.operation
63
+ )
64
+ }
65
 
66
  # Create the graph with state schema
67
  workflow = StateGraph(state_schema=CalculatorState)
 
78
  def create_search_tool() -> Graph:
79
  """Creates a search tool using DuckDuckGo that can search for information online."""
80
 
81
+ def search_function(state: SearchState) -> dict:
82
  # Initialize DuckDuckGo search
83
  with DDGS() as ddgs:
84
  # Perform the search
 
97
  for result in search_results
98
  ]
99
 
100
+ return {
101
+ "output": SearchOutput(
102
+ results=results,
103
+ query=state.input.query
104
+ )
105
+ }
106
 
107
  # Create the graph with state schema
108
  workflow = StateGraph(state_schema=SearchState)