Spaces:
Sleeping
Sleeping
File size: 1,349 Bytes
b928387 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
from langchain.agents import tool
import wikipedia
import re
def remove_citation_tags(input_string):
# Use regular expressions to find patterns [cita requerida]
pattern = re.compile(r"\[cita requerida\]", re.IGNORECASE)
# Replace the found patterns with an empty string
result = re.sub(pattern, "", input_string)
return result
def remove_natural_numbers(input_string):
# [n]
pattern = re.compile(r"\[\d+\]")
result = re.sub(pattern, "", input_string)
return result
@tool
def obtener_wikipedia_inform(topic: str) -> str:
"""Busca informaci贸n en Wikipedia."""
try:
inf = topic.split(':')
topic = inf[1]
wiki = wikipedia.set_lang('es')
wiki = wikipedia.summary(topic, sentences=1)
wikiResult = remove_natural_numbers(wiki)
wikiResult = remove_citation_tags(wiki)
# Verificar si la p谩gina existe
if wiki is not None:
# Obtener y devolver el resumen de la p谩gina
return wikiResult
else:
return "Lo siento, no pude encontrar informaci贸n sobre ese tema en Wikipedia."
except:
return "Lo siento, no pude encontrar informaci贸n sobre ese tema en Wikipedia."
# # Ejemplo de uso
# topic = "Busca en Wikipedia: Pau Gasol"
# result = get_wikipedia_summary(topic)
# print(result)
|