Skip to content

Commit 9b576e3

Browse files
bmehta001Copilot
andauthored
Add model context capabilities to Python (#564)
Python SDK: add contextLength, inputModalities, outputModalities, capabilities; also added tests for these fields --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d731c6d commit 9b576e3

6 files changed

Lines changed: 139 additions & 0 deletions

File tree

sdk/python/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,31 @@ cached = catalog.get_cached_models()
142142
loaded = catalog.get_loaded_models()
143143
```
144144

145+
### Inspecting Model Metadata
146+
147+
`Model` exposes metadata properties from the catalog:
148+
149+
```python
150+
model = catalog.get_model("phi-3.5-mini")
151+
152+
# Identity
153+
print(model.id) # e.g. "phi-3.5-mini-instruct-generic-gpu:3"
154+
print(model.alias) # e.g. "phi-3.5-mini"
155+
156+
# Context and token limits
157+
print(model.context_length) # e.g. 131072 (tokens), or None if unknown
158+
159+
# Modalities and capabilities
160+
print(model.input_modalities) # e.g. "text" or "text,image"
161+
print(model.output_modalities) # e.g. "text"
162+
print(model.capabilities) # e.g. "chat,completion"
163+
print(model.supports_tool_calling) # True, False, or None
164+
165+
# Cache / load state
166+
print(model.is_cached)
167+
print(model.is_loaded)
168+
```
169+
145170
### Loading and Running a Model
146171

147172
```python

sdk/python/src/detail/model_data_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ class ModelInfo(BaseModel):
7474
max_output_tokens: Optional[int] = Field(alias="maxOutputTokens")
7575
min_fl_version: Optional[str] = Field(alias="minFLVersion")
7676
created_at_unix: int = Field(alias="createdAt")
77+
context_length: Optional[int] = Field(alias="contextLength")
78+
input_modalities: Optional[str] = Field(alias="inputModalities")
79+
output_modalities: Optional[str] = Field(alias="outputModalities")
80+
capabilities: Optional[str] = Field(alias="capabilities")

sdk/python/src/imodel.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@ def is_loaded(self) -> bool:
3737
"""True if the model is loaded into memory."""
3838
pass
3939

40+
@property
41+
@abstractmethod
42+
def context_length(self) -> Optional[int]:
43+
"""Maximum context length (in tokens) supported by the model, or ``None`` if unknown."""
44+
pass
45+
46+
@property
47+
@abstractmethod
48+
def input_modalities(self) -> Optional[str]:
49+
"""Comma-separated input modalities (e.g. ``"text,image"``), or ``None`` if unknown."""
50+
pass
51+
52+
@property
53+
@abstractmethod
54+
def output_modalities(self) -> Optional[str]:
55+
"""Comma-separated output modalities (e.g. ``"text"``), or ``None`` if unknown."""
56+
pass
57+
58+
@property
59+
@abstractmethod
60+
def capabilities(self) -> Optional[str]:
61+
"""Comma-separated capability tags (e.g. ``"chat,completion"``), or ``None`` if unknown."""
62+
pass
63+
64+
@property
65+
@abstractmethod
66+
def supports_tool_calling(self) -> Optional[bool]:
67+
"""Whether the model supports tool/function calling, or ``None`` if unknown."""
68+
pass
69+
4070
@abstractmethod
4171
def download(self, progress_callback: Callable[[float], None] = None) -> None:
4272
"""

sdk/python/src/model.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,31 @@ def alias(self) -> str:
9494
"""Alias of this model."""
9595
return self._alias
9696

97+
@property
98+
def context_length(self) -> Optional[int]:
99+
"""Maximum context length (in tokens) of the currently selected variant."""
100+
return self._selected_variant.context_length
101+
102+
@property
103+
def input_modalities(self) -> Optional[str]:
104+
"""Comma-separated input modalities of the currently selected variant."""
105+
return self._selected_variant.input_modalities
106+
107+
@property
108+
def output_modalities(self) -> Optional[str]:
109+
"""Comma-separated output modalities of the currently selected variant."""
110+
return self._selected_variant.output_modalities
111+
112+
@property
113+
def capabilities(self) -> Optional[str]:
114+
"""Comma-separated capability tags of the currently selected variant."""
115+
return self._selected_variant.capabilities
116+
117+
@property
118+
def supports_tool_calling(self) -> Optional[bool]:
119+
"""Whether the currently selected variant supports tool/function calling."""
120+
return self._selected_variant.supports_tool_calling
121+
97122
@property
98123
def is_cached(self) -> bool:
99124
"""Is the currently selected variant cached locally?"""

sdk/python/src/model_variant.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ def info(self) -> ModelInfo:
5757
"""Full catalog metadata for this variant."""
5858
return self._model_info
5959

60+
@property
61+
def context_length(self) -> Optional[int]:
62+
"""Maximum context length (in tokens) supported by this variant, or ``None`` if unknown."""
63+
return self._model_info.context_length
64+
65+
@property
66+
def input_modalities(self) -> Optional[str]:
67+
"""Comma-separated input modalities (e.g. ``"text,image"``), or ``None`` if unknown."""
68+
return self._model_info.input_modalities
69+
70+
@property
71+
def output_modalities(self) -> Optional[str]:
72+
"""Comma-separated output modalities (e.g. ``"text"``), or ``None`` if unknown."""
73+
return self._model_info.output_modalities
74+
75+
@property
76+
def capabilities(self) -> Optional[str]:
77+
"""Comma-separated capability tags (e.g. ``"chat,completion"``), or ``None`` if unknown."""
78+
return self._model_info.capabilities
79+
80+
@property
81+
def supports_tool_calling(self) -> Optional[bool]:
82+
"""Whether this variant supports tool/function calling, or ``None`` if unknown."""
83+
return self._model_info.supports_tool_calling
84+
6085
@property
6186
def is_cached(self) -> bool:
6287
"""``True`` if this variant is present in the local model cache."""

sdk/python/test/test_model.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,33 @@ def test_should_load_and_unload_model(self, catalog):
5656
# Safety cleanup
5757
if model.is_loaded:
5858
model.unload()
59+
60+
def test_should_expose_context_length(self, catalog):
61+
"""Model should expose context_length from ModelInfo metadata."""
62+
model = catalog.get_model(TEST_MODEL_ALIAS)
63+
assert model is not None
64+
# context_length should be None or a positive integer
65+
ctx = model.context_length
66+
assert ctx is None or (isinstance(ctx, int) and ctx > 0)
67+
68+
def test_should_expose_modalities(self, catalog):
69+
"""Model should expose input_modalities and output_modalities."""
70+
model = catalog.get_model(TEST_MODEL_ALIAS)
71+
assert model is not None
72+
# Modalities should be None or non-empty strings
73+
for val in (model.input_modalities, model.output_modalities):
74+
assert val is None or (isinstance(val, str) and len(val) > 0)
75+
76+
def test_should_expose_capabilities(self, catalog):
77+
"""Model should expose capabilities metadata."""
78+
model = catalog.get_model(TEST_MODEL_ALIAS)
79+
assert model is not None
80+
caps = model.capabilities
81+
assert caps is None or (isinstance(caps, str) and len(caps) > 0)
82+
83+
def test_should_expose_supports_tool_calling(self, catalog):
84+
"""Model should expose supports_tool_calling metadata."""
85+
model = catalog.get_model(TEST_MODEL_ALIAS)
86+
assert model is not None
87+
stc = model.supports_tool_calling
88+
assert stc is None or isinstance(stc, bool)

0 commit comments

Comments
 (0)