tomaslucas commited on
Commit
dc75338
·
verified ·
1 Parent(s): 0d035b4

add test with api

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -18,6 +18,32 @@ 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.
@@ -55,7 +81,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+
22
+ import requests
23
+
24
+ @tool
25
+ def get_book():
26
+ """A tool that fetches the Harry Potter books with information about them.
27
+ Args:
28
+ """
29
+ response = requests.get('https://potterapi-fedeperin.vercel.app/en/books')
30
+ books = response.json()
31
+ return books
32
+
33
+ @tool
34
+ def filter_book(libro, campo, valor, operador='=='):
35
+ """
36
+ Filtra libros según un campo, valor y operador especificados
37
+ operadores permitidos: ==, >, <, >=, <=, contains
38
+ """
39
+ if operador == 'contains':
40
+ return [libro for libro in libros if valor.lower() in str(getattr(libro, campo)).lower()]
41
+ elif operador in ['==', '>', '<', '>=', '<=']:
42
+ return [libro for libro in libros if eval(f"{getattr(libro, campo)} {operador} {valor}")]
43
+ else:
44
+ raise ValueError("Operador no válido")
45
+
46
+
47
  @tool
48
  def get_current_time_in_timezone(timezone: str) -> str:
49
  """A tool that fetches the current local time in a specified timezone.
 
81
 
82
  agent = CodeAgent(
83
  model=model,
84
+ tools=[final_answer, get_current_time_in_timezone, get_book, filter_book], ## add your tools here (don't remove final answer)
85
  max_steps=6,
86
  verbosity_level=1,
87
  grammar=None,