Skip to content

Commit 342b970

Browse files
atihkinmitali401
andauthored
Added two new filters to the list endpoints CLI (#386)
* Added two new filters to the CLI. usage_type and mine * fixed pre-commit merge issues * clarified difference between endpoint type and usage type * fixed integration tests and added back usage_type filtering since PR got merged togethercomputer/together-dedicated-endpoints#92 * removed all indications of mine is false since we don't support it --------- Co-authored-by: mitali401 <[email protected]>
1 parent deb6145 commit 342b970

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

poetry.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ numpy = [
4343
{ version = ">=1.26.0", python = ">=3.12" },
4444
]
4545
pillow = "^11.1.0"
46+
black = "^25.9.0"
4647

4748
[tool.poetry.extras]
4849
pyarrow = ["pyarrow"]

src/together/cli/api/endpoints.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,30 @@ def delete(client: Together, endpoint_id: str) -> None:
337337
type=click.Choice(["dedicated", "serverless"]),
338338
help="Filter by endpoint type",
339339
)
340+
@click.option(
341+
"--mine",
342+
type=click.BOOL,
343+
default=None,
344+
help="true (only mine), default=all",
345+
)
346+
@click.option(
347+
"--usage-type",
348+
type=click.Choice(["on-demand", "reserved"]),
349+
help="Filter by endpoint usage type",
350+
)
340351
@click.pass_obj
341352
@handle_api_errors
342353
def list(
343-
client: Together, json: bool, type: Literal["dedicated", "serverless"] | None
354+
client: Together,
355+
json: bool,
356+
type: Literal["dedicated", "serverless"] | None,
357+
usage_type: Literal["on-demand", "reserved"] | None,
358+
mine: bool | None,
344359
) -> None:
345360
"""List all inference endpoints (includes both dedicated and serverless endpoints)."""
346-
endpoints: List[ListEndpoint] = client.endpoints.list(type=type)
361+
endpoints: List[ListEndpoint] = client.endpoints.list(
362+
type=type, usage_type=usage_type, mine=mine
363+
)
347364

348365
if not endpoints:
349366
click.echo("No dedicated endpoints found", err=True)

src/together/resources/endpoints.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ def __init__(self, client: TogetherClient) -> None:
1313
self._client = client
1414

1515
def list(
16-
self, type: Optional[Literal["dedicated", "serverless"]] = None
16+
self,
17+
type: Optional[Literal["dedicated", "serverless"]] = None,
18+
usage_type: Optional[Literal["on-demand", "reserved"]] = None,
19+
mine: Optional[bool] = None,
1720
) -> List[ListEndpoint]:
1821
"""
19-
List all endpoints, can be filtered by type.
22+
List all endpoints, can be filtered by endpoint type and ownership.
2023
2124
Args:
22-
type (str, optional): Filter endpoints by type ("dedicated" or "serverless"). Defaults to None.
25+
type (str, optional): Filter endpoints by endpoint type ("dedicated" or "serverless"). Defaults to None.
26+
usage_type (str, optional): Filter endpoints by usage type ("on-demand" or "reserved"). Defaults to None.
27+
mine (bool, optional): If True, return only endpoints owned by the caller. Defaults to None.
2328
2429
Returns:
2530
List[ListEndpoint]: List of endpoint objects
@@ -28,9 +33,20 @@ def list(
2833
client=self._client,
2934
)
3035

31-
params = {}
36+
params: Dict[
37+
str,
38+
Union[
39+
Literal["dedicated", "serverless"],
40+
Literal["on-demand", "reserved"],
41+
bool,
42+
],
43+
] = {}
3244
if type is not None:
3345
params["type"] = type
46+
if usage_type is not None:
47+
params["usage_type"] = usage_type
48+
if mine is not None:
49+
params["mine"] = mine
3450

3551
response, _, _ = requestor.request(
3652
options=TogetherRequest(
@@ -263,13 +279,18 @@ def __init__(self, client: TogetherClient) -> None:
263279
self._client = client
264280

265281
async def list(
266-
self, type: Optional[Literal["dedicated", "serverless"]] = None
282+
self,
283+
type: Optional[Literal["dedicated", "serverless"]] = None,
284+
usage_type: Optional[Literal["on-demand", "reserved"]] = None,
285+
mine: Optional[bool] = None,
267286
) -> List[ListEndpoint]:
268287
"""
269-
List all endpoints, can be filtered by type.
288+
List all endpoints, can be filtered by type and ownership.
270289
271290
Args:
272291
type (str, optional): Filter endpoints by type ("dedicated" or "serverless"). Defaults to None.
292+
usage_type (str, optional): Filter endpoints by usage type ("on-demand" or "reserved"). Defaults to None.
293+
mine (bool, optional): If True, return only endpoints owned by the caller. Defaults to None.
273294
274295
Returns:
275296
List[ListEndpoint]: List of endpoint objects
@@ -278,9 +299,20 @@ async def list(
278299
client=self._client,
279300
)
280301

281-
params = {}
302+
params: Dict[
303+
str,
304+
Union[
305+
Literal["dedicated", "serverless"],
306+
Literal["on-demand", "reserved"],
307+
bool,
308+
],
309+
] = {}
282310
if type is not None:
283311
params["type"] = type
312+
if usage_type is not None:
313+
params["usage_type"] = usage_type
314+
if mine is not None:
315+
params["mine"] = mine
284316

285317
response, _, _ = await requestor.arequest(
286318
options=TogetherRequest(

0 commit comments

Comments
 (0)