35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
"""Time public model metadata endpoints; no account credential is sent."""
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
import json
|
|
import time
|
|
from urllib.error import HTTPError, URLError
|
|
from urllib.request import urlopen
|
|
|
|
|
|
def run():
|
|
urls = {
|
|
"hf_mirror_api": "https://hf-mirror.com/api/models/Qwen/Qwen2.5-0.5B-Instruct",
|
|
"hf_mirror_config": "https://hf-mirror.com/Qwen/Qwen2.5-0.5B-Instruct/resolve/main/config.json",
|
|
"hf_official_api": "https://huggingface.co/api/models/Qwen/Qwen2.5-0.5B-Instruct",
|
|
"modelscope_config": "https://modelscope.cn/models/Qwen/Qwen2.5-0.5B-Instruct/resolve/master/config.json",
|
|
}
|
|
|
|
def check(item):
|
|
name, url = item
|
|
started = time.monotonic()
|
|
value = {"endpoint": name}
|
|
try:
|
|
with urlopen(url, timeout=8) as response:
|
|
body = response.read(262144)
|
|
value.update(httpStatus=response.status, jsonValid=isinstance(json.loads(body), dict))
|
|
except HTTPError as error:
|
|
value.update(httpStatus=error.code, errorType=type(error).__name__)
|
|
except (URLError, TimeoutError, ValueError, OSError) as error:
|
|
value["errorType"] = type(error).__name__
|
|
value["seconds"] = round(time.monotonic() - started, 2)
|
|
return value
|
|
|
|
with ThreadPoolExecutor(max_workers=4) as executor:
|
|
results = list(executor.map(check, urls.items()))
|
|
print(json.dumps({"name": "xc-cloud-network-probe", "version": "probe-20261026-04", "results": results}), flush=True)
|