Spaces:
Sleeping
Sleeping
tool issue
Browse files
app.py
CHANGED
|
@@ -25,25 +25,25 @@ OPENAI_TOKEN = os.getenv("OPENAI_API_KEY")
|
|
| 25 |
class ReliableSearchTool(Tool):
|
| 26 |
name = "reliable_search"
|
| 27 |
description = "Search the web for information with built-in retry and fallback mechanisms"
|
|
|
|
|
|
|
| 28 |
|
| 29 |
def __init__(self):
|
| 30 |
self.ddg_tool = DuckDuckGoSearchTool()
|
| 31 |
-
self.max_retries = 2
|
| 32 |
self.timeout = 8
|
| 33 |
|
| 34 |
-
def
|
| 35 |
"""Search the web with retry logic and fallbacks."""
|
| 36 |
for attempt in range(self.max_retries):
|
| 37 |
try:
|
| 38 |
-
# Try DuckDuckGo first
|
| 39 |
result = self.ddg_tool(query)
|
| 40 |
-
if result and len(result) > 50:
|
| 41 |
return result
|
| 42 |
except Exception as e:
|
| 43 |
print(f"DuckDuckGo search failed (attempt {attempt+1}/{self.max_retries}): {e}")
|
| 44 |
-
time.sleep(2)
|
| 45 |
|
| 46 |
-
# If all DuckDuckGo attempts failed, return a fallback response
|
| 47 |
return f"I couldn't search for '{query}' due to search service limitations. Using my existing knowledge instead."
|
| 48 |
|
| 49 |
# --- Basic Agent Definition ---
|
|
@@ -70,7 +70,7 @@ class SlpMultiAgent:
|
|
| 70 |
|
| 71 |
# Here you can implement your agent logic, tools, and model calls
|
| 72 |
web_agent = CodeAgent(
|
| 73 |
-
tools=[ReliableSearchTool(), VisitWebpageTool()],
|
| 74 |
model=model,
|
| 75 |
additional_authorized_imports=["pandas", "time", "json", "requests"],
|
| 76 |
max_steps=5, # Keep sufficient steps for complex tasks
|
|
|
|
| 25 |
class ReliableSearchTool(Tool):
|
| 26 |
name = "reliable_search"
|
| 27 |
description = "Search the web for information with built-in retry and fallback mechanisms"
|
| 28 |
+
inputs = {"query": {"type": "string", "description": "The search query to look up"}}
|
| 29 |
+
output_type = "string"
|
| 30 |
|
| 31 |
def __init__(self):
|
| 32 |
self.ddg_tool = DuckDuckGoSearchTool()
|
| 33 |
+
self.max_retries = 2
|
| 34 |
self.timeout = 8
|
| 35 |
|
| 36 |
+
def __call__(self, query: str) -> str:
|
| 37 |
"""Search the web with retry logic and fallbacks."""
|
| 38 |
for attempt in range(self.max_retries):
|
| 39 |
try:
|
|
|
|
| 40 |
result = self.ddg_tool(query)
|
| 41 |
+
if result and len(result) > 50:
|
| 42 |
return result
|
| 43 |
except Exception as e:
|
| 44 |
print(f"DuckDuckGo search failed (attempt {attempt+1}/{self.max_retries}): {e}")
|
| 45 |
+
time.sleep(2)
|
| 46 |
|
|
|
|
| 47 |
return f"I couldn't search for '{query}' due to search service limitations. Using my existing knowledge instead."
|
| 48 |
|
| 49 |
# --- Basic Agent Definition ---
|
|
|
|
| 70 |
|
| 71 |
# Here you can implement your agent logic, tools, and model calls
|
| 72 |
web_agent = CodeAgent(
|
| 73 |
+
tools=[ReliableSearchTool(), VisitWebpageTool()],
|
| 74 |
model=model,
|
| 75 |
additional_authorized_imports=["pandas", "time", "json", "requests"],
|
| 76 |
max_steps=5, # Keep sufficient steps for complex tasks
|