MCPcopy
hub / github.com/usestrix/strix / _build_llm_usage_stats

Function _build_llm_usage_stats

strix/interface/utils.py:276–314  ·  view source on GitHub ↗
(
    stats_text: Text,
    report_state: Any,
    *,
    live: bool = False,
)

Source from the content-addressed store, hash-verified

274
275
276def _build_llm_usage_stats(
277 stats_text: Text,
278 report_state: Any,
279 *,
280 live: bool = False,
281) -> None:
282 usage = _llm_usage(report_state)
283 if not usage or _int_stat(usage, "requests") <= 0:
284 stats_text.append("\n")
285 stats_text.append("Cost ", style="dim")
286 stats_text.append("$0.0000 ", style="#fbbf24")
287 stats_text.append("· ", style="dim white")
288 stats_text.append("Tokens ", style="dim")
289 stats_text.append("0", style="white")
290 return
291
292 input_tokens = _int_stat(usage, "input_tokens")
293 output_tokens = _int_stat(usage, "output_tokens")
294 cached_tokens = _detail_value(usage, "input_tokens_details", "cached_tokens")
295 cost = _float_stat(usage, "cost")
296
297 stats_text.append("\n")
298 stats_text.append("Input Tokens ", style="dim")
299 stats_text.append(format_token_count(input_tokens), style="white")
300
301 if live or cached_tokens > 0:
302 stats_text.append(" · ", style="dim white")
303 stats_text.append("Cached Tokens ", style="dim")
304 stats_text.append(format_token_count(cached_tokens), style="white")
305
306 separator = "\n" if live else " · "
307 stats_text.append(separator, style="dim white")
308 stats_text.append("Output Tokens ", style="dim")
309 stats_text.append(format_token_count(output_tokens), style="white")
310
311 if live or cost > 0:
312 stats_text.append(" · ", style="dim white")
313 stats_text.append("Cost ", style="dim")
314 stats_text.append(f"${cost:.4f}", style="#fbbf24")
315
316
317def build_final_stats_text(report_state: Any) -> Text:

Callers 2

build_final_stats_textFunction · 0.85
build_live_stats_textFunction · 0.85

Calls 5

_llm_usageFunction · 0.85
_int_statFunction · 0.85
_detail_valueFunction · 0.85
_float_statFunction · 0.85
format_token_countFunction · 0.85

Tested by

no test coverage detected