model_capabilities
model_capabilities.py — Provider capability registry for LLM model dispatch.
Replaces the fragile "gemini" in model.lower() substring checks in
openrouter_client with an explicit pattern-matched registry.
Usage:
from model_capabilities import get_capabilities
caps = get_capabilities(model)
if caps.provider == "google":
... # inject reasoning field, apply Gemini-specific sanitization
if caps.requires_reasoning_field:
...
- class model_capabilities.ModelCapabilities(provider='openrouter', requires_reasoning_field=False, supports_multimodal=True, supports_system_role=True, supports_tool_calls=True)[source]
Bases:
objectImmutable capability record for a matched model pattern.
A frozen dataclass describing what an LLM endpoint supports, so callers can branch on provider quirks instead of repeating brittle substring checks. The flags drive provider-specific request shaping in the OpenRouter client – for example whether to inject a separate
reasoning/thinkingfield, whether asystemrole is accepted, and whether multimodal parts or tool calls are allowed.Instances are constructed in this module’s
_REGISTRY(one per glob pattern) and the_DEFAULTfallback, and are returned byget_capabilities. Being frozen, a single instance is shared by every model that matches a given pattern, so it must never be mutated by callers.- Parameters:
- provider: str = 'openrouter'
‘google’, ‘anthropic’, ‘openai’, ‘deepseek’, ‘openrouter’.
- Type:
Canonical provider name
- model_capabilities.get_capabilities(model)[source]
Return the
ModelCapabilitiesfor model.Matches the model identifier against
_REGISTRYusingfnmatch.fnmatch()(case-insensitive). Falls back to legacy substring heuristics for unregistered models that still contain well-known provider keywords, then returns safe defaults.- Parameters:
model (
str) – The model identifier string (e.g."gemini-2.5-pro").- Return type:
- Returns:
ModelCapabilitiesinstance; never raises.