naman1102 commited on
Commit
fc853f2
·
1 Parent(s): 5a9202f

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +13 -7
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 exponential backoff and longer delays
115
  max_attempts = 4
116
- base_delay = 30 # increased base delay to 30 seconds
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
- print(f"Attempt {attempt + 1}/{max_attempts} failed: {str(e)}")
132
- if attempt < max_attempts - 1:
133
- # Longer delays between attempts
134
- delay = base_delay * (2 ** attempt) # exponential backoff
 
 
 
 
 
 
135
  print(f"Retrying in {delay}s...")
136
  time.sleep(delay)
137
  else:
138
- print(f"All {max_attempts} attempts failed. Last exception: {str(e)}")
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 []