Spaces:
Runtime error
Runtime error
Upload sync_hf.py
Browse files- scripts/sync_hf.py +57 -2
scripts/sync_hf.py
CHANGED
|
@@ -960,6 +960,31 @@ class OpenClawFullSync:
|
|
| 960 |
}, f)
|
| 961 |
print("[SYNC] Created minimal openclaw.json")
|
| 962 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 963 |
def _patch_config(self):
|
| 964 |
config_path = OPENCLAW_HOME / "openclaw.json"
|
| 965 |
if not config_path.exists():
|
|
@@ -1069,13 +1094,43 @@ class OpenClawFullSync:
|
|
| 1069 |
).split(",")
|
| 1070 |
if m.strip()
|
| 1071 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1072 |
providers_section["xkiro"] = {
|
| 1073 |
"baseUrl": "https://api.xkiro.com/v1",
|
| 1074 |
"apiKey": "${XKIRO_API_KEY}",
|
| 1075 |
"api": "openai-completions",
|
| 1076 |
-
"models":
|
| 1077 |
}
|
| 1078 |
-
print(f"[SYNC] Configured xkiro provider ({len(xkiro_ids)} models
|
|
|
|
| 1079 |
elif "xkiro" in providers_section:
|
| 1080 |
del providers_section["xkiro"]
|
| 1081 |
print("[SYNC] Removed xkiro provider (XKIRO_API_KEY not set)")
|
|
|
|
| 960 |
}, f)
|
| 961 |
print("[SYNC] Created minimal openclaw.json")
|
| 962 |
|
| 963 |
+
def _fetch_xkiro_catalog(self):
|
| 964 |
+
url = os.environ.get("XKIRO_CATALOG_URL")
|
| 965 |
+
if url == "":
|
| 966 |
+
return {}
|
| 967 |
+
if not url:
|
| 968 |
+
url = "https://api.xkiro.com/v1/models"
|
| 969 |
+
try:
|
| 970 |
+
req = urllib.request.Request(url, headers={"User-Agent": "HuggingClaw/1.0"})
|
| 971 |
+
with urllib.request.urlopen(req, timeout=5) as resp:
|
| 972 |
+
payload = json.loads(resp.read().decode("utf-8", "replace"))
|
| 973 |
+
if isinstance(payload, dict):
|
| 974 |
+
rows = payload.get("data") or payload.get("models") or []
|
| 975 |
+
elif isinstance(payload, list):
|
| 976 |
+
rows = payload
|
| 977 |
+
else:
|
| 978 |
+
rows = []
|
| 979 |
+
return {
|
| 980 |
+
r["id"]: r
|
| 981 |
+
for r in rows
|
| 982 |
+
if isinstance(r, dict) and isinstance(r.get("id"), str)
|
| 983 |
+
}
|
| 984 |
+
except Exception as e:
|
| 985 |
+
print(f"[SYNC] xkiro catalog fetch failed ({e}); using bare model entries")
|
| 986 |
+
return {}
|
| 987 |
+
|
| 988 |
def _patch_config(self):
|
| 989 |
config_path = OPENCLAW_HOME / "openclaw.json"
|
| 990 |
if not config_path.exists():
|
|
|
|
| 1094 |
).split(",")
|
| 1095 |
if m.strip()
|
| 1096 |
]
|
| 1097 |
+
xkiro_catalog = self._fetch_xkiro_catalog()
|
| 1098 |
+
xkiro_entries = []
|
| 1099 |
+
xkiro_enriched = 0
|
| 1100 |
+
for mid in xkiro_ids:
|
| 1101 |
+
row = xkiro_catalog.get(mid)
|
| 1102 |
+
entry = {"id": mid, "name": mid}
|
| 1103 |
+
if isinstance(row, dict):
|
| 1104 |
+
if row.get("display_name"):
|
| 1105 |
+
entry["name"] = str(row["display_name"])
|
| 1106 |
+
if isinstance(row.get("context_length"), (int, float)):
|
| 1107 |
+
entry["contextWindow"] = int(row["context_length"])
|
| 1108 |
+
if isinstance(row.get("max_output_tokens"), (int, float)):
|
| 1109 |
+
entry["maxTokens"] = int(row["max_output_tokens"])
|
| 1110 |
+
caps = row.get("capabilities")
|
| 1111 |
+
caps = caps if isinstance(caps, dict) else {}
|
| 1112 |
+
entry["input"] = ["text", "image"] if caps.get("vision") else ["text"]
|
| 1113 |
+
if caps.get("reasoning") is not None:
|
| 1114 |
+
entry["reasoning"] = bool(caps.get("reasoning"))
|
| 1115 |
+
price = row.get("pricing")
|
| 1116 |
+
price = price if isinstance(price, dict) else {}
|
| 1117 |
+
cost = {
|
| 1118 |
+
k: price[k]
|
| 1119 |
+
for k in ("input", "output", "cacheRead", "cacheWrite")
|
| 1120 |
+
if isinstance(price.get(k), (int, float))
|
| 1121 |
+
}
|
| 1122 |
+
if cost:
|
| 1123 |
+
entry["cost"] = cost
|
| 1124 |
+
xkiro_enriched += 1
|
| 1125 |
+
xkiro_entries.append(entry)
|
| 1126 |
providers_section["xkiro"] = {
|
| 1127 |
"baseUrl": "https://api.xkiro.com/v1",
|
| 1128 |
"apiKey": "${XKIRO_API_KEY}",
|
| 1129 |
"api": "openai-completions",
|
| 1130 |
+
"models": xkiro_entries,
|
| 1131 |
}
|
| 1132 |
+
print(f"[SYNC] Configured xkiro provider ({len(xkiro_ids)} models, "
|
| 1133 |
+
f"{xkiro_enriched} enriched)")
|
| 1134 |
elif "xkiro" in providers_section:
|
| 1135 |
del providers_section["xkiro"]
|
| 1136 |
print("[SYNC] Removed xkiro provider (XKIRO_API_KEY not set)")
|