jjvelezo commited on
Commit
667e88a
·
verified ·
1 Parent(s): ba8bc4e

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +17 -4
agent.py CHANGED
@@ -1,17 +1,30 @@
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}")
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, WikipediaSearchTool
2
+ import datetime
3
+
4
+
5
 
6
  class DuckDuckGoAgent:
7
  def __init__(self):
8
+
9
  self.agent = CodeAgent(
10
+ tools=[DuckDuckGoSearchTool(), WikipediaSearchTool()],
11
+ model=HfApiModel(),
12
+ additional_authorized_imports=['datetime']
13
  )
14
 
15
  def __call__(self, question: str) -> str:
16
+ """Busca la respuesta usando Internet o Wikipedia, luego limita la longitud."""
17
  print(f"Running search for question: {question}")
18
  try:
19
  response = self.agent.run(question)
20
+ if not response:
21
+ return "No information found."
22
+
23
+
24
+ max_length = 200
25
+ response = response.strip()
26
+ if len(response) > max_length:
27
+ response = response[:max_length].rsplit('.', 1)[0] + '.'
28
  return response
29
  except Exception as e:
30
  print(f"Error during agent search: {e}")