Spaces:
Sleeping
Sleeping
Create agent.py
Browse files
agent.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
| 2 |
+
|
| 3 |
+
class DuckDuckGoAgent:
|
| 4 |
+
def __init__(self):
|
| 5 |
+
self.agent = CodeAgent(
|
| 6 |
+
tools=[DuckDuckGoSearchTool()],
|
| 7 |
+
model=HfApiModel()
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def __call__(self, question: str) -> str:
|
| 11 |
+
"""Recibe una pregunta, busca en DuckDuckGo y devuelve una respuesta."""
|
| 12 |
+
print(f"Running search for question: {question}")
|
| 13 |
+
try:
|
| 14 |
+
response = self.agent.run(question)
|
| 15 |
+
return response
|
| 16 |
+
except Exception as e:
|
| 17 |
+
print(f"Error during agent search: {e}")
|
| 18 |
+
return "Sorry, I couldn't find an answer."
|