Spaces:
Sleeping
Sleeping
timeout issues
Browse files
app.py
CHANGED
|
@@ -37,11 +37,11 @@ class ReliableSearchTool(Tool):
|
|
| 37 |
|
| 38 |
def forward(self, query: str) -> str:
|
| 39 |
"""Search the web with retry logic and fallbacks."""
|
| 40 |
-
# Try Wikipedia first
|
| 41 |
try:
|
| 42 |
import requests
|
| 43 |
wiki_url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + query.replace(" ", "_")
|
| 44 |
-
response = requests.get(wiki_url, timeout=
|
| 45 |
if response.status_code == 200:
|
| 46 |
data = response.json()
|
| 47 |
if 'extract' in data and data['extract']:
|
|
@@ -49,26 +49,20 @@ class ReliableSearchTool(Tool):
|
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Wikipedia search failed: {e}")
|
| 51 |
|
| 52 |
-
# Try
|
| 53 |
try:
|
| 54 |
-
|
| 55 |
-
response = requests.get(
|
| 56 |
if response.status_code == 200:
|
| 57 |
data = response.json()
|
| 58 |
-
if '
|
| 59 |
-
return f"
|
| 60 |
except Exception as e:
|
| 61 |
-
print(f"
|
| 62 |
|
| 63 |
-
#
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
if result and len(result) > 50:
|
| 67 |
-
return result
|
| 68 |
-
except Exception as e:
|
| 69 |
-
print(f"DuckDuckGo search failed: {e}")
|
| 70 |
-
|
| 71 |
-
return f"Search unavailable for '{query}'. Please use your existing knowledge to answer."
|
| 72 |
|
| 73 |
# --- Basic Agent Definition ---
|
| 74 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
| 37 |
|
| 38 |
def forward(self, query: str) -> str:
|
| 39 |
"""Search the web with retry logic and fallbacks."""
|
| 40 |
+
# Try Wikipedia first (reduced timeout)
|
| 41 |
try:
|
| 42 |
import requests
|
| 43 |
wiki_url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + query.replace(" ", "_")
|
| 44 |
+
response = requests.get(wiki_url, timeout=3)
|
| 45 |
if response.status_code == 200:
|
| 46 |
data = response.json()
|
| 47 |
if 'extract' in data and data['extract']:
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Wikipedia search failed: {e}")
|
| 51 |
|
| 52 |
+
# Try Wikidata API as backup
|
| 53 |
try:
|
| 54 |
+
wikidata_url = f"https://www.wikidata.org/w/api.php?action=wbsearchentities&search={query.replace(' ', '%20')}&language=en&format=json"
|
| 55 |
+
response = requests.get(wikidata_url, timeout=3)
|
| 56 |
if response.status_code == 200:
|
| 57 |
data = response.json()
|
| 58 |
+
if 'search' in data and data['search']:
|
| 59 |
+
return f"Wikidata: {data['search'][0].get('description', 'No description available')}"
|
| 60 |
except Exception as e:
|
| 61 |
+
print(f"Wikidata search failed: {e}")
|
| 62 |
|
| 63 |
+
# Skip DuckDuckGo entirely due to consistent timeouts
|
| 64 |
+
# Return knowledge-based response
|
| 65 |
+
return f"External search unavailable. Based on available knowledge, I'll attempt to answer '{query}' using my training data. Note: This information may not be current."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# --- Basic Agent Definition ---
|
| 68 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|