Update tools.py
Browse files
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 |
-
|
39 |
-
def calculator_function(state: 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 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
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) ->
|
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 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
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)
|