Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -69,7 +69,13 @@ AUTHORIZED_IMPORTS = [
|
|
69 |
"fractions",
|
70 |
"csv",
|
71 |
]
|
|
|
|
|
|
|
72 |
|
|
|
|
|
|
|
73 |
load_dotenv(override=True)
|
74 |
login(os.getenv("HF_TOKEN"))
|
75 |
|
@@ -125,53 +131,37 @@ browser = SimpleTextBrowser(**BROWSER_CONFIG)
|
|
125 |
class DuckDuckGoSearchTool(Tool):
|
126 |
"""Search tool using DuckDuckGo"""
|
127 |
name = "web_search"
|
128 |
-
description = "Search the web using DuckDuckGo
|
129 |
-
|
130 |
-
# Smolagents requires these formatted as dicts (not lists) [github.com]
|
131 |
inputs = {
|
132 |
"query": {
|
133 |
-
"type": "string",
|
134 |
-
"description": "Search query
|
135 |
"required": True
|
136 |
}
|
137 |
}
|
138 |
-
|
139 |
-
|
140 |
-
"results": {
|
141 |
-
"type": "string",
|
142 |
-
"description": "Formatted search results with URLs and snippets"
|
143 |
-
}
|
144 |
-
}
|
145 |
-
|
146 |
-
def __init__(self, max_results: int = 5):
|
147 |
super().__init__()
|
148 |
self.max_results = max_results
|
149 |
-
self.args_schema = {
|
150 |
-
"max_results": {
|
151 |
-
"type": "integer",
|
152 |
-
"description": "Max results to return",
|
153 |
-
"default": 5
|
154 |
-
}
|
155 |
-
}
|
156 |
|
157 |
def run(self, query: str) -> str:
|
158 |
-
"""Perform a search and return formatted results"""
|
159 |
try:
|
160 |
-
with DDGS() as ddgs:
|
161 |
results = list(ddgs.text(
|
162 |
-
|
|
|
163 |
region='wt-wt',
|
164 |
-
safesearch='moderate'
|
165 |
-
max_results=self.max_results
|
166 |
))
|
167 |
-
|
168 |
-
|
169 |
-
f"β’ {res['title']}\n {res['href']}\n {res['body'][:300]}..."
|
170 |
for res in results
|
171 |
])
|
172 |
except Exception as e:
|
173 |
return f"Search failed: {str(e)}"
|
174 |
|
|
|
175 |
|
176 |
WEB_TOOLS = [
|
177 |
DuckDuckGoSearchTool(max_results=5),
|
|
|
69 |
"fractions",
|
70 |
"csv",
|
71 |
]
|
72 |
+
import os
|
73 |
+
from huggingface_hub import configure_http_backend
|
74 |
+
configure_http_backend(backends=["httpx"]) # More stable backend
|
75 |
|
76 |
+
# Set environment variables before other imports
|
77 |
+
os.environ["HF_HUB_DOWNLOAD_TIMEOUT"] = "300" # 5 minute timeout
|
78 |
+
os.environ["HF_HUB_OFFLINE"] = "0" # Disable offline mode
|
79 |
load_dotenv(override=True)
|
80 |
login(os.getenv("HF_TOKEN"))
|
81 |
|
|
|
131 |
class DuckDuckGoSearchTool(Tool):
|
132 |
"""Search tool using DuckDuckGo"""
|
133 |
name = "web_search"
|
134 |
+
description = "Search the web using DuckDuckGo"
|
135 |
+
output_type = "string" # Explicit output type [github.com]
|
|
|
136 |
inputs = {
|
137 |
"query": {
|
138 |
+
"type": "string",
|
139 |
+
"description": "Search query",
|
140 |
"required": True
|
141 |
}
|
142 |
}
|
143 |
+
|
144 |
+
def __init__(self, max_results=5):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
super().__init__()
|
146 |
self.max_results = max_results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
def run(self, query: str) -> str:
|
|
|
149 |
try:
|
150 |
+
with DDGS(timeout=30) as ddgs: # Increased timeout
|
151 |
results = list(ddgs.text(
|
152 |
+
query,
|
153 |
+
max_results=self.max_results,
|
154 |
region='wt-wt',
|
155 |
+
safesearch='moderate'
|
|
|
156 |
))
|
157 |
+
return "\n".join([
|
158 |
+
f"β’ {res['title']}\n {res['href']}\n {res['body'][:200]}..."
|
|
|
159 |
for res in results
|
160 |
])
|
161 |
except Exception as e:
|
162 |
return f"Search failed: {str(e)}"
|
163 |
|
164 |
+
|
165 |
|
166 |
WEB_TOOLS = [
|
167 |
DuckDuckGoSearchTool(max_results=5),
|