FrancescaScipioni commited on
Commit
3f8f511
·
verified ·
1 Parent(s): 97bdee5

added search tools

Browse files
Files changed (1) hide show
  1. agent.py +40 -9
agent.py CHANGED
@@ -1,4 +1,5 @@
1
  from langchain.tools import Tool
 
2
  import math
3
 
4
  ## ----- TOOLS DEFINITION ----- ##
@@ -123,15 +124,45 @@ def logarithm(a: float, base: float = math.e) -> float:
123
  raise ValueError("Logarithm arguments must be positive")
124
  return math.log(a, base)
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  ## ----- TOOLS LIST ----- ##
127
 
128
  tools = [
129
- add_numbers,
130
- subtract_numbers,
131
- multiply_numbers,
132
- divide_numbers,
133
- power,
134
- modulus,
135
- square_root,
136
- logarithm
137
- ]
 
 
 
 
 
1
  from langchain.tools import Tool
2
+ from langchain.utilities import WikipediaAPIWrapper, ArxivAPIWrapper, DuckDuckGoSearchRun
3
  import math
4
 
5
  ## ----- TOOLS DEFINITION ----- ##
 
124
  raise ValueError("Logarithm arguments must be positive")
125
  return math.log(a, base)
126
 
127
+ # ** Search Tools ** #
128
+
129
+ # DuckDuckGo Web Search
130
+ duckduckgo_search = DuckDuckGoSearchRun()
131
+ web_search_tool = Tool.from_function(
132
+ func=duckduckgo_search.run,
133
+ name="Web Search",
134
+ description="Use this tool to search the internet for general-purpose queries."
135
+ )
136
+
137
+ # Wikipedia Search
138
+ wikipedia_search = WikipediaAPIWrapper()
139
+ wikipedia_tool = Tool.from_function(
140
+ func=wikipedia_search.run,
141
+ name="Wikipedia Search",
142
+ description="Use this tool to search Wikipedia for factual or encyclopedic information."
143
+ )
144
+
145
+ # ArXiv Search
146
+ arxiv_search = ArxivAPIWrapper()
147
+ arxiv_tool = Tool.from_function(
148
+ func=arxiv_search.run,
149
+ name="ArXiv Search",
150
+ description="Use this tool to search ArXiv for scientific papers. Input should be a research topic or query."
151
+ )
152
+
153
  ## ----- TOOLS LIST ----- ##
154
 
155
  tools = [
156
+ # Math
157
+ Tool.from_function(func=add_numbers, name="Add Numbers", description="Add two numbers."),
158
+ Tool.from_function(func=subtract_numbers, name="Subtract Numbers", description="Subtract two numbers."),
159
+ Tool.from_function(func=multiply_numbers, name="Multiply Numbers", description="Multiply two numbers."),
160
+ Tool.from_function(func=divide_numbers, name="Divide Numbers", description="Divide two numbers."),
161
+ Tool.from_function(func=power, name="Power", description="Raise one number to the power of another."),
162
+ Tool.from_function(func=modulus, name="Modulus", description="Compute the modulus (remainder) of a division."),
163
+ Tool.from_function(func=square_root, name="Square Root", description="Compute the square root of a number."),
164
+ Tool.from_function(func=logarithm, name="Logarithm", description="Compute the logarithm of a number with a given base."),
165
+ # Search
166
+ web_search_tool,
167
+ wikipedia_tool,
168
+ arxiv_tool