LLMCalc / src /pricing.py
carbonnnnn's picture
update fetching
d8f251a
raw
history blame
1.05 kB
import pandas as pd
import requests
def fetch_prices():
# Fetch the JSON data from the URL
url = "https://llm-price.huhuhang.workers.dev/"
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
# Extract relevant information
extracted_data = []
for entry in data:
extracted_info = {
"output_tokens": entry["fields"]["output_tokens"],
"provider": entry["fields"]["provider"],
"model_name": entry["fields"]["model_name"],
"url": entry["fields"]["url"],
"input_tokens": entry["fields"]["input_tokens"],
"update_time": entry["fields"]["update_time"]
}
extracted_data.append(extracted_info)
# Create a DataFrame from the extracted data
df = pd.DataFrame(extracted_data)
return df
else:
print(f"Failed to retrieve data: {response.status_code}")
return None