auto run models update script

This commit is contained in:
shroominic
2025-06-30 16:11:18 +00:00
parent 976df1d5cc
commit e5354fd773
2 changed files with 16 additions and 4 deletions
+5 -1
View File
@@ -1,3 +1,7 @@
REPO_DIR=/home/user/proxy
LOG_FILE=/home/user/proxy/update.log
* * * * * /home/user/proxy/scripts/auto_update.sh >/dev/null 2>&1
* * * * * /home/user/proxy/scripts/auto_update.sh >/dev/null 2>&1
OUTPUT_FILE=/home/user/proxy/models.json
BASE_URL=https://openrouter.ai/api/v1
0 * * * * python3 /home/user/proxy/scripts/models_meta.py >/dev/null 2>&1
Regular → Executable
+11 -3
View File
@@ -1,4 +1,7 @@
#!/usr/bin/env python3
import json
import os
from typing import TypedDict
from urllib.request import urlopen
@@ -38,9 +41,13 @@ class Model(TypedDict):
per_request_limits: dict | None
OUTPUT_FILE = os.getenv("OUTPUT_FILE", "models.json")
BASE_URL = os.getenv("BASE_URL", "https://openrouter.ai/api/v1")
def fetch_openrouter_models() -> list[Model]:
"""Fetches model information from OpenRouter API."""
with urlopen("https://openrouter.ai/api/v1/models") as response:
with urlopen(f"{BASE_URL}/models") as response:
data = json.loads(response.read().decode("utf-8"))
models_data: list[Model] = []
@@ -64,9 +71,10 @@ def main() -> None:
models = fetch_openrouter_models()
# Print the first model data in a nicely indented JSON format
print(json.dumps(models[0], indent=4))
# print(json.dumps(models[0], indent=4))
print(f"Writing {len(models)} models to {OUTPUT_FILE}")
with open("or-models.json", "w") as f:
with open(OUTPUT_FILE, "w") as f:
json.dump({"models": models}, f, indent=4)