To accomplish the task described, we will create a Python module that checks the provided URL, parses the HTML content, and searches for your LLM model (o3) in the table. The module will then check its ranking and trigger an action based on the ranking.
First, ensure you have the necessary libraries installed. You will need requests for making an HTTP request to the URL and beautifulsoup4 for parsing the HTML content. You can install them using pip:
pip install requests beautifulsoup4
Here's a Python module that performs the described task:
import requests
from bs4 import BeautifulSoup
def check_model_ranking(url: str = "https://beta.lmarena.ai/"):
"""
Checks the ranking of the o3 model on the provided URL.
Args:
- url (str): The URL to check. Defaults to "https://beta.lmarena.ai/".
Returns:
- ranking (int or None): The ranking of the model if found, None otherwise.
"""
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors
except requests.RequestException as e:
print(f"Request failed: {e}")
return None
soup = BeautifulSoup(response.text, 'html.parser')
model_rows = soup.find_all('tr')
for row in model_rows:
cols = row.find_all('td')
if len(cols) > 2: # Ensure it's a model row
model_name_col = cols[2]
model_name_link = model_name_col.find('a')
if model_name_link:
model_name = model_name_link.text.strip()
if model_name.startswith('o3') and 'mini' not in model_name.lower():
ranking_col = cols[0]
ranking = int(ranking_col.text.strip())
return ranking
return None
def trigger_action(ranking: int):
"""
Triggers an action based on the model's ranking.
Args:
- ranking (int): The ranking of the model.
"""
if ranking is not None and ranking != 1:
# Implement your action here
print(f"Model is ranked {ranking}. Triggering action...")
# Your action code goes here
else:
print("Model is ranked #1 or not found. No action triggered.")
def main():
url = "https://beta.lmarena.ai/"
ranking = check_model_ranking(url)
if ranking is None:
print("Model not found or request failed.")
else:
print(f"Model ranking: {ranking}")
trigger_action(ranking)
if __name__ == "__main__":
main()
This script does the following:
- Sends a GET request to the specified URL.
- Parses the HTML response using BeautifulSoup.
- Iterates through the table rows to find the one containing your
o3 model (not o3-mini or its variants).
- Extracts the ranking of the model.