Solobrad commited on
Commit
f4c0a57
·
verified ·
1 Parent(s): 1f13d8d

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +84 -1
agent.py CHANGED
@@ -17,6 +17,57 @@ llm = HuggingFaceInferenceAPI(
17
  token=os.getenv("HF_TOKEN"),
18
  )
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  @tool
21
  def web_search(query: str) -> list:
22
  """Search Tavily for a query and return a maximum 3 results as LlamaIndex Documents.
@@ -74,6 +125,38 @@ wiki_search = FunctionTool(
74
  metadata=ToolMetadata(name="wiki_search", description="Wikipedia 2-hit search")
75
  )
76
 
77
- tools = [web_search, wiki_search]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  agent = AgentWorkflow.from_tools_or_functions(tools, llm=llm)
 
17
  token=os.getenv("HF_TOKEN"),
18
  )
19
 
20
+ @tool
21
+ def multiply(a: int, b: int) -> int:
22
+ """Multiply two numbers.
23
+ Args:
24
+ a: first int
25
+ b: second int
26
+ """
27
+ return a * b
28
+
29
+ @tool
30
+ def add(a: int, b: int) -> int:
31
+ """Add two numbers.
32
+
33
+ Args:
34
+ a: first int
35
+ b: second int
36
+ """
37
+ return a + b
38
+
39
+ @tool
40
+ def subtract(a: int, b: int) -> int:
41
+ """Subtract two numbers.
42
+
43
+ Args:
44
+ a: first int
45
+ b: second int
46
+ """
47
+ return a - b
48
+
49
+ @tool
50
+ def divide(a: int, b: int) -> int:
51
+ """Divide two numbers.
52
+
53
+ Args:
54
+ a: first int
55
+ b: second int
56
+ """
57
+ if b == 0:
58
+ raise ValueError("Cannot divide by zero.")
59
+ return a / b
60
+
61
+ @tool
62
+ def modulus(a: int, b: int) -> int:
63
+ """Get the modulus of two numbers.
64
+
65
+ Args:
66
+ a: first int
67
+ b: second int
68
+ """
69
+ return a % b
70
+
71
  @tool
72
  def web_search(query: str) -> list:
73
  """Search Tavily for a query and return a maximum 3 results as LlamaIndex Documents.
 
125
  metadata=ToolMetadata(name="wiki_search", description="Wikipedia 2-hit search")
126
  )
127
 
128
+ multiply_tool = FunctionTool(
129
+ multiply,
130
+ metadata=ToolMetadata(name="multiply", description="Multiply two numbers.")
131
+ )
132
+ add_tool = FunctionTool(
133
+ add,
134
+ metadata=ToolMetadata(name="add", description="Add two numbers.")
135
+ )
136
+ subtract_tool = FunctionTool(
137
+ subtract,
138
+ metadata=ToolMetadata(name="subtract", description="Subtract two numbers.")
139
+ )
140
+ divide_tool = FunctionTool(
141
+ divide,
142
+ metadata=ToolMetadata(name="divide", description="Divide two numbers.")
143
+ )
144
+ modulus_tool = FunctionTool(
145
+ modulus,
146
+ metadata=ToolMetadata(name="modulus", description="Modulus operation on two numbers.")
147
+ )
148
+
149
+ # Then include all tools in the list
150
+ tools = [
151
+ web_search,
152
+ wiki_search,
153
+ multiply_tool,
154
+ add_tool,
155
+ subtract_tool,
156
+ divide_tool,
157
+ modulus_tool
158
+ ]
159
+
160
+
161
 
162
  agent = AgentWorkflow.from_tools_or_functions(tools, llm=llm)