Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supercoder 1389 Issue Resolved #1425

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion superagi/tools/searx/searx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ def _execute(self, query: str) -> tuple:
Returns:
Snippets from the Searx search.
"""
snippets = search_results(query)
try:
snippets = search_results(query)
except HTTPError as http_err:
if http_err.response.status_code == 429:
return "Error: Searx returned 429 status code. Too many requests. Please try again later."
else:
return f"HTTP error occurred: {http_err}"
except Exception as err:
return f"An error occurred: {err}"

summary = self.summarise_result(query, snippets)

return summary
Expand Down
25 changes: 25 additions & 0 deletions superagi/tools/searx/searx_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
from superagi.tools.base_tool import BaseToolkit, BaseTool, ToolConfiguration
from superagi.tools.searx.searx import SearxSearchTool
from superagi.types.key_type import ToolConfigKeyType
import time
import requests

class SearxSearchTool:
def search(self, query):
url = "http://your-searx-instance/search"
params = {
'q': query,
'format': 'json'
}
max_retries = 5
backoff_factor = 1

for attempt in range(max_retries):
response = requests.get(url, params=params)
if response.status_code == 200:
return response.json()
elif response.status_code == 429:
wait_time = backoff_factor * (2 ** attempt)
print(f"Received 429 status code. Retrying in {wait_time} seconds...")
time.sleep(wait_time)
else:
response.raise_for_status()

raise Exception("Max retries exceeded with 429 status code")

class SearxSearchToolkit(BaseToolkit, ABC):
name: str = "Searx Toolkit"
Expand Down