Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -25,30 +25,6 @@ import wikipedia
|
|
| 25 |
from bs4 import BeautifulSoup
|
| 26 |
from langchain_core.tools import tool
|
| 27 |
|
| 28 |
-
@tool
|
| 29 |
-
def count_years_in_range(text: str, start_year: int, end_year: int) -> str:
|
| 30 |
-
"""
|
| 31 |
-
Counts how many 4-digit years appear in the text and fall between start_year and end_year (inclusive).
|
| 32 |
-
|
| 33 |
-
Args:
|
| 34 |
-
text (str): The input text, e.g. extracted from a Wikipedia section.
|
| 35 |
-
start_year (int): Start of the target year range (inclusive).
|
| 36 |
-
end_year (int): End of the target year range (inclusive).
|
| 37 |
-
|
| 38 |
-
Returns:
|
| 39 |
-
str: A message stating how many years were found in the range and which years matched.
|
| 40 |
-
"""
|
| 41 |
-
try:
|
| 42 |
-
# Find all proper 4-digit years between 1900 and 2099
|
| 43 |
-
years = re.findall(r"\b(19|20)\d{2}\b", text)
|
| 44 |
-
# Convert to full year integers
|
| 45 |
-
full_years = re.findall(r"\b(19\d{2}|20\d{2})\b", text)
|
| 46 |
-
numeric_years = [int(y) for y in full_years if start_year <= int(y) <= end_year]
|
| 47 |
-
return f"{len(numeric_years)} year(s) found in range {start_year}–{end_year}: {sorted(set(numeric_years))}"
|
| 48 |
-
except Exception as e:
|
| 49 |
-
return f"Error parsing years: {str(e)}"
|
| 50 |
-
|
| 51 |
-
|
| 52 |
@tool
|
| 53 |
def extract_wikipedia_section_html(page_title: str, section_title: str, mode: str = "html") -> str:
|
| 54 |
"""
|
|
@@ -144,7 +120,6 @@ def filter_vegetables(items: list[str]) -> list[str]:
|
|
| 144 |
|
| 145 |
# List of all tools
|
| 146 |
all_tools = [
|
| 147 |
-
count_years_in_range,
|
| 148 |
reverse_sentence,
|
| 149 |
filter_vegetables,
|
| 150 |
extract_wikipedia_section_html
|
|
|
|
| 25 |
from bs4 import BeautifulSoup
|
| 26 |
from langchain_core.tools import tool
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
@tool
|
| 29 |
def extract_wikipedia_section_html(page_title: str, section_title: str, mode: str = "html") -> str:
|
| 30 |
"""
|
|
|
|
| 120 |
|
| 121 |
# List of all tools
|
| 122 |
all_tools = [
|
|
|
|
| 123 |
reverse_sentence,
|
| 124 |
filter_vegetables,
|
| 125 |
extract_wikipedia_section_html
|