xonecas.io
79113
Ma

mini-coding-agent / files

mini-coding-agent / tools / gen_models_dev.py

1.2 KB
1#!/usr/bin/env python3
2"""Fetches models.dev and writes src/models_dev.json.
3
4The provider decides which models exist (we ask it at runtime); models.dev
5decides the wire, base URL and metadata for each model id. Only the providers
6this agent can talk to are kept. The output is committed, so a normal
7`zig build` needs no network. Run `python3 tools/gen_models_dev.py` to refresh.
8"""
9
10import json
11import sys
12import urllib.request
13
14MODELS_DEV = "https://models.dev/api.json"
15
16PROVIDERS = ["opencode", "opencode-go", "openrouter"]
17
18
19def main():
20    out = sys.argv[1] if len(sys.argv) > 1 else "src/models_dev.json"
21    req = urllib.request.Request(MODELS_DEV, headers={"User-Agent": "mini-models-dev/1"})
22    with urllib.request.urlopen(req) as r:
23        data = json.loads(r.read())
24
25    kept = {}
26    for pid in PROVIDERS:
27        if pid not in data:
28            sys.exit("models.dev: provider %r missing" % pid)
29        kept[pid] = dict(data[pid])
30
31    with open(out, "w") as f:
32        json.dump(kept, f, separators=(",", ":"))
33        f.write("\n")
34    print("wrote %s (%d providers, %d models)" % (
35        out, len(kept), sum(len(p["models"]) for p in kept.values())))
36
37
38if __name__ == "__main__":
39    main()