Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
from smolagents import CodeAgent, ToolCallingAgent, LiteLLMModel, tool, Tool, load_tool,
|
|
|
|
| 2 |
import asyncio
|
| 3 |
import os
|
| 4 |
import re
|
|
@@ -59,8 +60,9 @@ class VisitWebpageTool(Tool):
|
|
| 59 |
response.raise_for_status()
|
| 60 |
markdown_content = markdownify(response.text).strip()
|
| 61 |
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
|
| 62 |
-
from smolagents.utils import truncate_content
|
| 63 |
-
return truncate_content(markdown_content, 10000)
|
|
|
|
| 64 |
except requests.exceptions.HTTPError as e:
|
| 65 |
if e.response.status_code == 429:
|
| 66 |
raise # Retry on 429
|
|
@@ -163,15 +165,15 @@ class PythonCodeReaderTool(Tool):
|
|
| 163 |
|
| 164 |
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
|
| 165 |
|
| 166 |
-
class RetryDuckDuckGoSearchTool(DuckDuckGoSearchTool):
|
| 167 |
-
@retry(
|
| 168 |
-
stop=stop_after_attempt(3),
|
| 169 |
-
wait=wait_exponential(multiplier=1, min=4, max=10),
|
| 170 |
-
retry=retry_if_exception_type(Exception)
|
| 171 |
-
)
|
| 172 |
|
| 173 |
-
def forward(self, query: str) -> str:
|
| 174 |
-
return super().forward(query)
|
| 175 |
|
| 176 |
class MagAgent:
|
| 177 |
def __init__(self, rate_limiter: Optional[Limiter] = None):
|
|
@@ -241,8 +243,9 @@ class MagAgent:
|
|
| 241 |
web_agent = ToolCallingAgent(
|
| 242 |
tools=[
|
| 243 |
# RetryDuckDuckGoSearchTool(),
|
| 244 |
-
WikipediaSearchTool(),
|
| 245 |
# SpeechToTextTool(),
|
|
|
|
| 246 |
VisitWebpageTool(),
|
| 247 |
# ExcelReaderTool(),
|
| 248 |
# PythonCodeReaderTool(),
|
|
@@ -261,7 +264,7 @@ class MagAgent:
|
|
| 261 |
add_base_tools=True,
|
| 262 |
additional_authorized_imports=self.imports,
|
| 263 |
verbosity_level=2,
|
| 264 |
-
max_steps=
|
| 265 |
)
|
| 266 |
print("MagAgent initialized.")
|
| 267 |
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, ToolCallingAgent, LiteLLMModel, tool, Tool, load_tool, WebSearchTool
|
| 2 |
+
#DuckDuckGoSearchTool, WikipediaSearchTool
|
| 3 |
import asyncio
|
| 4 |
import os
|
| 5 |
import re
|
|
|
|
| 60 |
response.raise_for_status()
|
| 61 |
markdown_content = markdownify(response.text).strip()
|
| 62 |
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
|
| 63 |
+
#from smolagents.utils import truncate_content
|
| 64 |
+
#return truncate_content(markdown_content, 10000)
|
| 65 |
+
return markdown_content
|
| 66 |
except requests.exceptions.HTTPError as e:
|
| 67 |
if e.response.status_code == 429:
|
| 68 |
raise # Retry on 429
|
|
|
|
| 165 |
|
| 166 |
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
|
| 167 |
|
| 168 |
+
#class RetryDuckDuckGoSearchTool(DuckDuckGoSearchTool):
|
| 169 |
+
# @retry(
|
| 170 |
+
# stop=stop_after_attempt(3),
|
| 171 |
+
# wait=wait_exponential(multiplier=1, min=4, max=10),
|
| 172 |
+
# retry=retry_if_exception_type(Exception)
|
| 173 |
+
# )
|
| 174 |
|
| 175 |
+
# def forward(self, query: str) -> str:
|
| 176 |
+
# return super().forward(query)
|
| 177 |
|
| 178 |
class MagAgent:
|
| 179 |
def __init__(self, rate_limiter: Optional[Limiter] = None):
|
|
|
|
| 243 |
web_agent = ToolCallingAgent(
|
| 244 |
tools=[
|
| 245 |
# RetryDuckDuckGoSearchTool(),
|
| 246 |
+
# WikipediaSearchTool(),
|
| 247 |
# SpeechToTextTool(),
|
| 248 |
+
WebSearchTool(),
|
| 249 |
VisitWebpageTool(),
|
| 250 |
# ExcelReaderTool(),
|
| 251 |
# PythonCodeReaderTool(),
|
|
|
|
| 264 |
add_base_tools=True,
|
| 265 |
additional_authorized_imports=self.imports,
|
| 266 |
verbosity_level=2,
|
| 267 |
+
max_steps=10
|
| 268 |
)
|
| 269 |
print("MagAgent initialized.")
|
| 270 |
|