Spaces:
Runtime error
Runtime error
dynamic tool picking
Browse files- basic_agent.py +44 -3
basic_agent.py
CHANGED
|
@@ -1,10 +1,51 @@
|
|
| 1 |
-
from tools import
|
| 2 |
|
| 3 |
class BasicAgent:
|
| 4 |
def __call__(self, question: str) -> str:
|
| 5 |
try:
|
| 6 |
-
|
|
|
|
| 7 |
return result
|
| 8 |
except Exception as e:
|
| 9 |
-
return f"Error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
| 1 |
+
from tools import all_tools
|
| 2 |
|
| 3 |
class BasicAgent:
|
| 4 |
def __call__(self, question: str) -> str:
|
| 5 |
try:
|
| 6 |
+
tool = self.select_tool(question)
|
| 7 |
+
result = tool.invoke({"query": question})
|
| 8 |
return result
|
| 9 |
except Exception as e:
|
| 10 |
+
return f"Error: {e}"
|
| 11 |
+
|
| 12 |
+
def select_tool(self, question: str):
|
| 13 |
+
q = question.lower()
|
| 14 |
+
|
| 15 |
+
if "wikipedia" in q or "encyclopedia" in q:
|
| 16 |
+
return all_tools[1] # search_wikipedia
|
| 17 |
+
elif "youtube" in q or "video" in q:
|
| 18 |
+
return all_tools[2] # search_youtube_transcript
|
| 19 |
+
elif "opposite" in q or "reverse" in q:
|
| 20 |
+
return all_tools[3] # reverse_sentence
|
| 21 |
+
elif "chess" in q or "position" in q:
|
| 22 |
+
return all_tools[4] # solve_chess_position
|
| 23 |
+
elif "table" in q or "commutative" in q:
|
| 24 |
+
return all_tools[5] # math_solver
|
| 25 |
+
elif "libretext" in q or "document" in q:
|
| 26 |
+
return all_tools[6] # document_search
|
| 27 |
+
elif "vegetable" in q or "botany" in q:
|
| 28 |
+
return all_tools[7] # classify_vegetable
|
| 29 |
+
elif "audio" in q or "transcribe" in q or "mp3" in q:
|
| 30 |
+
return all_tools[8] # transcribe_audio
|
| 31 |
+
elif "imdb" in q or "movie" in q or "tv show" in q:
|
| 32 |
+
return all_tools[9] # search_imdb
|
| 33 |
+
elif "python" in q or "code" in q:
|
| 34 |
+
return all_tools[10] # run_python_code
|
| 35 |
+
elif "yankee" in q or "baseball" in q and "walks" in q:
|
| 36 |
+
return all_tools[11] # search_baseball_stats
|
| 37 |
+
elif "nasa" in q or "universe today" in q:
|
| 38 |
+
return all_tools[12] # scrape_document
|
| 39 |
+
elif "specimen" in q or "zoological" in q:
|
| 40 |
+
return all_tools[13] # search_zoological_database
|
| 41 |
+
elif "olympic" in q or "athletes" in q:
|
| 42 |
+
return all_tools[14] # search_olympic_database
|
| 43 |
+
elif "roster" in q or "pitcher" in q:
|
| 44 |
+
return all_tools[15] # search_baseball_roster
|
| 45 |
+
elif "excel" in q or "sales" in q or "menu" in q:
|
| 46 |
+
return all_tools[16] # process_excel
|
| 47 |
+
elif "malko" in q or "music competition" in q:
|
| 48 |
+
return all_tools[17] # search_classical_music_database
|
| 49 |
+
else:
|
| 50 |
+
return all_tools[0] # fallback to search_duckduckgo
|
| 51 |
|