|
import pandas as pd |
|
import requests |
|
import os |
|
|
|
def fetch_prices(): |
|
|
|
url = "https://llm-price.huhuhang.workers.dev/" |
|
response = requests.get(url) |
|
|
|
|
|
if response.status_code == 200: |
|
data = response.json() |
|
|
|
extracted_data = [] |
|
for entry in data: |
|
extracted_info = { |
|
"model_name": entry["fields"]["model_name"], |
|
"provider": entry["fields"]["provider"], |
|
"input_tokens": entry["fields"]["input_tokens"], |
|
"output_tokens": entry["fields"]["output_tokens"], |
|
"url": entry["fields"]["url"], |
|
"update_time": entry["fields"]["update_time"] |
|
} |
|
extracted_data.append(extracted_info) |
|
|
|
|
|
df = pd.DataFrame(extracted_data) |
|
save_path = os.path.join('src', 'prices.csv') |
|
df.to_csv(save_path, index=False) |
|
print(f"Saved the Prices as a CSV under {save_path}") |
|
else: |
|
print(f"Failed to retrieve data: {response.status_code}") |
|
return None |
|
|
|
if __name__ == '__main__': |
|
fetch_prices() |