Kackle commited on
Commit
226d733
·
verified ·
1 Parent(s): 6d99028

timeout issues

Browse files
Files changed (1) hide show
  1. app.py +11 -17
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=5)
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 Wikipedia search API
53
  try:
54
- search_url = "https://en.wikipedia.org/api/rest_v1/page/search/" + query.replace(" ", "%20")
55
- response = requests.get(search_url, timeout=5)
56
  if response.status_code == 200:
57
  data = response.json()
58
- if 'pages' in data and data['pages']:
59
- return f"Wikipedia search: {data['pages'][0].get('description', 'No description available')}"
60
  except Exception as e:
61
- print(f"Wikipedia search API failed: {e}")
62
 
63
- # Fallback to DuckDuckGo
64
- try:
65
- result = self.ddg_tool(query)
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 ------