|
13 | 13 |
|
14 | 14 |
|
15 | 15 | def print_endpoint( |
16 | | - endpoint: Union[DedicatedEndpoint, ListEndpoint], json: bool = False |
| 16 | + endpoint: Union[DedicatedEndpoint, ListEndpoint], |
17 | 17 | ) -> None: |
18 | 18 | """Print endpoint details in a Docker-like format or JSON.""" |
19 | | - if json: |
20 | | - import json as json_lib |
21 | | - |
22 | | - output: Dict[str, Any] = { |
23 | | - "id": endpoint.id, |
24 | | - "name": endpoint.name, |
25 | | - "model": endpoint.model, |
26 | | - "type": endpoint.type, |
27 | | - "owner": endpoint.owner, |
28 | | - "state": endpoint.state, |
29 | | - "created_at": endpoint.created_at.isoformat(), |
30 | | - } |
31 | | - |
32 | | - if isinstance(endpoint, DedicatedEndpoint): |
33 | | - output.update( |
34 | | - { |
35 | | - "display_name": endpoint.display_name, |
36 | | - "hardware": endpoint.hardware, |
37 | | - "autoscaling": { |
38 | | - "min_replicas": endpoint.autoscaling.min_replicas, |
39 | | - "max_replicas": endpoint.autoscaling.max_replicas, |
40 | | - }, |
41 | | - } |
42 | | - ) |
43 | | - |
44 | | - click.echo(json_lib.dumps(output, indent=2)) |
45 | | - return |
46 | 19 |
|
47 | 20 | # Print header info |
48 | 21 | click.echo(f"ID:\t\t{endpoint.id}") |
@@ -244,7 +217,12 @@ def create( |
244 | 217 | def get(client: Together, endpoint_id: str, json: bool) -> None: |
245 | 218 | """Get a dedicated inference endpoint.""" |
246 | 219 | endpoint = client.endpoints.get(endpoint_id) |
247 | | - print_endpoint(endpoint, json=json) |
| 220 | + if json: |
| 221 | + import json as json_lib |
| 222 | + |
| 223 | + click.echo(json_lib.dumps(endpoint.model_dump(), indent=2)) |
| 224 | + else: |
| 225 | + print_endpoint(endpoint) |
248 | 226 |
|
249 | 227 |
|
250 | 228 | @endpoints.command() |
@@ -362,10 +340,19 @@ def list( |
362 | 340 | click.echo("No dedicated endpoints found", err=True) |
363 | 341 | return |
364 | 342 |
|
365 | | - click.echo("Dedicated endpoints:", err=True) |
366 | | - for endpoint in endpoints: |
367 | | - print_endpoint(endpoint, json=json) |
368 | | - click.echo() |
| 343 | + click.echo("Endpoints:", err=True) |
| 344 | + if json: |
| 345 | + import json as json_lib |
| 346 | + |
| 347 | + click.echo( |
| 348 | + json_lib.dumps([endpoint.model_dump() for endpoint in endpoints], indent=2) |
| 349 | + ) |
| 350 | + else: |
| 351 | + for endpoint in endpoints: |
| 352 | + print_endpoint( |
| 353 | + endpoint, |
| 354 | + ) |
| 355 | + click.echo() |
369 | 356 |
|
370 | 357 |
|
371 | 358 | @endpoints.command() |
|
0 commit comments