File size: 646 Bytes
ef96de0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel

class DuckDuckGoAgent:
    def __init__(self):
        self.agent = CodeAgent(
            tools=[DuckDuckGoSearchTool()],
            model=HfApiModel()
        )

    def __call__(self, question: str) -> str:
        """Recibe una pregunta, busca en DuckDuckGo y devuelve una respuesta."""
        print(f"Running search for question: {question}")
        try:
            response = self.agent.run(question)
            return response
        except Exception as e:
            print(f"Error during agent search: {e}")
            return "Sorry, I couldn't find an answer."