Skip to content

Commit 009b0b2

Browse files
committed
feat: add support for --type dedicated
1 parent b22a58a commit 009b0b2

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

src/together/cli/api/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ def models(ctx: click.Context) -> None:
1515

1616

1717
@models.command()
18+
@click.option(
19+
"--type",
20+
type=click.Choice(["dedicated"]),
21+
help="Filter models by type (dedicated: models that support autoscaling)",
22+
)
1823
@click.pass_context
19-
def list(ctx: click.Context) -> None:
24+
def list(ctx: click.Context, type: str | None) -> None:
2025
"""List models"""
2126
client: Together = ctx.obj
2227

23-
response = client.models.list()
28+
response = client.models.list(dedicated=(type == "dedicated"))
2429

2530
display_list = []
2631

src/together/resources/models.py

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,47 @@
1111
)
1212

1313

14-
class Models:
14+
class ModelsBase:
1515
def __init__(self, client: TogetherClient) -> None:
1616
self._client = client
1717

18+
def _filter_dedicated_models(
19+
self, models: List[ModelObject], dedicated_response: TogetherResponse
20+
) -> List[ModelObject]:
21+
"""
22+
Filter models based on dedicated model response.
23+
24+
Args:
25+
models (List[ModelObject]): List of all models
26+
dedicated_response (TogetherResponse): Response from autoscale models endpoint
27+
28+
Returns:
29+
List[ModelObject]: Filtered list of models
30+
"""
31+
assert isinstance(dedicated_response.data, list)
32+
33+
# Create a set of dedicated model names for efficient lookup
34+
dedicated_model_names = {model["name"] for model in dedicated_response.data}
35+
36+
# Filter models to only include those in dedicated_model_names
37+
# Note: The model.id from ModelObject matches the name field in the autoscale response
38+
return [model for model in models if model.id in dedicated_model_names]
39+
40+
41+
class Models(ModelsBase):
1842
def list(
1943
self,
44+
dedicated: bool = False,
2045
) -> List[ModelObject]:
2146
"""
2247
Method to return list of models on the API
2348
49+
Args:
50+
dedicated (bool, optional): If True, returns only dedicated models. Defaults to False.
51+
2452
Returns:
2553
List[ModelObject]: List of model objects
2654
"""
27-
2855
requestor = api_requestor.APIRequestor(
2956
client=self._client,
3057
)
@@ -40,23 +67,37 @@ def list(
4067
assert isinstance(response, TogetherResponse)
4168
assert isinstance(response.data, list)
4269

43-
return [ModelObject(**model) for model in response.data]
70+
models = [ModelObject(**model) for model in response.data]
4471

72+
if dedicated:
73+
# Get dedicated models
74+
dedicated_response, _, _ = requestor.request(
75+
options=TogetherRequest(
76+
method="GET",
77+
url="autoscale/models",
78+
),
79+
stream=False,
80+
)
81+
82+
models = self._filter_dedicated_models(models, dedicated_response)
83+
84+
return models
4585

46-
class AsyncModels:
47-
def __init__(self, client: TogetherClient) -> None:
48-
self._client = client
4986

87+
class AsyncModels(ModelsBase):
5088
async def list(
5189
self,
90+
dedicated: bool = False,
5291
) -> List[ModelObject]:
5392
"""
5493
Async method to return list of models on API
5594
95+
Args:
96+
dedicated (bool, optional): If True, returns only dedicated models. Defaults to False.
97+
5698
Returns:
5799
List[ModelObject]: List of model objects
58100
"""
59-
60101
requestor = api_requestor.APIRequestor(
61102
client=self._client,
62103
)
@@ -72,4 +113,18 @@ async def list(
72113
assert isinstance(response, TogetherResponse)
73114
assert isinstance(response.data, list)
74115

75-
return [ModelObject(**model) for model in response.data]
116+
models = [ModelObject(**model) for model in response.data]
117+
118+
if dedicated:
119+
# Get dedicated models
120+
dedicated_response, _, _ = await requestor.arequest(
121+
options=TogetherRequest(
122+
method="GET",
123+
url="autoscale/models",
124+
),
125+
stream=False,
126+
)
127+
128+
models = self._filter_dedicated_models(models, dedicated_response)
129+
130+
return models

0 commit comments

Comments
 (0)