Skip to content

Commit 3c9bd57

Browse files
committed
Update readurls to read tables
1 parent 7ac44fc commit 3c9bd57

6 files changed

+816
-6
lines changed

optillm/plugins/readurls_plugin.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def extract_urls(text: str) -> List[str]:
2525
def fetch_webpage_content(url: str, max_length: int = 100000) -> str:
2626
try:
2727
headers = {
28-
'User-Agent': 'optillm/0.0.1 (hhttps://github.com/codelion/optillm)'
28+
'User-Agent': 'optillm/0.0.1 (https://github.com/codelion/optillm)'
2929
}
3030

3131
response = requests.get(url, headers=headers, timeout=10)
@@ -45,15 +45,42 @@ def fetch_webpage_content(url: str, max_length: int = 100000) -> str:
4545
for tag in ['article', 'main', 'div[role="main"]', '.main-content']:
4646
content = soup.select_one(tag)
4747
if content:
48-
text_elements.extend(content.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p']))
48+
text_elements.extend(content.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'table']))
4949
break
5050

51-
# If no main content found, fall back to all headers and paragraphs
51+
# If no main content found, fall back to all headers, paragraphs, and tables
5252
if not text_elements:
53-
text_elements = soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'])
53+
text_elements = soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'table'])
5454

55-
# Extract text from elements
56-
text = ' '.join(element.get_text(strip=True) for element in text_elements)
55+
# Process all elements including tables
56+
content_parts = []
57+
58+
for element in text_elements:
59+
if element.name == 'table':
60+
# Process table
61+
table_content = []
62+
63+
# Get headers
64+
headers = element.find_all('th')
65+
if headers:
66+
header_text = ' | '.join(header.get_text(strip=True) for header in headers)
67+
table_content.append(header_text)
68+
69+
# Get rows
70+
for row in element.find_all('tr'):
71+
cells = row.find_all(['td', 'th'])
72+
if cells:
73+
row_text = ' | '.join(cell.get_text(strip=True) for cell in cells)
74+
table_content.append(row_text)
75+
76+
# Add table content with proper spacing
77+
content_parts.append('\n' + '\n'.join(table_content) + '\n')
78+
else:
79+
# Process regular text elements
80+
content_parts.append(element.get_text(strip=False))
81+
82+
# Join all content
83+
text = ' '.join(content_parts)
5784

5885
# Remove extra whitespace
5986
text = re.sub(r'\s+', ' ', text).strip()

scripts/eval_frames_benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def get_llm_response(prompt: str, model: str) -> str:
4444
n=1,
4545
stop=None,
4646
temperature=0.7,
47+
extra_body={"optillm_approach": "readurls&memory"}
4748
)
4849
return response.choices[0].message.content.strip()
4950

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"index": 0,
4+
"prompt": "If my future wife has the same first name as the 15th first lady of the United States' mother and her surname is the same as the second assassinated president's mother's maiden name, what is my future wife's name? ",
5+
"ground_truth": "Jane Ballou",
6+
"llm_response": "Based on the margin notes provided, the first name of the 15th First Lady of the United States' mother is Mary, and the surname of the second assassinated president's mother (Abraham Lincoln) is Hanks. Therefore, if your future wife has the same first name as Harriet Lane's mother (Mary) and the same surname as Abraham Lincoln's mother's maiden name (Hanks), her name would be Mary Hanks.",
7+
"evaluation_decision": "FALSE",
8+
"evaluation_explanation": "The \"Predicted Answer\" states that the future wife's name would be \"Mary Hanks,\" derived from the first name of the 15th First Lady of the United States' mother (Mary) and the surname of Abraham Lincoln's mother's maiden name (Hanks). However, the \"Ground Truth Answer\" is \"Jane Ballou,\" which does not match the name derived in the \"Predicted Answer.\" The key information and vital facts leading to the correct name are not present in the \"Predicted Answer,\" as it provides a different name entirely.",
9+
"reasoning_type": "Multiple constraints"
10+
},
11+
{
12+
"index": 1,
13+
"prompt": "Imagine there is a building called Bronte tower whose height in feet is the same number as the dewey decimal classification for the Charlotte Bronte book that was published in 1847. Where would this building rank among tallest buildings in New York City, as of August 2024?",
14+
"ground_truth": "37th",
15+
"llm_response": "The Dewey Decimal classification for \"Jane Eyre,\" published in 1847, is 823.8. The height of the Bronte Tower, according to the information provided, would be 824 feet.\n\nAs of March 2024, a building that is 824 feet tall would rank at 52nd place among the tallest buildings in New York City, sharing that rank with several other buildings of the same height.\n\nSince the question refers to August 2024, it can be inferred that the rankings have not dramatically changed in that time period unless there have been significant new constructions or demolitions, which the provided information does not indicate. Therefore, it is reasonable to conclude that the Bronte Tower at 824 feet would still rank at around the same place.\n\nThus, the Bronte Tower would likely still rank at 52nd place among the tallest buildings in New York City as of August 2024.",
16+
"evaluation_decision": "FALSE",
17+
"evaluation_explanation": "The Predicted Answer states that the Bronte Tower would rank at 52nd place among the tallest buildings in New York City as of August 2024. In contrast, the Ground Truth Answer indicates that the ranking should be 37th. The two answers provide different rankings, and the Predicted Answer does not support the Ground Truth Answer in terms of the building's rank. Therefore, the essential information regarding the ranking of the Bronte Tower is not aligned between the two answers.",
18+
"reasoning_type": "Numerical reasoning | Tabular reasoning | Multiple constraints"
19+
},
20+
{
21+
"index": 2,
22+
"prompt": "How many years earlier would Punxsutawney Phil have to be canonically alive to have made a Groundhog Day prediction in the same state as the US capitol?",
23+
"ground_truth": "87",
24+
"llm_response": "To answer your question, we need to know both the canonical year of Punxsutawney Phil's first prediction and the year when Groundhog Day was declared an established tradition in Punxsutawney, Pennsylvania, compared to when Washington, D.C. became the capital of the United States.\n\nGroundhog Day has been celebrated in Punxsutawney since 1887. The establishment of the city of Washington, D.C., as the capital was solidified with the Residence Act of 1790, although the city was formally founded in 1791.\n\nIf we take 1887, the year Phil's predictions began, and 1790 as the year Washington became the capital, the difference in years is:\n\n1887 - 1790 = 97 years.\n\nThus, to have made a Groundhog Day prediction in the same state as the U.S. capital, Punxsutawney Phil would have to canonically be alive 97 years earlier, specifically from 1887.",
25+
"evaluation_decision": "FALSE",
26+
"evaluation_explanation": "The \"Predicted Answer\" provides a calculation based on the years when Groundhog Day began (1887) and when Washington, D.C. was established as the capital (1790). It correctly calculates the difference as 97 years. However, the \"Ground Truth Answer\" states that the answer is 87 years, which is incorrect based on the provided historical context. The \"Predicted Answer\" does not contain the correct answer of 87 years, and instead provides a different calculation of 97 years. Therefore, the meaning and vital facts of the \"Ground Truth Answer\" are not present in the \"Predicted Answer.\"",
27+
"reasoning_type": "Numerical reasoning | Multiple constraints | Temporal reasoning"
28+
},
29+
{
30+
"index": 3,
31+
"prompt": "As of August 1, 2024, which country were holders of the FIFA World Cup the last time the UEFA Champions League was won by a club from London?",
32+
"ground_truth": "France",
33+
"llm_response": "As of August 1, 2024, the last time the UEFA Champions League was won by a club from London was in 2021, when Chelsea FC won the title. The FIFA World Cup held before that date was in 2018, and the holder of the FIFA World Cup at that time was France, who won the tournament in Russia. Therefore, holders of the FIFA World Cup as of August 1, 2024, were France.",
34+
"evaluation_decision": "TRUE",
35+
"evaluation_explanation": "The \"Predicted Answer\" states that the holders of the FIFA World Cup as of August 1, 2024, were France, which directly matches the \"Ground Truth Answer\" of \"France.\" The meaning and vital facts are present in the \"Predicted Answer,\" confirming that France was the holder of the FIFA World Cup at the relevant time.",
36+
"reasoning_type": "Tabular reasoning | Multiple constraints | Temporal reasoning"
37+
},
38+
{
39+
"index": 4,
40+
"prompt": "What is the name of the vocalist from the first band to make it in the top 200 under the record label that produced the third studio album for Dismal Euphony?",
41+
"ground_truth": "Jens Kidman",
42+
"llm_response": "The name of the vocalist is Jens Kidman, who is from the band Meshuggah.",
43+
"evaluation_decision": "TRUE",
44+
"evaluation_explanation": "The \"Predicted Answer\" identifies Jens Kidman as the vocalist, which directly matches the \"Ground Truth Answer\" that simply states \"Jens Kidman.\" The essential information regarding the name of the vocalist is present in the \"Predicted Answer,\" even though it includes additional context about the band Meshuggah. Since the core fact that Jens Kidman is the name of the vocalist is included, the meaning is preserved.",
45+
"reasoning_type": "Multiple constraints"
46+
},
47+
{
48+
"index": 5,
49+
"prompt": "According to the 2000 United States census, what was the 2000 population of the birth city of the only 21st-century mayor of Austin, Texas who also served as mayor in the 1990s? Round your answer to the nearest thousand.",
50+
"ground_truth": "506000",
51+
"llm_response": "According to the note, the birth city of Kirk Watson, the only 21st-century mayor of Austin who also served as mayor in the 1990s, is Oklahoma City. The 2000 population of Oklahoma City, as stated in the note, was 506,132. \n\nRounding this number to the nearest thousand gives us **506,000**.",
52+
"evaluation_decision": "TRUE",
53+
"evaluation_explanation": "The Predicted Answer provides the birth city of Kirk Watson, the only 21st-century mayor of Austin who also served in the 1990s, as Oklahoma City. It also states the 2000 population of Oklahoma City as 506,132 and correctly rounds it to 506,000. The Ground Truth Answer is simply the rounded population figure, which matches the rounding provided in the Predicted Answer. Since the essential information and the final rounded population figure are present and accurate in the Predicted Answer, it aligns with the Ground Truth Answer.",
54+
"reasoning_type": "Numerical reasoning | Tabular reasoning | Multiple constraints"
55+
}
56+
]

0 commit comments

Comments
 (0)