Update tools.py
Browse files
tools.py
CHANGED
@@ -84,6 +84,17 @@ def simple_search(query: str, max_results: int = 5) -> List[str]:
|
|
84 |
"""
|
85 |
def _raw_search(q: str, max_results: int) -> List[str]:
|
86 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
with DDGS() as ddgs:
|
88 |
results = []
|
89 |
for r in ddgs.text(q, max_results=max_results):
|
@@ -104,6 +115,12 @@ def simple_search(query: str, max_results: int = 5) -> List[str]:
|
|
104 |
max_attempts = 4
|
105 |
base_delay = 30 # increased base delay to 30 seconds
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
for attempt in range(max_attempts):
|
108 |
try:
|
109 |
results = _raw_search(query, max_results)
|
|
|
84 |
"""
|
85 |
def _raw_search(q: str, max_results: int) -> List[str]:
|
86 |
try:
|
87 |
+
# Ensure we have a valid search query
|
88 |
+
if not q or not q.strip():
|
89 |
+
print("Warning: Empty search query")
|
90 |
+
return []
|
91 |
+
|
92 |
+
# Clean and validate the query
|
93 |
+
q = q.strip()
|
94 |
+
if len(q) < 2: # DuckDuckGo requires at least 2 characters
|
95 |
+
print("Warning: Query too short")
|
96 |
+
return []
|
97 |
+
|
98 |
with DDGS() as ddgs:
|
99 |
results = []
|
100 |
for r in ddgs.text(q, max_results=max_results):
|
|
|
115 |
max_attempts = 4
|
116 |
base_delay = 30 # increased base delay to 30 seconds
|
117 |
|
118 |
+
# Clean the input query
|
119 |
+
query = query.strip()
|
120 |
+
if not query:
|
121 |
+
print("Error: Empty search query provided")
|
122 |
+
return []
|
123 |
+
|
124 |
for attempt in range(max_attempts):
|
125 |
try:
|
126 |
results = _raw_search(query, max_results)
|