Skip to content

Commit a96c6bb

Browse files
committed
chore(lint): Fix ruff check and format issues from the rpm/tpm gauge commit
- quota_display.py: extract magic values (1_000, 100_000, 1_000_000) to module-level constants to silence PLR2004. - app.py: reorder import (QuestionApp before QuotaDisplay). - quota.py: ruff format on count_requests_today signature and on the midnight_utc chained call in count_requests_today / sum_prompt_tokens_today. Pinned ruff to the pre-commit version (0.14.5) for the format pass.
1 parent 8e85865 commit a96c6bb

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

‎albert_code/cli/textual_ui/app.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
from albert_code.cli.textual_ui.widgets.no_markup_static import NoMarkupStatic
5555
from albert_code.cli.textual_ui.widgets.path_display import PathDisplay
5656
from albert_code.cli.textual_ui.widgets.proxy_setup_app import ProxySetupApp
57-
from albert_code.cli.textual_ui.widgets.quota_display import QuotaDisplay
5857
from albert_code.cli.textual_ui.widgets.question_app import QuestionApp
58+
from albert_code.cli.textual_ui.widgets.quota_display import QuotaDisplay
5959
from albert_code.cli.textual_ui.widgets.session_picker import SessionPickerApp
6060
from albert_code.cli.textual_ui.widgets.teleport_message import TeleportMessage
6161
from albert_code.cli.textual_ui.widgets.tools import ToolResultMessage
@@ -1803,9 +1803,7 @@ async def _poll_daily_usage_loop(self) -> None:
18031803
rpd_used = count_requests_today(events, canonical)
18041804
tpd_used = sum_prompt_tokens_today(events, canonical)
18051805
throttler.update_daily_usage(
1806-
canonical,
1807-
rpd_used=rpd_used,
1808-
tpd_used=tpd_used,
1806+
canonical, rpd_used=rpd_used, tpd_used=tpd_used
18091807
)
18101808
self._refresh_quota_display()
18111809
except Exception:

‎albert_code/cli/textual_ui/widgets/quota_display.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
WARNING_RATIO = 0.8
2727
DANGER_RATIO = 0.95
2828

29+
# Thresholds for compact token formatting (3500 -> 3.5k, 128000 -> 128k, 2.5M -> 2.5M).
30+
_THOUSAND = 1_000
31+
_HUNDRED_THOUSAND = 100_000
32+
_MILLION = 1_000_000
33+
2934

3035
class QuotaDisplay(NoMarkupStatic):
3136
"""Compact rpm/tpm gauge for the bottom bar."""
@@ -94,10 +99,10 @@ def _ratio(used: int, limit: int | None) -> float:
9499

95100
def _compact_tokens(value: int) -> str:
96101
"""Format a token count compactly (3500 -> 3.5k, 128000 -> 128k)."""
97-
if value >= 1_000_000:
98-
return f"{value / 1_000_000:.1f}M"
99-
if value >= 100_000:
100-
return f"{value // 1_000}k"
101-
if value >= 1_000:
102-
return f"{value / 1_000:.1f}k".replace(".0k", "k")
102+
if value >= _MILLION:
103+
return f"{value / _MILLION:.1f}M"
104+
if value >= _HUNDRED_THOUSAND:
105+
return f"{value // _THOUSAND}k"
106+
if value >= _THOUSAND:
107+
return f"{value / _THOUSAND:.1f}k".replace(".0k", "k")
103108
return str(value)

‎albert_code/core/llm/quota.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ def sum_prompt_tokens_today(
123123
return total
124124

125125

126-
def count_requests_today(
127-
usage_events: list[dict[str, object]], model_name: str
128-
) -> int:
126+
def count_requests_today(usage_events: list[dict[str, object]], model_name: str) -> int:
129127
"""Count `model_name` calls that happened today (UTC).
130128
131129
Mirror of `sum_prompt_tokens_today` for the rpd (requests per day)

0 commit comments

Comments
 (0)