zvl commited on
Commit
b70e0c1
·
verified ·
1 Parent(s): 469d60b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -9,25 +9,26 @@ 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 buscar_datos_gob(term: str, page_size: int = 10, page: int = 0, sort: str = "title") -> dict:
13
- """
14
- Busca conjuntos de datos en la API de datos.gob.es.
 
15
 
16
  Args:
17
- term (str): Palabra clave para buscar conjuntos de datos.
18
- page_size (int): Número de resultados por página. Máximo 50. (Por defecto: 10)
19
- page (int): Página de resultados a consultar. (Por defecto: 0)
20
- sort (str): Campo por el cual ordenar los resultados (Por defecto: "title").
21
 
22
  Returns:
23
- dict: Diccionario con los conjuntos de datos encontrados o un mensaje de error.
24
  """
25
  base_url = "https://datos.gob.es/apidata/catalog/dataset"
26
  params = {
27
  "q": term,
28
  "_pageSize": page_size,
29
  "_page": page,
30
- "_sort": sort # ✅ Ahora `sort` está definido
31
  }
32
  headers = {
33
  "Accept": "application/json"
@@ -38,7 +39,8 @@ def buscar_datos_gob(term: str, page_size: int = 10, page: int = 0, sort: str =
38
  response.raise_for_status()
39
  return response.json()
40
  except requests.exceptions.RequestException as e:
41
- return {"error": f"Error en la solicitud: {str(e)}"}
 
42
 
43
  @tool
44
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def buscar_datos_gob(term: str, page_size: int, page: int, sort: str) -> dict:
13
+ # It's important to specify the return type
14
+ # Keep this format for the description / args description but feel free to modify the tool
15
+ """A tool that searches for datasets in the API of datos.gob.es.
16
 
17
  Args:
18
+ term: The search term to filter the datasets.
19
+ page_size: The number of results per page (maximum: 50).
20
+ page: The page number for pagination of results.
21
+ sort: The field by which to sort the results (default: "title").
22
 
23
  Returns:
24
+ A dictionary containing the search results from datos.gob.es API.
25
  """
26
  base_url = "https://datos.gob.es/apidata/catalog/dataset"
27
  params = {
28
  "q": term,
29
  "_pageSize": page_size,
30
  "_page": page,
31
+ "_sort": sort
32
  }
33
  headers = {
34
  "Accept": "application/json"
 
39
  response.raise_for_status()
40
  return response.json()
41
  except requests.exceptions.RequestException as e:
42
+ return {"error": f"Error in the request: {str(e)}"}
43
+
44
 
45
  @tool
46
  def get_current_time_in_timezone(timezone: str) -> str: