Skip to content

Commit eea00ff

Browse files
committed
✨ feat: add cost formatting for token usage
✨ feat: add cost formatting for token usage 🔧 Refactor: - Imported CommitAnalyzer to facilitate cost formatting. - Created a new function format_cost to handle cost representation. 💰 Update: - Updated print_token_usage function to use the new format_cost method. - Enhanced cost display for input, output, and total costs. This update improves the cost representation in token usage summaries for better readability.
1 parent dfdff74 commit eea00ff

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

commitloom/cli/console.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ..core.analyzer import CommitAnalysis, WarningLevel
1111
from ..core.git import GitFile
1212
from ..services.ai_service import TokenUsage
13+
from ..core.analyzer import CommitAnalyzer
1314

1415
console = Console()
1516

@@ -62,6 +63,12 @@ def print_batch_summary(total_files: int, total_batches: int) -> None:
6263
console.print(f" • Number of batches: [cyan]{total_batches}[/cyan]")
6364
console.print(f" • Files per batch: [cyan]~{total_files // total_batches}[/cyan]")
6465

66+
def format_cost(cost: float) -> str:
67+
"""Format cost in both human-readable and precise formats."""
68+
human_cost = CommitAnalyzer.format_cost_for_humans(cost)
69+
precise_cost = f"(€{cost:.8f})"
70+
return f"{human_cost} {precise_cost}"
71+
6572
def print_token_usage(usage: TokenUsage, batch_num: Optional[int] = None) -> None:
6673
"""Print token usage summary."""
6774
batch_info = f" (Batch {batch_num})" if batch_num is not None else ""
@@ -73,9 +80,9 @@ def print_token_usage(usage: TokenUsage, batch_num: Optional[int] = None) -> Non
7380
• Total Tokens: {usage.total_tokens:,}
7481
7582
[bold green]💰 Cost Breakdown:[/bold green]
76-
• Input Cost: {usage.input_cost:.8f}
77-
• Output Cost: {usage.output_cost:.8f}
78-
• Total Cost: {usage.total_cost:.8f}
83+
• Input Cost: {format_cost(usage.input_cost)}
84+
• Output Cost: {format_cost(usage.output_cost)}
85+
• Total Cost: {format_cost(usage.total_cost)}
7986
"""
8087
)
8188

0 commit comments

Comments
 (0)