BrisaMLuna commited on
Commit
fd16c8a
·
verified ·
1 Parent(s): 8c5c24b

app.py con tool unidades de conversión

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -18,6 +18,40 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
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.
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def conversor_unidades(arg1:str, arg2: int, arg3:str)-> str:
23
+ """Une herramienta que convierte diferentes unidades de medida
24
+ Args:
25
+ arg1: Unidad de medida origen
26
+ arg2: Cantidad
27
+ arg3: Unidad de medida de salida
28
+ """
29
+ try:
30
+ #normalizar
31
+ origen = arg1.lower().strip()
32
+ destino = arg3.lower().strip()
33
+ cantidad = arg2
34
+ if origen == 'km' and destino == 'millas':
35
+ return str(cantidad * 0.621371)
36
+
37
+ if origen == 'millas' and destino == 'km':
38
+ return str(cantidad * 1.60934)
39
+
40
+ if origen == "c" and destino == "f":
41
+ return str((cantidad * 9/5) + 32)
42
+
43
+ if origen == "f" and destino == "c":
44
+ return str((cantidad - 32) * 5/9)
45
+
46
+ return "Conversión no soportada entre esas unidades."
47
+ except Exception as e:
48
+ return f"Error en la conversión: {e}"
49
+
50
+
51
+
52
+
53
+
54
+
55
  @tool
56
  def get_current_time_in_timezone(timezone: str) -> str:
57
  """A tool that fetches the current local time in a specified timezone.