Print one available model per line for quick CLI inspection.
(payload: dict, show_raw: bool)
| 503 | |
| 504 | |
| 505 | def print_models(payload: dict, show_raw: bool) -> int: |
| 506 | """Print one available model per line for quick CLI inspection.""" |
| 507 | data = payload.get("data") |
| 508 | if not isinstance(data, list): |
| 509 | print("Invalid models payload", file=sys.stderr) |
| 510 | if show_raw: |
| 511 | print(json.dumps(payload, ensure_ascii=False, indent=2), file=sys.stderr) |
| 512 | return 1 |
| 513 | for item in data: |
| 514 | if not isinstance(item, dict): |
| 515 | continue |
| 516 | model_id = item.get("id") |
| 517 | owned_by = item.get("owned_by") |
| 518 | if isinstance(model_id, str): |
| 519 | if isinstance(owned_by, str) and owned_by: |
| 520 | print(f"{model_id}\t{owned_by}") |
| 521 | else: |
| 522 | print(model_id) |
| 523 | if show_raw: |
| 524 | print(json.dumps(payload, ensure_ascii=False, indent=2), file=sys.stderr) |
| 525 | return 0 |
| 526 | |
| 527 | |
| 528 | def parse_args() -> argparse.Namespace: |