mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 02:54:37 +00:00
Merge pull request #101 from Routstr/model-collecting
update model collecting to filter by source
This commit is contained in:
+17
-9
@@ -43,24 +43,33 @@ class Model(TypedDict):
|
||||
|
||||
OUTPUT_FILE = os.getenv("OUTPUT_FILE", "models.json")
|
||||
BASE_URL = os.getenv("BASE_URL", "https://openrouter.ai/api/v1")
|
||||
SOURCE = os.getenv("SOURCE")
|
||||
|
||||
|
||||
def fetch_openrouter_models() -> list[Model]:
|
||||
def fetch_openrouter_models(source_filter: str | None = None) -> list[Model]:
|
||||
"""Fetches model information from OpenRouter API."""
|
||||
with urlopen(f"{BASE_URL}/models") as response:
|
||||
data = json.loads(response.read().decode("utf-8"))
|
||||
|
||||
models_data: list[Model] = []
|
||||
for model in data.get("data", []):
|
||||
# Skip models with '(free)' in the name or id = 'openrouter/auto'
|
||||
model_id = model.get("id", "")
|
||||
|
||||
if source_filter:
|
||||
source_prefix = f"{source_filter}/"
|
||||
if not model_id.startswith(source_prefix):
|
||||
continue
|
||||
|
||||
model = dict(model)
|
||||
model["id"] = model_id[len(source_prefix) :]
|
||||
model_id = model["id"]
|
||||
|
||||
if (
|
||||
"(free)" in model.get("name", "")
|
||||
or model.get("id") == "openrouter/auto"
|
||||
or model_id == "openrouter/auto"
|
||||
or model_id == "google/gemini-2.5-pro-exp-03-25"
|
||||
):
|
||||
continue
|
||||
# Skip free Gemini 2.5 Pro Exp
|
||||
if model.get("id") == "google/gemini-2.5-pro-exp-03-25":
|
||||
continue
|
||||
|
||||
models_data.append(model)
|
||||
|
||||
@@ -68,10 +77,9 @@ def fetch_openrouter_models() -> list[Model]:
|
||||
|
||||
|
||||
def main() -> None:
|
||||
models = fetch_openrouter_models()
|
||||
source_filter = SOURCE if SOURCE and SOURCE.strip() else None
|
||||
models = fetch_openrouter_models(source_filter=source_filter)
|
||||
|
||||
# Print the first model data in a nicely indented JSON format
|
||||
# print(json.dumps(models[0], indent=4))
|
||||
print(f"Writing {len(models)} models to {OUTPUT_FILE}")
|
||||
|
||||
with open(OUTPUT_FILE, "w") as f:
|
||||
|
||||
Reference in New Issue
Block a user