alisamak commited on
Commit
e604d32
·
verified ·
1 Parent(s): 144e88d

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +9 -17
tools.py CHANGED
@@ -19,7 +19,6 @@ def search_duckduckgo(query: str) -> str:
19
  Use this when no other tool applies or you need open-ended facts from the internet.
20
  Returns the top result snippet.
21
  """
22
- print(f"🛠️ search_duckduckgo called with: {query}")
23
 
24
  with DDGS() as ddgs:
25
  results = ddgs.text(query, safesearch="Moderate")
@@ -34,7 +33,6 @@ def search_wikipedia(query: str) -> str:
34
  Search English Wikipedia and return a summary of the most relevant page.
35
  Use this for questions about people, dates, history, science, or named concepts.
36
  """
37
- print(f"🛠️ search_wikipedia called with: {query}")
38
 
39
  try:
40
  page = wikipedia.page(query)
@@ -53,7 +51,6 @@ def classify_vegetable(item: str) -> str:
53
  Use this for tasks involving scientific food classification.
54
  Returns 'vegetable' or 'fruit'.
55
  """
56
- print(f"🛠️ classify_vegetable called with: {item}")
57
 
58
  fruits = {"sweet potatoes", "plums", "bell pepper", "corn", "green beans"}
59
  if item.lower() in fruits:
@@ -68,7 +65,6 @@ def solve_chess_position(fen: str) -> str:
68
  Returns the best move for the current player.
69
  Use this for decision-making or evaluation in chess scenarios.
70
  """
71
- print(f"🛠️ solve_chess_position called with: {fen}")
72
 
73
  try:
74
  board = chess.Board(fen)
@@ -84,7 +80,6 @@ def math_solver(expression: str) -> str:
84
  Solve or simplify a symbolic math expression.
85
  Use this for algebraic simplifications or symbolic math steps.
86
  """
87
- print(f"🛠️ math_solver called with: {expression}")
88
 
89
  try:
90
  result = sympy.simplify(expression)
@@ -99,7 +94,6 @@ def document_search(filepath: str, query: str) -> str:
99
  Use this for information retrieval from uploaded documents.
100
  Returns the page text where the query was found.
101
  """
102
- print(f"🛠️ document_search called with: {filepath}, query={query}")
103
 
104
  try:
105
  doc = fitz.open(filepath)
@@ -118,7 +112,6 @@ def transcribe_audio(file_path: str) -> str:
118
  Use this when the user provides audio recordings.
119
  Returns the full transcript.
120
  """
121
- print(f"🛠️ transcribe_audio called with: {file_path}")
122
 
123
  try:
124
  model = whisper.load_model("small")
@@ -134,7 +127,6 @@ def search_imdb(title: str) -> str:
134
  Use this to identify media titles, actors, or related entertainment metadata.
135
  Returns the best matching title.
136
  """
137
- print(f"🛠️ search_imdb called with: {title}")
138
 
139
  try:
140
  ia = IMDb()
@@ -152,7 +144,6 @@ def run_python_code(code: str) -> str:
152
  Use this for running basic computations or logic blocks shared in string form.
153
  Returns the result of 'result' variable if defined.
154
  """
155
- print(f"🛠️ run_python_code called with code snippet:\n{code}")
156
 
157
  try:
158
  exec_globals = {}
@@ -168,7 +159,6 @@ def search_youtube_transcript(video_id: str) -> str:
168
  Use this for questions asking what was said in a specific video.
169
  Returns full transcript as plain text.
170
  """
171
- print(f"🛠️ search_youtube_transcript called with: {video_id}")
172
 
173
  try:
174
  transcript = YouTubeTranscriptApi.get_transcript(video_id)
@@ -182,7 +172,6 @@ def search_baseball_stats(player: str) -> str:
182
  Simulate a lookup of a baseball player's stats on Baseball Reference.
183
  Use this for sports questions involving MLB players.
184
  """
185
- print(f"🛠️ search_baseball_stats called with: {player}")
186
 
187
  try:
188
  url = f"https://www.baseball-reference.com/search/search.fcgi?search={player}"
@@ -200,7 +189,6 @@ def scrape_document(url: str) -> str:
200
  Download and extract raw text from a web page.
201
  Use this when needing the full text content of an online article.
202
  """
203
- print(f"🛠️ scrape_document called with: {url}")
204
 
205
  try:
206
  r = requests.get(url)
@@ -215,7 +203,6 @@ def search_zoological_database(query: str) -> str:
215
  Simulate a search in a zoological records database.
216
  Use for biological or species-related queries when the user references animal data.
217
  """
218
- print(f"🛠️ search_zoological_database called with: {query}")
219
 
220
  return f"Simulated search result for {query} in zoological database."
221
 
@@ -225,7 +212,6 @@ def search_olympic_database(country: str) -> str:
225
  Simulate a country search in an Olympics dataset.
226
  Use this for questions about Olympic history, participation, or medal stats by country.
227
  """
228
- print(f"🛠️ search_olympic_database called with: {country}")
229
 
230
  return f"Simulated search for {country} in Olympics database."
231
 
@@ -235,7 +221,6 @@ def search_baseball_roster(player_number: str) -> str:
235
  Simulate a roster lookup for a baseball player by jersey number.
236
  Use for lineup, identity, or number-matching tasks.
237
  """
238
- print(f"🛠️ search_baseball_roster called with: {player_number}")
239
 
240
  return f"Simulated search result for player number {player_number}."
241
 
@@ -246,7 +231,6 @@ def process_excel(file_path: str) -> str:
246
  Use this for business, finance, or menu data-related tasks.
247
  Returns total food sales as formatted currency.
248
  """
249
- print(f"🛠️ process_excel called with: {file_path}")
250
 
251
  try:
252
  df = pd.read_excel(file_path)
@@ -261,10 +245,18 @@ def search_classical_music_database(query: str) -> str:
261
  Simulate a lookup in a classical music competition or archive database.
262
  Use for questions about award winners, orchestras, or composers.
263
  """
264
- print(f"🛠️ search_classical_music_database called with: {query}")
265
 
266
  return f"Simulated search result for {query} in classical music competition database."
267
 
 
 
 
 
 
 
 
 
 
268
  # List of all tools
269
  all_tools = [
270
  search_duckduckgo,
 
19
  Use this when no other tool applies or you need open-ended facts from the internet.
20
  Returns the top result snippet.
21
  """
 
22
 
23
  with DDGS() as ddgs:
24
  results = ddgs.text(query, safesearch="Moderate")
 
33
  Search English Wikipedia and return a summary of the most relevant page.
34
  Use this for questions about people, dates, history, science, or named concepts.
35
  """
 
36
 
37
  try:
38
  page = wikipedia.page(query)
 
51
  Use this for tasks involving scientific food classification.
52
  Returns 'vegetable' or 'fruit'.
53
  """
 
54
 
55
  fruits = {"sweet potatoes", "plums", "bell pepper", "corn", "green beans"}
56
  if item.lower() in fruits:
 
65
  Returns the best move for the current player.
66
  Use this for decision-making or evaluation in chess scenarios.
67
  """
 
68
 
69
  try:
70
  board = chess.Board(fen)
 
80
  Solve or simplify a symbolic math expression.
81
  Use this for algebraic simplifications or symbolic math steps.
82
  """
 
83
 
84
  try:
85
  result = sympy.simplify(expression)
 
94
  Use this for information retrieval from uploaded documents.
95
  Returns the page text where the query was found.
96
  """
 
97
 
98
  try:
99
  doc = fitz.open(filepath)
 
112
  Use this when the user provides audio recordings.
113
  Returns the full transcript.
114
  """
 
115
 
116
  try:
117
  model = whisper.load_model("small")
 
127
  Use this to identify media titles, actors, or related entertainment metadata.
128
  Returns the best matching title.
129
  """
 
130
 
131
  try:
132
  ia = IMDb()
 
144
  Use this for running basic computations or logic blocks shared in string form.
145
  Returns the result of 'result' variable if defined.
146
  """
 
147
 
148
  try:
149
  exec_globals = {}
 
159
  Use this for questions asking what was said in a specific video.
160
  Returns full transcript as plain text.
161
  """
 
162
 
163
  try:
164
  transcript = YouTubeTranscriptApi.get_transcript(video_id)
 
172
  Simulate a lookup of a baseball player's stats on Baseball Reference.
173
  Use this for sports questions involving MLB players.
174
  """
 
175
 
176
  try:
177
  url = f"https://www.baseball-reference.com/search/search.fcgi?search={player}"
 
189
  Download and extract raw text from a web page.
190
  Use this when needing the full text content of an online article.
191
  """
 
192
 
193
  try:
194
  r = requests.get(url)
 
203
  Simulate a search in a zoological records database.
204
  Use for biological or species-related queries when the user references animal data.
205
  """
 
206
 
207
  return f"Simulated search result for {query} in zoological database."
208
 
 
212
  Simulate a country search in an Olympics dataset.
213
  Use this for questions about Olympic history, participation, or medal stats by country.
214
  """
 
215
 
216
  return f"Simulated search for {country} in Olympics database."
217
 
 
221
  Simulate a roster lookup for a baseball player by jersey number.
222
  Use for lineup, identity, or number-matching tasks.
223
  """
 
224
 
225
  return f"Simulated search result for player number {player_number}."
226
 
 
231
  Use this for business, finance, or menu data-related tasks.
232
  Returns total food sales as formatted currency.
233
  """
 
234
 
235
  try:
236
  df = pd.read_excel(file_path)
 
245
  Simulate a lookup in a classical music competition or archive database.
246
  Use for questions about award winners, orchestras, or composers.
247
  """
 
248
 
249
  return f"Simulated search result for {query} in classical music competition database."
250
 
251
+ @tool
252
+ def reverse_sentence(sentence: str) -> str:
253
+ """
254
+ Reverse each word in a sentence individually.
255
+ Use this for reversing letter order in each word, not the sentence order.
256
+ """
257
+
258
+ return " ".join(word[::-1] for word in sentence.split())
259
+
260
  # List of all tools
261
  all_tools = [
262
  search_duckduckgo,