回源拉上游模型列表,归一化成 Science 可消费的模型列表。relay 会刷新 RELAY_MODELS 缓存(供 resolve_model 贴合);openai-custom 仅用于模型发现。返回 list(可空)。
()
| 354 | |
| 355 | |
| 356 | def fetch_relay_models(): |
| 357 | """回源拉上游模型列表,归一化成 Science 可消费的模型列表。relay 会刷新 |
| 358 | RELAY_MODELS 缓存(供 resolve_model 贴合);openai-custom 仅用于模型发现。返回 list(可空)。""" |
| 359 | global RELAY_MODELS |
| 360 | murl = PROV.get("models_url") |
| 361 | if not murl: |
| 362 | return [] |
| 363 | headers = dict(_upstream_auth_headers()) |
| 364 | if PROV_NAME == "relay": |
| 365 | headers["anthropic-version"] = "2023-06-01" |
| 366 | raw = http_get_json(murl, headers) |
| 367 | data = raw.get("data") if isinstance(raw, dict) else raw |
| 368 | out, ids = [], [] |
| 369 | for m in data or []: |
| 370 | mid = m.get("id") if isinstance(m, dict) else None |
| 371 | if not mid: |
| 372 | continue |
| 373 | ids.append(mid) |
| 374 | # 能力位:从上游 supported_parameters 推断,绝不臆测(无该字段 → None)。 |
| 375 | sp = m.get("supported_parameters") if isinstance(m, dict) else None |
| 376 | supports_tools = ("tools" in sp) if isinstance(sp, list) else None |
| 377 | out.append({"type": "model", "id": mid, |
| 378 | "display_name": (m.get("display_name") if isinstance(m, dict) else None) or mid, |
| 379 | "supports_tools": supports_tools, |
| 380 | "created_at": "2026-01-01T00:00:00Z"}) |
| 381 | if ids and PROV_NAME == "relay": |
| 382 | RELAY_MODELS = ids |
| 383 | return out |
| 384 | |
| 385 | |
| 386 | def build_models_response(): |
no test coverage detected