Ensure model capabilities have required fields. TODO: Remove once the runtime schema correctly marks these fields as optional. Some models (e.g. embedding models) may omit 'limits' or 'supports' in their capabilities, or omit 'max_context_window_tokens' within limits. The generated
(data: dict)
| 25062 | return {} |
| 25063 | |
| 25064 | def _patch_model_capabilities(data: dict) -> dict: |
| 25065 | """Ensure model capabilities have required fields. |
| 25066 | |
| 25067 | TODO: Remove once the runtime schema correctly marks these fields as optional. |
| 25068 | Some models (e.g. embedding models) may omit 'limits' or 'supports' in their |
| 25069 | capabilities, or omit 'max_context_window_tokens' within limits. The generated |
| 25070 | deserializer requires these fields, so we supply defaults here. |
| 25071 | """ |
| 25072 | for model in data.get("models", []): |
| 25073 | caps = model.get("capabilities") |
| 25074 | if caps is None: |
| 25075 | model["capabilities"] = {"supports": {}, "limits": {"max_context_window_tokens": 0}} |
| 25076 | continue |
| 25077 | if "supports" not in caps: |
| 25078 | caps["supports"] = {} |
| 25079 | if "limits" not in caps: |
| 25080 | caps["limits"] = {"max_context_window_tokens": 0} |
| 25081 | elif "max_context_window_tokens" not in caps["limits"]: |
| 25082 | caps["limits"]["max_context_window_tokens"] = 0 |
| 25083 | return data |
| 25084 | |
| 25085 | |
| 25086 | # Experimental: this API group is experimental and may change or be removed. |