Update tools.py
Browse files
tools.py
CHANGED
@@ -111,9 +111,9 @@ def simple_search(query: str, max_results: int = 5) -> List[str]:
|
|
111 |
print(f"Search error: {str(e)}")
|
112 |
return []
|
113 |
|
114 |
-
# Retry logic with
|
115 |
max_attempts = 4
|
116 |
-
|
117 |
|
118 |
# Clean the input query
|
119 |
query = query.strip()
|
@@ -128,14 +128,20 @@ def simple_search(query: str, max_results: int = 5) -> List[str]:
|
|
128 |
return results
|
129 |
print(f"Attempt {attempt + 1}/{max_attempts}: No results found")
|
130 |
except Exception as e:
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
print(f"Retrying in {delay}s...")
|
136 |
time.sleep(delay)
|
137 |
else:
|
138 |
-
print(f"All {max_attempts} attempts failed. Last exception: {
|
139 |
return []
|
140 |
|
141 |
return []
|
|
|
111 |
print(f"Search error: {str(e)}")
|
112 |
return []
|
113 |
|
114 |
+
# Retry logic with rate limit handling
|
115 |
max_attempts = 4
|
116 |
+
rate_limit_delay = 20 # seconds to wait on rate limit
|
117 |
|
118 |
# Clean the input query
|
119 |
query = query.strip()
|
|
|
128 |
return results
|
129 |
print(f"Attempt {attempt + 1}/{max_attempts}: No results found")
|
130 |
except Exception as e:
|
131 |
+
error_msg = str(e)
|
132 |
+
print(f"Attempt {attempt + 1}/{max_attempts} failed: {error_msg}")
|
133 |
+
|
134 |
+
# Check if it's a rate limit error
|
135 |
+
if "Ratelimit" in error_msg or "202" in error_msg:
|
136 |
+
print(f"Rate limit detected. Waiting {rate_limit_delay} seconds...")
|
137 |
+
time.sleep(rate_limit_delay)
|
138 |
+
elif attempt < max_attempts - 1:
|
139 |
+
# For other errors, use exponential backoff
|
140 |
+
delay = 30 * (2 ** attempt)
|
141 |
print(f"Retrying in {delay}s...")
|
142 |
time.sleep(delay)
|
143 |
else:
|
144 |
+
print(f"All {max_attempts} attempts failed. Last exception: {error_msg}")
|
145 |
return []
|
146 |
|
147 |
return []
|