JeanQuezada commited on
Commit
46a7509
·
verified ·
1 Parent(s): ae7a494

update_simples_tools_mst

Browse files
Files changed (1) hide show
  1. app.py +51 -16
app.py CHANGED
@@ -3,35 +3,70 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
- def get_current_time_in_timezone(timezone: str) -> str:
23
- """A tool that fetches the current local time in a specified timezone.
 
24
  Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
26
  """
27
  try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
  final_answer = FinalAnswerTool()
@@ -55,7 +90,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import wikipedia
7
+ import math
8
  from tools.final_answer import FinalAnswerTool
9
 
10
  from Gradio_UI import GradioUI
11
 
 
12
  @tool
13
+ def calculate_mcm_mcd(num1: int, num2: int) -> dict:
14
+ """Calcula los primeros 10 múltiplos comunes mínimos (MCM) y divisores comunes máximos (MCD) de dos números.
15
+
16
  Args:
17
+ num1: Primer número entero.
18
+ num2: Segundo número entero.
19
+
20
+ Returns:
21
+ Un diccionario con:
22
+ - Lista de los primeros 10 MCM.
23
+ - Lista de los primeros 10 MCD.
24
  """
25
+ try:
26
+ gcd_value = math.gcd(num1, num2)
27
+ mcm_list = [math.lcm(num1, num2) * i for i in range(1, 11)]
28
+ mcd_list = [i for i in range(1, gcd_value + 1) if gcd_value % i == 0][:10]
29
+
30
+ return {
31
+ "MCM": mcm_list,
32
+ "MCD": mcd_list
33
+ }
34
+
35
+ except Exception as e:
36
+ return {"Error": f"Ocurrió un error: {str(e)}"}
37
 
38
  @tool
39
+ def get_time_by_city(city: str) -> str:
40
+ """Obtiene la hora local en una ciudad específica.
41
+
42
  Args:
43
+ city: Nombre de la ciudad (Ejemplo: 'America/Lima')
44
+
45
+ Returns:
46
+ Hora actual en la ciudad dada.
47
  """
48
  try:
49
+ tz = pytz.timezone(city)
 
 
50
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
51
+ return f"La hora en {city} es {local_time}."
52
+ except Exception as e:
53
+ return f"Error al obtener la hora para '{city}': {str(e)}"
54
+
55
+ @tool
56
+ def search_wikipedia(query: str) -> str:
57
+ """Busca información en Wikipedia.
58
+
59
+ Args:
60
+ query: Término de búsqueda (Ejemplo: 'Machine Learning').
61
+
62
+ Returns:
63
+ Resumen del artículo en Wikipedia.
64
+ """
65
+ try:
66
+ summary = wikipedia.summary(query, sentences=2, lang="es")
67
+ return summary
68
  except Exception as e:
69
+ return f"Error al buscar en Wikipedia: {str(e)}"
70
 
71
 
72
  final_answer = FinalAnswerTool()
 
90
 
91
  agent = CodeAgent(
92
  model=model,
93
+ tools=[calculate_mcm_mcd, get_time_by_city, search_wikipedia, final_answer], ## add your tools here (don't remove final answer)
94
  max_steps=6,
95
  verbosity_level=1,
96
  grammar=None,