Spaces:
Sleeping
Sleeping
Update multiple_tools.py
Browse files- multiple_tools.py +30 -30
multiple_tools.py
CHANGED
|
@@ -25,36 +25,36 @@ my_search_engine = os.getenv("Google_WebSearch_Engine")
|
|
| 25 |
g_search = GoogleSearchToolSpec(key=google_key, engine=my_search_engine, num=3)
|
| 26 |
|
| 27 |
#Wikipedia Search Tool
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
wikipedia.set_lang("en")
|
| 32 |
-
|
| 33 |
-
def wiki_search(query: str) -> str:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
wikipedia_search_tool = FunctionTool.from_defaults(wiki_search)
|
| 58 |
|
| 59 |
|
| 60 |
def google_web_search(query : str) -> str:
|
|
|
|
| 25 |
g_search = GoogleSearchToolSpec(key=google_key, engine=my_search_engine, num=3)
|
| 26 |
|
| 27 |
#Wikipedia Search Tool
|
| 28 |
+
wikipedia_tool = WikipediaToolSpec()
|
| 29 |
+
wikipedia_search_tool = FunctionTool.from_defaults(wikipedia_tool.search_data)
|
| 30 |
+
|
| 31 |
+
# wikipedia.set_lang("en")
|
| 32 |
+
|
| 33 |
+
# def wiki_search(query: str) -> str:
|
| 34 |
+
# """
|
| 35 |
+
# Safe Wikipedia summary tool with disambiguation and fallback protection.
|
| 36 |
+
# """
|
| 37 |
+
# try:
|
| 38 |
+
# return wikipedia.summary(query, sentences=3)
|
| 39 |
+
# except wikipedia.DisambiguationError as e:
|
| 40 |
+
# # Try the first disambiguation option if available
|
| 41 |
+
# if e.options:
|
| 42 |
+
# try:
|
| 43 |
+
# return wikipedia.summary(e.options[0], sentences=3)
|
| 44 |
+
# except Exception as inner:
|
| 45 |
+
# return f"Disambiguation fallback failed: {inner}"
|
| 46 |
+
# return "Disambiguation error: No options available."
|
| 47 |
+
# except wikipedia.PageError:
|
| 48 |
+
# search_results = wikipedia.search(query)
|
| 49 |
+
# if not search_results:
|
| 50 |
+
# return "No relevant Wikipedia page found."
|
| 51 |
+
# try:
|
| 52 |
+
# return wikipedia.summary(search_results[0], sentences=3)
|
| 53 |
+
# except Exception as inner:
|
| 54 |
+
# return f"Wikipedia fallback summary error: {inner}"
|
| 55 |
+
# except Exception as e:
|
| 56 |
+
# return f"Wikipedia general error: {e}"
|
| 57 |
+
# wikipedia_search_tool = FunctionTool.from_defaults(wiki_search)
|
| 58 |
|
| 59 |
|
| 60 |
def google_web_search(query : str) -> str:
|