Albertoleon86 commited on
Commit
d37806e
·
verified ·
1 Parent(s): c0d8b8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -43,39 +43,44 @@ def get_random_joke() -> str:
43
  @tool
44
  def question_about_car_km77(query: str) -> str:
45
  """
46
- A tool that queries https://www.km77.com/ for information about a specific car or topic.
47
 
48
  Args:
49
  query (str): The keywords or phrase to search for on km77.
 
 
 
50
  """
51
  try:
52
  search_url = f"https://www.km77.com/buscador/?q={query}"
53
  response = requests.get(search_url, timeout=10)
54
-
55
  if response.status_code != 200:
56
  return f"Error accediendo a km77. Código de estado HTTP: {response.status_code}"
57
-
58
  soup = BeautifulSoup(response.text, 'html.parser')
59
-
 
60
  results = soup.select("div.col-xs-12.col-md-8 a")
61
  if not results:
62
  return "No se encontraron resultados para tu búsqueda en km77."
63
-
64
  answer_lines = []
65
  for r in results[:5]:
66
  title = r.get_text(strip=True)
67
  link = r.get("href")
 
68
  if link.startswith('/'):
69
  link = f"https://www.km77.com{link}"
70
  answer_lines.append(f"- {title}: {link}")
71
-
72
  answer = (
73
- f"**Resultados de km77 para** '{query}':\n\n"
74
  + "\n".join(answer_lines)
75
  )
76
-
77
  return answer
78
-
79
  except Exception as e:
80
  return f"Ocurrió un error al realizar la búsqueda: {str(e)}"
81
 
 
43
  @tool
44
  def question_about_car_km77(query: str) -> str:
45
  """
46
+ Queries https://www.km77.com/ for information about a specific car or topic.
47
 
48
  Args:
49
  query (str): The keywords or phrase to search for on km77.
50
+
51
+ Returns:
52
+ str: A short text containing the top search results or an error message if none are found.
53
  """
54
  try:
55
  search_url = f"https://www.km77.com/buscador/?q={query}"
56
  response = requests.get(search_url, timeout=10)
57
+
58
  if response.status_code != 200:
59
  return f"Error accediendo a km77. Código de estado HTTP: {response.status_code}"
60
+
61
  soup = BeautifulSoup(response.text, 'html.parser')
62
+
63
+ # Ajusta el selector a la estructura actual de km77
64
  results = soup.select("div.col-xs-12.col-md-8 a")
65
  if not results:
66
  return "No se encontraron resultados para tu búsqueda en km77."
67
+
68
  answer_lines = []
69
  for r in results[:5]:
70
  title = r.get_text(strip=True)
71
  link = r.get("href")
72
+ # Ajustamos a URL absoluta si empieza con '/'
73
  if link.startswith('/'):
74
  link = f"https://www.km77.com{link}"
75
  answer_lines.append(f"- {title}: {link}")
76
+
77
  answer = (
78
+ f"**Resultados de km77 para** '{query}':\n\n"
79
  + "\n".join(answer_lines)
80
  )
81
+
82
  return answer
83
+
84
  except Exception as e:
85
  return f"Ocurrió un error al realizar la búsqueda: {str(e)}"
86