Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,10 +59,10 @@ class GoogleSearchTool(Tool):
|
|
| 59 |
'key': self.google_search_api_key,
|
| 60 |
'cx': self.google_search_cx,
|
| 61 |
'q': query,
|
| 62 |
-
'num':
|
| 63 |
}
|
| 64 |
|
| 65 |
-
response = requests.get(url, params=params, timeout=
|
| 66 |
if response.status_code != 200:
|
| 67 |
return f"Google Search failed with status {response.status_code}"
|
| 68 |
|
|
@@ -70,15 +70,14 @@ class GoogleSearchTool(Tool):
|
|
| 70 |
if 'items' not in results:
|
| 71 |
return f"No search results found for: {query}"
|
| 72 |
|
| 73 |
-
# Format search results
|
| 74 |
-
formatted_results = f"
|
| 75 |
-
for
|
| 76 |
title = item.get('title', 'No title')
|
| 77 |
snippet = item.get('snippet', 'No description')
|
| 78 |
-
|
| 79 |
-
formatted_results += f"{i}. {title}\n {snippet}\n Source: {link}\n\n"
|
| 80 |
|
| 81 |
-
return formatted_results[:
|
| 82 |
|
| 83 |
except Exception as e:
|
| 84 |
return f"Google Search error for '{query}': {str(e)}"
|
|
|
|
| 59 |
'key': self.google_search_api_key,
|
| 60 |
'cx': self.google_search_cx,
|
| 61 |
'q': query,
|
| 62 |
+
'num': 5
|
| 63 |
}
|
| 64 |
|
| 65 |
+
response = requests.get(url, params=params, timeout=10)
|
| 66 |
if response.status_code != 200:
|
| 67 |
return f"Google Search failed with status {response.status_code}"
|
| 68 |
|
|
|
|
| 70 |
if 'items' not in results:
|
| 71 |
return f"No search results found for: {query}"
|
| 72 |
|
| 73 |
+
# Format search results
|
| 74 |
+
formatted_results = f"Google search results for '{query}':\n\n"
|
| 75 |
+
for item in results['items']:
|
| 76 |
title = item.get('title', 'No title')
|
| 77 |
snippet = item.get('snippet', 'No description')
|
| 78 |
+
formatted_results += f"• {title}: {snippet}\n"
|
|
|
|
| 79 |
|
| 80 |
+
return formatted_results[:1000] # Limit length
|
| 81 |
|
| 82 |
except Exception as e:
|
| 83 |
return f"Google Search error for '{query}': {str(e)}"
|