Print a model-usage stats table to a Rich console. Each row shows the serving provider alongside the model name. When the session spans multiple models each gets its own row with a totals row appended; single-model sessions show one row. Args: stats: Cumulative session stat
(
stats: SessionStats,
wall_time: float,
console: Console,
)
| 100 | |
| 101 | |
| 102 | def print_usage_table( |
| 103 | stats: SessionStats, |
| 104 | wall_time: float, |
| 105 | console: Console, |
| 106 | ) -> None: |
| 107 | """Print a model-usage stats table to a Rich console. |
| 108 | |
| 109 | Each row shows the serving provider alongside the model name. When the |
| 110 | session spans multiple models each gets its own row with a totals row |
| 111 | appended; single-model sessions show one row. |
| 112 | |
| 113 | Args: |
| 114 | stats: Cumulative session stats. |
| 115 | wall_time: Total wall-clock time in seconds. |
| 116 | console: Rich console for output. |
| 117 | """ |
| 118 | from rich.table import Table |
| 119 | |
| 120 | has_time = wall_time >= 0.1 # noqa: PLR2004 |
| 121 | if not (stats.request_count or stats.input_tokens or has_time): |
| 122 | return |
| 123 | |
| 124 | if stats.per_model: |
| 125 | multi_model = len(stats.per_model) > 1 |
| 126 | |
| 127 | table = Table( |
| 128 | show_header=True, |
| 129 | header_style="bold", |
| 130 | box=None, |
| 131 | padding=(0, 2, 0, 0), |
| 132 | show_edge=False, |
| 133 | ) |
| 134 | table.add_column("Provider", style="dim") |
| 135 | table.add_column("Model", style="dim") |
| 136 | table.add_column("Reqs", justify="right", style="dim") |
| 137 | table.add_column("InputTok", justify="right", style="dim") |
| 138 | table.add_column("OutputTok", justify="right", style="dim") |
| 139 | |
| 140 | if multi_model: |
| 141 | for ms in stats.per_model.values(): |
| 142 | table.add_row( |
| 143 | ms.provider, |
| 144 | ms.model_name, |
| 145 | str(ms.request_count), |
| 146 | format_token_count(ms.input_tokens), |
| 147 | format_token_count(ms.output_tokens), |
| 148 | ) |
| 149 | table.add_row( |
| 150 | "", |
| 151 | "Total", |
| 152 | str(stats.request_count), |
| 153 | format_token_count(stats.input_tokens), |
| 154 | format_token_count(stats.output_tokens), |
| 155 | ) |
| 156 | else: |
| 157 | ms = next(iter(stats.per_model.values())) |
| 158 | table.add_row( |
| 159 | ms.provider, |
searching dependent graphs…